Run command line from vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • venky5186
    New Member
    • Oct 2008
    • 5

    Run command line from vb.net

    How do I run commands like cacls or any other windows commands using vb.net


    I am unable to run commands using the shell method in Vb.net but I would like to be able to run other executables with command line switches from a vb.net application.

    Please help.
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    If you're trying to start other processes with arguments then the ProcessStartInf o Class will probably be useful, with the .Arguments property also. Is that what you were looking for?

    joedeene

    Comment

    • venky5186
      New Member
      • Oct 2008
      • 5

      #3
      This is what I am trying to do,I am trying to integrate the cacls utility(Microso ft utility to remove ntfs permissions) onto a vb.net project.

      I would like to run the following command using a form based application.

      My form will have a textbox which will take an input of the files for which permissions need to be removed.

      On a button click it should be able to run the cacls utility with the following parameters.

      cacls.exe "filename" /d everyone.
      the file name part will be replaced with the +textbox1.text+

      any suggestions let me know.

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        You'll need to use the ProcessStartInf o object.
        Also, use String.Format instead of string concatenation:
        Code:
        Dim psi As ProcessStartInfo
        Dim procname As String = "calcs.exe"
        Dim filename As String = "whatever.txt"
        Dim args As String = String.Format("{0} /d everyone", filename)
        psi = New ProcessStartInfo(procname, args)
        Dim proc As New Process()
        proc.StartInfo = psi
        proc.Start()

        Comment

        • venky5186
          New Member
          • Oct 2008
          • 5

          #5
          Originally posted by insertAlias
          You'll need to use the ProcessStartInf o object.
          Also, use String.Format instead of string concatenation:
          Code:
          Dim psi As ProcessStartInfo
          Dim procname As String = "calcs.exe"
          Dim filename As String = "whatever.txt"
          Dim args As String = String.Format("{0} /d everyone", filename)
          psi = New ProcessStartInfo(procname, args)
          Dim proc As New Process()
          proc.StartInfo = psi
          proc.Start()

          I was able to run the utility,just one more information,aft er execution I would like to make the program pass another argument -Y

          Basically it is cacls.exe "filename" /d everyone

          on pressing enter- it shows

          Are you sure?Y/N

          How would I pass the Y onto the command.
          Appreciate your help in this..

          Comment

          • raids51
            New Member
            • Nov 2007
            • 59

            #6
            Originally posted by venky5186
            How do I run commands like cacls or any other windows commands using vb.net


            I am unable to run commands using the shell method in Vb.net but I would like to be able to run other executables with command line switches from a vb.net application.

            Please help.
            I think i understand you...did u try using
            Code:
            Shell("calcs myfile.txt ")
            replace myfile.txt with the filename you want to run it on

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Originally posted by venky5186
              I was able to run the utility,just one more information,aft er execution I would like to make the program pass another argument -Y

              Basically it is cacls.exe "filename" /d everyone

              on pressing enter- it shows

              Are you sure?Y/N

              How would I pass the Y onto the command.
              Appreciate your help in this..
              Ahh, the calcs program also waits on user input?
              In the ProcessStartInf o object there is a ".RedirectStand ardInput" property. Set it to true.
              Then you can do this after the .Start() call
              myprocess.Stand ardInput.Write( "Y");

              Note: You may have to wait a few cycles before calling that.
              So like:
              [code=c#]
              myprocess.Start ();
              Thread.Sleep(10 0);
              myprocess.Stand ardInput.Write( "Y");//do you need to press the enter key? I think you would change it to myprocess.Stand ardInput.WriteL ine("Y")
              [/code]

              Comment

              Working...