Running a EXE with command line parameters in VB 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flamingskullz
    New Member
    • Jun 2007
    • 11

    Running a EXE with command line parameters in VB 2005

    Hi Guys, im trying to get VB to run the regedit.exe function with the following command line

    regedit.exe /E C:\VB.txt "HKEY_LOCAL_MAC HINE\Software\A berlink 3D"

    Anybody have any ideas? The problem i have is getting VB 2005 to export an entire subkey rather than just one value at a time. Am i going down the right route with using regedit or is there a function within .net that will do this for me?

    Thanks in advance

    Ben
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Check the Process class.
    It will take a filename and arguments

    There is also a Registry class for editing the Registry settings though

    Comment

    • flamingskullz
      New Member
      • Jun 2007
      • 11

      #3
      Cheers Plater, but ive been using the process class and it doesn't like and parameters after the .exe ive also played with the registry class but there isnt a function to export a part of the registry :(

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by flamingskullz
        Cheers Plater, but ive been using the process class and it doesn't like and parameters after the .exe ive also played with the registry class but there isnt a function to export a part of the registry :(
        What does your code look like for the arguments and the like?

        Comment

        • flamingskullz
          New Member
          • Jun 2007
          • 11

          #5
          Here is the line ive been playing with:

          Code:
            Private Sub ExportReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportReg.Click
                  Process.Start("regedit.exe /E C:\Regtest.reg "HKEY_LOCAL_MACHINE\Software\Aberlink 3D")
              End Sub
          But it refuses to let me run the .exe with added parameters, i delved into the My.computer.reg istry functions again with no luck.

          Thanks again

          Comment

          • TRScheel
            Recognized Expert Contributor
            • Apr 2007
            • 638

            #6
            Originally posted by flamingskullz
            Here is the line ive been playing with:

            Code:
              Private Sub ExportReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportReg.Click
                    Process.Start("regedit.exe /E C:\Regtest.reg "HKEY_LOCAL_MACHINE\Software\Aberlink 3D")
                End Sub
            But it refuses to let me run the .exe with added parameters, i delved into the My.computer.reg istry functions again with no luck.

            Thanks again
            Process.Start has an overload where you can pass parameters. Its something like:

            Code:
            Process.Start(string Filename, string Arguements);

            Comment

            • flamingskullz
              New Member
              • Jun 2007
              • 11

              #7
              Originally posted by TRScheel
              Process.Start has an overload where you can pass parameters. Its something like:

              Code:
              Process.Start(string Filename, string Arguements);
              Thanks that seems to have done the trick, below is the function of clicking a button, the command works fine until the Reg key i want to export has a space somewhere in the key name.
              IE Aberlink 3D shown below:

              Code:
                  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
                      Process.Start("C:\Windows\Regedit.exe", "/e C:\Joy.xxx HKEY_LOCAL_MACHINE\SOFTWARE\Aberlink 3D")
              
                  End Sub
              Anybody know how to get around this??? been trying for the last day. The command works fine if i were to use the "Ahead" key rather than "Aberlink 3D" for example

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                You are going to need to put the argument itself in quotes (as opposed to just a string in code)

                [CODE=vb]
                Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
                Process.Start(" C:\Windows\Rege dit.exe", "/e \C:\Joy.xxx \"HKEY_LOCAL_MA CHINE\SOFTWARE\ Aberlink 3D\"")

                End Sub
                [/CODE]

                The \" is used to insert a " inside a string, so just make sure they wrap around the correct parts

                Comment

                • flamingskullz
                  New Member
                  • Jun 2007
                  • 11

                  #9
                  still wont run with that space between "Aberlink 3D". im so close if it werent for this silly void between words!

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Try "[" or "(" or something then?
                    Or look up the help for that command on msdn?

                    Comment

                    • flamingskullz
                      New Member
                      • Jun 2007
                      • 11

                      #11
                      still no joy, VB obviously sees the space and assumes that the "3D" is a seperate parameter. I cant see any way of getting round it unless VB has its own export function. All the functions i have found only include low level functions like, read, write, create and delete. i will venture on though!

                      Comment

                      • Martin2007
                        New Member
                        • Jul 2007
                        • 21

                        #12
                        The argument you are using, is it a file? If it is a file you will need the full file extension...

                        also have you tried typing exactly what you have in the string into the command prompt...?

                        I managed to get this working, with the space, but it is using a txt file not a directory, hope this helps.

                        Code:
                            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                                Process.Start("notepad.exe", "C:\Documents and Settings\User\Desktop\test test.txt")
                            End Sub
                        Also it appears you are using more than one argument, maybe you have to put them as seperate strings, although i doubt it, i'm just thinking outloud...

                        any additional info u have on the prob will help with the solution!

                        Martin

                        Comment

                        • flamingskullz
                          New Member
                          • Jun 2007
                          • 11

                          #13
                          Hi Martin, the code i have works providing there isnt a space anywhere in the registry path i want to export. Which is a real pisser considering the part of the registry i need is some software called "Aberlink 3D". I just need to code it so it sees "Aberlink" and "3D" as the complete path name rather than two seperate entities.

                          Comment

                          • Martin2007
                            New Member
                            • Jul 2007
                            • 21

                            #14
                            Originally posted by flamingskullz
                            Hi Martin, the code i have works providing there isnt a space anywhere in the registry path i want to export. Which is a real pisser considering the part of the registry i need is some software called "Aberlink 3D". I just need to code it so it sees "Aberlink" and "3D" as the complete path name rather than two seperate entities.
                            So it is a directory then.... try

                            Code:
                            Process.Start("C:\Windows\Regedit.exe", "/e C:\Joy.xxx \HKEY_LOCAL_MACHINE\SOFTWARE\Aberlink 3D\")
                            To be honest i have never used the function that you are using, but I have used command line args, and when passing a directory I found that you had to pass the full name with the final "\".

                            Report back, this is annoying me, tho i can appreciate not as much as it annoys you!

                            Martin

                            Comment

                            • flamingskullz
                              New Member
                              • Jun 2007
                              • 11

                              #15
                              Martin you are a saint my friend! i have managed to get it to export finally!

                              Code:
                               Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                                      Process.Start("c:\Windows\regedit.exe", "/e c:\AB3DSettings.reg ""HKEY_LOCAL_MACHINE\Software\Aberlink 3D\""")
                              
                                  End Sub
                              I had to double quote the arguement but the \ has done the trick. My hero :)
                              Thanks again to Plater for you help, most appreciated :)

                              Comment

                              Working...