473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 10795
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

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

Similar topics

8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
7
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
4
by: lkrubner | last post by:
I'd like to write a PHP script to be used from the command line on a Unix machine. I'd like for the script to put together a string, turn it into a web page, print it, then return control the...
5
by: randyelliott | last post by:
Good Day, I have a MS Access (Access 2000 now upgraded to 2003) database that tracks customer information. One function of this database is to create an encrypted license file for our software,...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
4
by: Bit byte | last post by:
I have a project that I normally build (without problems) from the DevStudio IDE. However, I have embarked on automating all my builds (this test project being one of several). The project...
2
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.