CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1

    File|Run in .NET

    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

  2. #2
    Join Date
    Jan 2003
    Location
    Amsterdam, Netherlands
    Posts
    97
    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

  3. #3
    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

  4. #4
    Join Date
    Feb 2003
    Location
    UK
    Posts
    19

    Double quotes

    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

  5. #5

    File | Run

    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

  6. #6

    File | Run whoops

    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

  7. #7
    Join Date
    Feb 2003
    Location
    UK
    Posts
    19

    Got it thanks

    Thanks for the reply but I kind of came across the same answer at around 3am this morning.

    Its all good now though

    Russ

  8. #8
    Join Date
    Apr 2005
    Posts
    1

    Re: File|Run in .NET

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured