To execute shell command from c#, save the commands within a batch file (.bat) extension. You can create a batch file using Notepad application and saving the file like <your-preferred-name.bat> (example: demo123.bat).
After creating the batch file, save the commands within the file like
net use a:
\\192.168.1.1\SharedFilder myPassword /user:MyUserName.
A complete followup of "net use" command can be found in
www.outsmartsoftware.com or
technet.Microsoft.comOnce you are settled with the batch file, invoke it from the C# code:
System.Diagnostics.Process objProcess = new Process();
objProcess.StartInfo.FileName = Server.MapPath("testfiles/netcmd.bat");
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; // to hide the command window popping up
objProcess.Start();
objProcess.WaitForExit(); // Gives time for the process to complete operation.
// After code is executed, call the dispose() method
objProcess.Dispose();
and there we go!!!!
for clarification, please feel free to reply to this post.
With thanks,
Arun Prasad.K.R
arun85prasad@live.com