Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running cmd commands with Administrator rights

How can I run the command **cd..** behind the scenes of a Windows Form? (i.e. the user cannot see it)

Thanks.

like image 762
user1547766 Avatar asked Dec 10 '12 19:12

user1547766


People also ask

What happens when you Run cmd as administrator?

When you use “Run as Administrator,” UAC gets out of the way, and the application is run with full administrator access to everything on your system.


1 Answers

See System.Diagnostics.Process http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

There is also this SO answer to this same exact question: https://stackoverflow.com/a/1469790/25882

Example:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C copy /b Image1.jpg + Archive.rar Image2.jpg";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
like image 144
Chris Andrews Avatar answered Oct 17 '22 00:10

Chris Andrews