Just a note: there is not such thing as "DOS Command". If you're talking about "CMD.EXE" — this is just a regular Windows protected-more application using console and running command interpreter.
You don't need to run it in your case. You need to run "NET.EXE" itself:
string cmdLine = string.Format("{0} {1} {2}", mapDriveP + mapDriveU + mapDriveS);
System.Diagnostics.Process.Start("NET.EXE", cmdLine);
If you have a problem running only one "NET.EXE" session you can consider running it one-by-one:
string[] parameters = new string[] {
@"use u: \\server\multimedia /user:""indiana jones""",
@"use p: \\server\temp /user:""indiana jones""",
@"use s: \\server\user /user:""indiana jones""", };
foreach(string cmdLineParameter in parameters) {
System.Diagnostics.Process process =
System.Diagnostics.Process.Start("NET.EXE", cmdLineParameter);
process.WaitForExit();
}
If one instance of the "NET.EXE" process does not depend on the result of another one, you can omit
WaitForExit
, but if you further code depends on the results, you need to wait anyway.
Another option is using batch file.
System.Diagnostics.Process.Start("myBatchFile.bat");
Do not use Sleep
! Do not use "CMD.EXE"!!!
—SA