I have a button that runs dos commands that are listed in a textbox. I use the below code to run the text. If I run one command to reboot the computer it works fine, another command that adds a item to the registry does not work. It just opens the dos window with no text. When the dos window opens, if I just paste in the text in that window it works just fine so it shouldn't be a permissions issue. Can anyone see the problem?
Code that runs dos
--------------------------------------------
System.Diagnostics.Process process1;
process1 = new System.Diagnostics.Process();
process1.StartInfo.FileName = "cmd.exe";
process1.StartInfo.Arguments = textBox3.Text;
process1.Start();
Dos script to restart computer
--------------------------------------------
cmd /c shutdown -r -t 00 -m \\MyComputerName
Dos script that just opens a command window (replaced some dir names for security reasons)
--------------------------------------------
reg add \\MyComputerName\\somedir\\SOFTWARE\\somedir\\somedir\\somedir\\somedir\\anotherdir /v scforceoption /t REG_DWORD /d 0 /f

1 answers
I'd try prefixing the reg command with cmd.exe's /k switch:
process1.StartInfo.Arguments = "/k " + textBox3.Text;
This should leave the command window open so that you can read the output.
answered 2 years ago by:
17279
I think that you need to add "/c" to argument, when you try to run the reg command from cmd.exe.
answered 2 years ago by:
0
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!