Replace VB6-Shell with ProcessStartInfo

E

Erik

Hi.
I got an old vb6-app that is going to be converted into C#. In the old
code the current program is starting another .exe with a command like:

If Shell("""" & "c:\Myapps\MyApp.exe" & """" & " " & Parameters,
vbNormalFocus) = 0 Then
........

Parameters is some parameters (a string with colon-separated arguments)
to be passed to the MyApp.exe.

So, now I translate this to:

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; (I have tried with true here too)
psi.FileName = c:\Myapps\MyApp.exe;
psi.Arguments = Parameters;
psi.WindowStyle = ProcessWindowStyle.Normal;
Process.Start(psi);

And It almost is ok. The program is starting, but something in the
parameterlist seems to be wrong. Is there something I have missed here?

The """"-stuff in the old shell maybe is something I should take care
of, I cannot find any real information about this.

/Erik
 
E

Erik

Hi.
Thanks for your comments, but there is actually nothing more to show.
The real codline here is:
If Shell("""" & destPath & "MyApp.EXE" & """" & " " & Parameters,
vbNormalFocus) = 0 Then
...........

(I changed it a bit in the original post, just for simplicity, but it's
got the same meaning, I think)

Where string destPath = "C:\Temp\TestApps\", and the string Parameters
contains a string like "dshdfsj, 1234,,,kdfs,,hsfgrf" or so, and the
exactly same string is used in the csharp-code.

The problem is that some of the values in the parameterlist seems to be
dislocated in csharp, frustrating.

I will try to get my hand on the original code to MyApp.exe, and debug
it from the new application, but i'm not sure I can get it.

/Erik


[...]
And It almost is ok. The program is starting, but something in the
parameterlist seems to be wrong. Is there something I have missed here?

Other than the missing quotes around the name of the executable, there's
nothing obvious in what little code you posted. So, if there's a
problem, it can only be found in the code you didn't post.

Post a concise-but-complete code example that reliably demonstrates the
problem, along with a specific description as to what that code does,
and why that's different from what you want and/or expect it to do.
The """"-stuff in the old shell maybe is something I should take care
of, I cannot find any real information about this.

I'm not that conversant with VB6 techniques, but that appears to simply
be there to allow for executable paths that include spaces. There
should be no need to duplicate that portion of the original code, since
the executable path and argument list are handled separately in the
Process class.

Pete
 
E

Erik

Hi.
Thanks for your comments, but there is actually nothing more to show.
The real codline here is:
If Shell("""" & destPath & "MyApp.EXE" & """" & " " & Parameters,
vbNormalFocus) = 0 Then
...........

(I changed it a bit in the original post, just for simplicity, but it's
got the same meaning, I think)

Where string destPath = "C:\Temp\TestApps\", and the string Parameters
contains a string like "dshdfsj, 1234,,,kdfs,,hsfgrf" or so, and the
exactly same string is used in the csharp-code.

The problem is that some of the values in the parameterlist seems to be
dislocated in csharp, frustrating.

I will try to get my hand on the original code to MyApp.exe, and debug
it from the new application, but i'm not sure I can get it.

/Erik


[...]
And It almost is ok. The program is starting, but something in the
parameterlist seems to be wrong. Is there something I have missed here?

Other than the missing quotes around the name of the executable, there's
nothing obvious in what little code you posted. So, if there's a
problem, it can only be found in the code you didn't post.

Post a concise-but-complete code example that reliably demonstrates the
problem, along with a specific description as to what that code does,
and why that's different from what you want and/or expect it to do.
The """"-stuff in the old shell maybe is something I should take care
of, I cannot find any real information about this.

I'm not that conversant with VB6 techniques, but that appears to simply
be there to allow for executable paths that include spaces. There
should be no need to duplicate that portion of the original code, since
the executable path and argument list are handled separately in the
Process class.

Pete
 
E

Erik

As I said, the only thing that's important is the line I wrote. Here is
an (working but stripped) example of the VB6-code:

Private Sub Main()
Dim callOk As Boolean
Dim destPath As String
Dim Parameters As String
destPath = "C:\Temp\TestApps\"
Parameters =
"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp"
ChDrive ("C:")
ChDir (destPath)
If Shell("""" & destPath & "MyApp.EXE" & """" & " " & Parameters,
vbNormalFocus) = 0 Then
callOk = False
Else
callOk = True
End If
End Sub

I cannot see what extra information this is going to give, but this is
working and if someone got a explanation why not the c#-code works:

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; (I have tried with true here too)
psi.FileName = "c:\Myapps\MyApp.exe;"
psi.Arguments = Parameters;
psi.WindowStyle = ProcessWindowStyle.Normal;
Process.Start(psi);



Peter Duniho skrev:
Hi.
Thanks for your comments, but there is actually nothing more to show.
[...]

All due respect, that's a ridiculous statement. You haven't posted
anything close to a complete, working example. How do you expect anyone
to reproduce the problem with what you've posted so far?

Here are some links you may find helpful:
http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/ (some Java-centric stuff, but mostly applicable to any
programming questions)

And yes, it's entirely possible you'll have to post code for _two_
sample applications (the program using Process, and the program being
executed by the Process class), if you can't find a way to reproduce the
problem using some application that can be reliably found on any Windows
installation.

Pete
 
E

Erik

As I said, the only thing that's important is the line I wrote. Here is
an (working but stripped) example of the VB6-code:

Private Sub Main()
Dim callOk As Boolean
Dim destPath As String
Dim Parameters As String
destPath = "C:\Temp\TestApps\"
Parameters =
"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp"
ChDrive ("C:")
ChDir (destPath)
If Shell("""" & destPath & "MyApp.EXE" & """" & " " & Parameters,
vbNormalFocus) = 0 Then
callOk = False
Else
callOk = True
End If
End Sub

I cannot see what extra information this is going to give, but this is
working and if someone got a explanation why not the c#-code works:

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; (I have tried with true here too)
psi.FileName = "c:\Myapps\MyApp.exe;"
psi.Arguments = Parameters;
psi.WindowStyle = ProcessWindowStyle.Normal;
Process.Start(psi);



Peter Duniho skrev:
Hi.
Thanks for your comments, but there is actually nothing more to show.
[...]

All due respect, that's a ridiculous statement. You haven't posted
anything close to a complete, working example. How do you expect anyone
to reproduce the problem with what you've posted so far?

Here are some links you may find helpful:
http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/ (some Java-centric stuff, but mostly applicable to any
programming questions)

And yes, it's entirely possible you'll have to post code for _two_
sample applications (the program using Process, and the program being
executed by the Process class), if you can't find a way to reproduce the
problem using some application that can be reliably found on any Windows
installation.

Pete
 
E

Erik

Damnit, you got me there, Is this a C# newgroup?
First you want me to show some code, I did, and then this comment about
wrong newsgroup, fascinating....

In fact, my point was to show that my only codeline in VB6 was the only
thing I was asking about, ant it would not make sense to put like 4
extraline of code in the .net-code, just to make it compile. All code
needed is there, if someone will look at it!

The question was posted as a C#-issue, because the VB6-code is working,
so put it in the VB6-newsgroup would NOT make any sense. (Those guys
would problably say "Hey... why do you post a question about a working
VB6-code her, when the problem is the C#-code.)

So, my point is that if someone have some skill in both VB6 and C# about
my issue, I be glad to get a tip from them, and they who don't, should
not even bother to answer, especially when their only comment is to tell
people how bad/stupid/ridiculous their question was.

(By the way, of course no one have the MyApp.exe, how could they? This
one is a production application, with another name.)

/Erik


Peter Duniho skrev:
As I said, the only thing that's important is the line I wrote. Here
is an (working but stripped) example of the VB6-code: [snip]

Did you read the links I provided?

VB6 code is not C# code. This is a C# newsgroup.

What C# code you did provide is not complete, especially since no one
here has a copy of "MyApp.exe" to test the code with.

Pete
 
E

Erik

Damnit, you got me there, Is this a C# newgroup?
First you want me to show some code, I did, and then this comment about
wrong newsgroup, fascinating....

In fact, my point was to show that my only codeline in VB6 was the only
thing I was asking about, ant it would not make sense to put like 4
extraline of code in the .net-code, just to make it compile. All code
needed is there, if someone will look at it!

The question was posted as a C#-issue, because the VB6-code is working,
so put it in the VB6-newsgroup would NOT make any sense. (Those guys
would problably say "Hey... why do you post a question about a working
VB6-code her, when the problem is the C#-code.)

So, my point is that if someone have some skill in both VB6 and C# about
my issue, I be glad to get a tip from them, and they who don't, should
not even bother to answer, especially when their only comment is to tell
people how bad/stupid/ridiculous their question was.

(By the way, of course no one have the MyApp.exe, how could they? This
one is a production application, with another name.)

/Erik


Peter Duniho skrev:
As I said, the only thing that's important is the line I wrote. Here
is an (working but stripped) example of the VB6-code: [snip]

Did you read the links I provided?

VB6 code is not C# code. This is a C# newsgroup.

What C# code you did provide is not complete, especially since no one
here has a copy of "MyApp.exe" to test the code with.

Pete
 
C

Cor Ligthert[MVP]

Erik,

You give in your VB code two parameters before Parameters (whatever that
is), an empty string and a space in a string.

If you want the equivalent then you need to do the same in C#.

You are testing the result of the process by reading that.

You can do that in C# as well by reading the process standardoutput using a
streamreader.

According your discussion with Pete, I say, have a look for that, it is
easily to find and to do it yourself.

Cor
 
C

Cor Ligthert[MVP]

Erik,

You give in your VB code two parameters before Parameters (whatever that
is), an empty string and a space in a string.

If you want the equivalent then you need to do the same in C#.

You are testing the result of the process by reading that.

You can do that in C# as well by reading the process standardoutput using a
streamreader.

According your discussion with Pete, I say, have a look for that, it is
easily to find and to do it yourself.

Cor
 
E

Erik

Thanks for that information. That could be just the thing I was looking
for. You know, the VB6-code is a bit messy to read I would say (at least
for someone who isn't familiar with that language). I will try to apply
that in the C#-code.

Thanks alot again.

/Erik



Cor Ligthert[MVP] skrev:
 
E

Erik

Thanks for that information. That could be just the thing I was looking
for. You know, the VB6-code is a bit messy to read I would say (at least
for someone who isn't familiar with that language). I will try to apply
that in the C#-code.

Thanks alot again.

/Erik



Cor Ligthert[MVP] skrev:
 
A

Alexander Mueller

Erik said:
As I said, the only thing that's important is the line I wrote. Here is
an (working but stripped) example of the VB6-code:
Private Sub Main()
destPath = "C:\Temp\TestApps\"
Parameters =
"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp"
End Sub

I cannot see what extra information this is going to give, but this is
working and if someone got a explanation why not the c#-code works:

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; (I have tried with true here too)
psi.FileName = "c:\Myapps\MyApp.exe;"

Hi,

C# has this double-backslash issue, like all c-styled languages.
You need to escape backslashes in strings with double backslashes,
The single backslash is an escape-character, like in "\r\n" which
is a vbCrLf.

If you assign a path to a string it's best to prepend a "@"-character,
to avoid escaping:


psi.FileName = @"c:\Myapps\MyApp.exe;"

OR

psi.FileName = "c:\\Myapps\\MyApp.exe;"

psi.Arguments = Parameters;


Maybe you should prepend the @ to the parameters-arg aswell
Parameters =
@"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp" ;

It should make no difference with the data you provided, but could make
a difference with other data.

Also it should be useful to specify the working directory in the
ProcessStartInfo-struct


MfG,
Alex
 
A

Alexander Mueller

Erik said:
As I said, the only thing that's important is the line I wrote. Here is
an (working but stripped) example of the VB6-code:
Private Sub Main()
destPath = "C:\Temp\TestApps\"
Parameters =
"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp"
End Sub

I cannot see what extra information this is going to give, but this is
working and if someone got a explanation why not the c#-code works:

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; (I have tried with true here too)
psi.FileName = "c:\Myapps\MyApp.exe;"

Hi,

C# has this double-backslash issue, like all c-styled languages.
You need to escape backslashes in strings with double backslashes,
The single backslash is an escape-character, like in "\r\n" which
is a vbCrLf.

If you assign a path to a string it's best to prepend a "@"-character,
to avoid escaping:


psi.FileName = @"c:\Myapps\MyApp.exe;"

OR

psi.FileName = "c:\\Myapps\\MyApp.exe;"

psi.Arguments = Parameters;


Maybe you should prepend the @ to the parameters-arg aswell
Parameters =
@"firstnamex,lastnamez,nextparam,,,,hjgf4hgdfk,jkhdserk,,testapp" ;

It should make no difference with the data you provided, but could make
a difference with other data.

Also it should be useful to specify the working directory in the
ProcessStartInfo-struct


MfG,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top