.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

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -