Restart computer from windows dialog
-
Can anyone help me with C++ code that will allow me to offer the user the choice to restart the computer from a windows dialog box? Kyle
ExitWindowsEx(EWX_REBOOT,SHTDN_REASON_MAJOR_APPLICATION); Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
ExitWindowsEx(EWX_REBOOT,SHTDN_REASON_MAJOR_APPLICATION); Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
It isn't, you need to use P/Invoke; kyle posted to the wrong forum ;P
[DllImport("user32.dll")] public external static bool ExitWindowsEx(uint uFlags, int dwReason);
Search through the Vc7\PlatformSDK\Include directory to get the constants needed for the paramters. James Simplicity Rules! -
It isn't, you need to use P/Invoke; kyle posted to the wrong forum ;P
[DllImport("user32.dll")] public external static bool ExitWindowsEx(uint uFlags, int dwReason);
Search through the Vc7\PlatformSDK\Include directory to get the constants needed for the paramters. James Simplicity Rules! -
I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle
kyledunn wrote: Please accept my apology. No problems :) kyledunn wrote: is there a way to restart the computer using C# managed code? AFAIK there isn't; I haven't run across one anyway. James Simplicity Rules!
-
I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle
It is very doable from WMI API wrapped in the .NET System.Managment namespace. You can reboot/shutdown the local or any other machine on the domain. Depending on the privileges you or your admin have set, your mileage will vary. Regards
-
I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle
using System.Management;
.
.
.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem WHERE Primary = TRUE");
ManagementBaseObject inParams;
ManagementBaseObject outParams;
bool temp;foreach (ManagementObject os in searcher.Get())
{
temp = os.Scope.Options.EnablePrivileges;
os.Scope.Options.EnablePrivileges = true;
inParams = os.GetMethodParameters("Reboot");
outParams = os.InvokeMethod("Reboot", inParams, null);
os.Scope.Options.EnablePrivileges = temp;
}You can also specify Shutdown for the method...