.net - How to shut down the computer from C# -


what's best way shut down computer c# program?

i've found few methods work - i'll post them below - none of them elegant. i'm looking that's simpler , natively .net.

works starting windows xp, not available in win 2000 or lower:

this quickest way it:

process.start("shutdown","/s /t 0"); 

otherwise use p/invoke or wmi others have said.

edit: how avoid creating window

var psi = new processstartinfo("shutdown","/s /t 0"); psi.createnowindow = true; psi.useshellexecute = false; process.start(psi); 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -