Trouble with "Process's" please help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    #1

    Trouble with "Process's" please help!

    Ok so I'm trying to run a simple dos command shell through a VB.NET
    2005 program. The oddest thing is happening given the following piece
    of code:


    '============== =============== =============== =============== =
    '=== VARIABLE DECLARATION AND INITIALIZATION =============== =
    '============== =============== =============== =============== =
    '---General Variables------------------------------------
    Dim CMDProcess As Process = New Process
    '---End General Variables--------------------------------
    '---XLNT Shell Variables---------------------------------
    CMDProcess.Star tInfo.FileName = "cmd.exe"
    CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
    '---End XLNT Shell Variables-----------------------------
    '============== =============== =============== =============== =
    '=== END VARIABLE DECLARATION AND INITIALIZATION ============
    '============== =============== =============== =============== =

    '============== =============== =============== =============== =
    '=== EXECUTE JOB AND KEEP TRACK OF TIME =============== ======
    '============== =============== =============== =============== =
    CMDProcess.Star t() <--- Does not work
    Process.Start(" cmd.exe", "/c md C:\temp\temp") <---- Works


    If I create a new instance of the "Process" object and then try to
    start it, the command will not work. But if I just simply call
    Process.start the command works!

    I need to be able to use the created object to do this job. If anyone
    could offer any thoughts I would be very appreciative.

    Thanks
    Matt

  • Kim Greenlee

    #2
    RE: Trouble with &quot;Process's &quot; please help!

    When you say the command doesn't work...what is the behavior? Do you get any
    errors, is there a message box, does an exception get thrown? And if
    so...what is the message?

    I’m wondering if the CMDProcess object is able to actually find cmd.exe.

    Kim Greenlee

    --
    digipede - Many legs make light work.
    Grid computing for the real world.
    Empower your business with the help of Digipede Technologies. We are a leading provider of distributed computing solutions on the Microsoft .NET platform.



    Comment

    • Miro

      #3
      Re: Trouble with &quot;Process's &quot; please help!

      I checked my process start program and the only difference I an see that I
      have and you have is the
      Dim of the Processes in the begining. This works for me... dont know if you
      want to see if it works for u.

      my code is as follows:
      Dim StartInfo As New ProcessStartInf o()
      Dim myNewApp As New Process()

      myNewApp.StartI nfo.FileName = "C:\FILENAME.EX E"
      myNewApp.StartI nfo.Arguments = "/Q"
      myNewApp.StartI nfo.WorkingDire ctory = "C:\Temp"
      myNewApp.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal

      myNewApp.Start( )


      Miro


      "Matt" <Kruz79@gmail.c omwrote in message
      news:1156274671 .901073.38000@b 28g2000cwb.goog legroups.com...
      Ok so I'm trying to run a simple dos command shell through a VB.NET
      2005 program. The oddest thing is happening given the following piece
      of code:
      >
      >
      '============== =============== =============== =============== =
      '=== VARIABLE DECLARATION AND INITIALIZATION =============== =
      '============== =============== =============== =============== =
      '---General Variables------------------------------------
      Dim CMDProcess As Process = New Process
      '---End General Variables--------------------------------
      '---XLNT Shell Variables---------------------------------
      CMDProcess.Star tInfo.FileName = "cmd.exe"
      CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
      '---End XLNT Shell Variables-----------------------------
      '============== =============== =============== =============== =
      '=== END VARIABLE DECLARATION AND INITIALIZATION ============
      '============== =============== =============== =============== =
      >
      '============== =============== =============== =============== =
      '=== EXECUTE JOB AND KEEP TRACK OF TIME =============== ======
      '============== =============== =============== =============== =
      CMDProcess.Star t() <--- Does not work
      Process.Start(" cmd.exe", "/c md C:\temp\temp") <---- Works
      >
      >
      If I create a new instance of the "Process" object and then try to
      start it, the command will not work. But if I just simply call
      Process.start the command works!
      >
      I need to be able to use the created object to do this job. If anyone
      could offer any thoughts I would be very appreciative.
      >
      Thanks
      Matt
      >

      Comment

      • Phill W.

        #4
        Re: Trouble with &quot;Process's &quot; please help!

        Matt wrote:
        Dim CMDProcess As Process = New Process
        CMDProcess.Star tInfo.FileName = "cmd.exe"
        CMDProcess.Star tInfo.Arguments = "\c md C:\temp\temp"
        CMDProcess.Star t() <--- Does not work
        Process.Start(" cmd.exe", "/c md C:\temp\temp") <---- Works
        Have a play with the StartInfo UseShellExecute property.
        IIRC, that has some bearing on how things work.

        Failing that, try "%COMSPEC%" instead of "cmd.exe"

        Or, better still, looking at what you're actually doing:

        System.IO.Direc tory.CreateDire ctory( "C:\temp\te mp" )

        HTH,
        Phill W.

        Comment

        • Matt

          #5
          Re: Trouble with &quot;Process's &quot; please help!

          I'm not trying to create a directory, that was just something I tossed
          in there to see if it would work. What I'm ultimately trying to do is
          to run dos commands from a VB.NET app.

          I was under the impression given the following code.

          Dim StartInfo As New ProcessStartInf o()
          Dim myNewApp As New Process()


          myNewApp.StartI nfo.FileName = "cmd.exe"
          myNewApp.StartI nfo.Arguments = "\c md C:\temp\temp"
          myNewApp.StartI nfo.WorkingDire ctory = "C:\Temp"
          myNewApp.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
          myNewApp.Start( )

          That the "Arguments" part of it would indicate what dos command I
          wanted to execute. When I run the following code I get a dos window
          showing up but it doesn't make a directory. How do I get it to execute
          it?

          The reason I want to do things this way is so that I can measure when
          the process ends, whereas if I just did it like this...

          Process.Start(" cmd.exe", "/c " & Command)

          I can't tell.

          Comment

          • Phill W.

            #6
            Re: Trouble with &quot;Process's &quot; please help!

            Matt wrote:
            I'm not trying to create a directory, that was just something I tossed
            in there to see if it would work.
            Fair enough.
            myNewApp.StartI nfo.FileName = "cmd.exe"
            myNewApp.StartI nfo.Arguments = "\c md C:\temp\temp"
            Shouldn't that be "/c md C:\temp\temp" ?
            The reason I want to do things this way is so that I can measure when
            the process ends, whereas if I just did it like this...
            >
            Process.Start(" cmd.exe", "/c " & Command)
            >
            I can't tell.
            That's because when you kick off a /Windows/ process from /DOS/, DOS
            doesn't wait for it to finish /unless/ you use the START command with
            the "/WAIT" flag, effectively

            START /WAIT winprog1.exe a b c d
            IF ERRORLEVEL 1 GOTO Boom

            The VB.Net way to start and wait for a Process would be more like this:

            With myNewApp.StartI nfo
            .FileName = "program1.e xe"
            .Arguments = "a b c"
            .Start()
            .WaitForExit( ... ' can't remember the arguments; sorry
            End With

            HTH,
            Phill W.

            Comment

            Working...