Click to See Complete Forum and Search --> : File|Run in .NET
Delamater
March 29th, 2003, 03:09 PM
Visual basic .NET...
I am trying to send a command to the OS that is the same as what would normally be the target line of a windows shortcut icon.
For example:
Target line:
"C:\Program Files\Best\MAS90\HOME\PVXWIN32.EXE" ..\launcher\sota.ini ..\soa\mas90 - ARG ..\SOA\DFDM_LOAD
There must be multiple arguments. If you notice correctly, the above statement shows "..\launcher\sota.ini", then it shows "..\soa\mas90", then I pass a seperate program as an argument.
I have been able to pass the first arguemtn with a shell statement:
dim shell as new shell32..shell
shell.open("c:\program files\best\mas90\home\pvxwin32.exe" ..\launcher\sota.ini
However, I get a file not found error when adding the subsequent "..\soa\mas90" statement. It appears, shell32 can only use one argument.
Does anyone know how to simply call the file | run dialogue off the start menu, or merely pass a command to the OS in .NET? It has to have multiple arguments.
Thanks in advance!
Bob
DdH
March 31st, 2003, 02:09 PM
I don't know if it works with multiple arguments, but you can start a program with the following example.
Dim ProgramExe As String = "C:\Program Files\Best\MAS90\HOME\PVXWIN32.EXE"
Dim ProgramArgs As String = "..\launcher\sota.ini ..\soa\mas90 - ARG ..\SOA\DFDM_LOAD"
Dim pi As New System.Diagnostics.ProcessStartInfo
pi.FileName = ProgramExe
pi.Arguments = ProgramArgs
' Start Program
Dim pr As System.Diagnostics.Process
pr = System.Diagnostics.Process.Start(pi)
' Wait until process has finished
Do
System.Threading.Thread.Sleep(0)
Loop Until pr.HasExited
Delamater
March 31st, 2003, 02:23 PM
Thanks for the reply! That almost worked. I get the same results had I used shell, although, your way looks good as well.
The main problem here is that if I type:
"C:\Program Files\Best\MAS90\HOME\PVXWIN32.EXE" ..\launcher\sota.ini ..\soa\mas90 - ARG ..\SOA\svmnta
using the windows File | Run, then the program svmnta will actually load, using the properties of the sota.ini file.
However, if I use a command prompt (dos in this case), then I get an error 12 - file not found (this error is reported from the providex.exe - Providex is a business basic language).
For some reason, dos cannot interpret the same command line. I get the same results from shell as I do with the example you provided. And both of these results are the same as you get in dos.
So this must mean that the File | Run prompt interprets string commands slightly different than dos does. Any ideas why? Seems kind of strange to me.
Thanks again for the reply!
Bob
russgreen
April 2nd, 2003, 08:41 PM
I'm trying to do the same thing and I'm getting the same fault. The reason I believe is because when a file path contains spaces it need to be in double quotes, ie
dim shell as new shell32..shell
shell.open(""c:\program files\best\mas90\home\pvxwin32.exe"")
but that syntax obviously won't work....
What's the work around?
Russ
Delamater
April 2nd, 2003, 11:10 PM
Actually, DdH had it correct. The only thing that we were missing was the fact that in order for his set of code to work, you have to use the chdir () command to change to the directory where the .exe file is. In my case the .exe file was the pvxwin32.exe file. So, once I changed directories to that file, then ran the .exe from using DdH's code, it worked perfectly!
How do I know I have to change directories? Well consider this. If you take the command:
"C:\Program Files\Best\MAS90\HOME\PVXWIN32.EXE" ..\launcher\sota.ini ..\soa\mas90 - ARG ..\SOA\DFDM_LOAD
and copy that into a File | Run prompt in windows, it will work. If I perform that same command in dos, I experience an error. So, for whatever reason, dos is not smart enough to understand how to path that file.
Long story short, I had to write a routine to get the current directory, save it to a variable, then change to the directory where the .exe file is located, call that file, then change back to the previous directory.
Hope this helps!
Bob
Delamater
April 2nd, 2003, 11:12 PM
Whoops, I should have mentioned that the Visual Basic error I get is the same error I get when in the dos prompt, executing the same command outside of VB.
If you need some sample code just drop a line.
Bob
russgreen
April 3rd, 2003, 04:56 AM
Thanks for the reply but I kind of came across the same answer at around 3am this morning.
Its all good now though
Russ
msn2wolf
April 21st, 2005, 09:15 AM
Just a note:
the correct syntaxis to enquote a long filename/pathname in VBScript would be...
Shell.Open("""C:\Program Files\ProvideX\Home\PVXWIN32.EXE"" -ARG xxxxxxx")
Regards.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.