How to start a PC/Application from Program
-
Dear Friends, I would like to restart a PC whenever any error occurs in my application. How can I do so. Please help me as soon as possible. Thanking You in advance....... Billar
-
If you are using NT/2000/XP, you will need to set privileges.
DWORD dwVersion = GetVersion(); if ( dwVersion < 0x80000000) { // NT/2000/XP HANDLE hToken; LUID tmpLuid; HANDLE handleProcess=GetCurrentProcess(); if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return; if (!LookupPrivilegeValue(0,"SeShutdownPrivilege", &tmpLuid)) return; TOKEN_PRIVILEGES NewState; LUID_AND_ATTRIBUTES luidattr; NewState.PrivilegeCount = 1; luidattr.Luid=tmpLuid; luidattr.Attributes=SE_PRIVILEGE_ENABLED; NewState.Privileges[0]=luidattr; if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0)) return; } ExitWindowsEx(...);
-
Dear Friends, I would like to restart a PC whenever any error occurs in my application. How can I do so. Please help me as soon as possible. Thanking You in advance....... Billar
Billar wrote: I would like to restart a PC whenever any error occurs in my application. This is a very bad design in my opinion. :eek: Since there is no way you are going to develop an error-free application, I certainly would not want my PC restarting while I am in the middle of something important (e.g., typing research paper, presentation to the board). Do you concur?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Billar wrote: I would like to restart a PC whenever any error occurs in my application. This is a very bad design in my opinion. :eek: Since there is no way you are going to develop an error-free application, I certainly would not want my PC restarting while I am in the middle of something important (e.g., typing research paper, presentation to the board). Do you concur?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
If you are using NT/2000/XP, you will need to set privileges.
DWORD dwVersion = GetVersion(); if ( dwVersion < 0x80000000) { // NT/2000/XP HANDLE hToken; LUID tmpLuid; HANDLE handleProcess=GetCurrentProcess(); if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return; if (!LookupPrivilegeValue(0,"SeShutdownPrivilege", &tmpLuid)) return; TOKEN_PRIVILEGES NewState; LUID_AND_ATTRIBUTES luidattr; NewState.PrivilegeCount = 1; luidattr.Luid=tmpLuid; luidattr.Attributes=SE_PRIVILEGE_ENABLED; NewState.Privileges[0]=luidattr; if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0)) return; } ExitWindowsEx(...);