469,352 Members | 2,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

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.
Oct 20 '08 #1
6 10129
joedeene
583 512MB
If you're trying to start other processes with arguments then the ProcessStartInfo Class will probably be useful, with the .Arguments property also. Is that what you were looking for?

joedeene
Oct 20 '08 #2
This is what I am trying to do,I am trying to integrate the cacls utility(Microsoft 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.
Oct 23 '08 #3
Curtis Rutland
3,256 Expert 2GB
You'll need to use the ProcessStartInfo object.
Also, use String.Format instead of string concatenation:
Expand|Select|Wrap|Line Numbers
  1. Dim psi As ProcessStartInfo
  2. Dim procname As String = "calcs.exe"
  3. Dim filename As String = "whatever.txt"
  4. Dim args As String = String.Format("{0} /d everyone", filename)
  5. psi = New ProcessStartInfo(procname, args)
  6. Dim proc As New Process()
  7. proc.StartInfo = psi
  8. proc.Start()
  9.  
Oct 23 '08 #4
You'll need to use the ProcessStartInfo object.
Also, use String.Format instead of string concatenation:
Expand|Select|Wrap|Line Numbers
  1. Dim psi As ProcessStartInfo
  2. Dim procname As String = "calcs.exe"
  3. Dim filename As String = "whatever.txt"
  4. Dim args As String = String.Format("{0} /d everyone", filename)
  5. psi = New ProcessStartInfo(procname, args)
  6. Dim proc As New Process()
  7. proc.StartInfo = psi
  8. proc.Start()
  9.  

I was able to run the utility,just one more information,after 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..
Oct 25 '08 #5
raids51
59
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
Expand|Select|Wrap|Line Numbers
  1. Shell("calcs myfile.txt ")
replace myfile.txt with the filename you want to run it on
Oct 27 '08 #6
Plater
7,872 Expert 4TB
I was able to run the utility,just one more information,after 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 ProcessStartInfo object there is a ".RedirectStandardInput" property. Set it to true.
Then you can do this after the .Start() call
myprocess.StandardInput.Write("Y");

Note: You may have to wait a few cycles before calling that.
So like:
Expand|Select|Wrap|Line Numbers
  1. myprocess.Start();
  2. Thread.Sleep(100);
  3. myprocess.StandardInput.Write("Y");//do you need to press the enter key? I think you would change it to myprocess.StandardInput.WriteLine("Y")
  4.  
Oct 27 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by randyelliott | last post: by
34 posts views Thread by Roman Mashak | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.