LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Restart the PC using a C instruction

Sometimes, developing a specific application using CVI, I'd need to Shutdown or Restart the PC.
Do you know the way to do this using a C instruction or a particular sequence of instructions or an already available C Funcion?
Thanks. 
0 Kudos
Message 1 of 4
(3,152 Views)
See ExitWindowsEx()
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 2 of 4
(3,149 Views)

On Windows/XP the Shudown command is available that permits to turn off or restart the computer: simply launch it with LaunchExecutable passing the appropriate command line options.

For a referenc on this command, simply open a command prompt, type SHUTDOWN and press Enter: all the available options will be listed on the screen.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 4
(3,140 Views)

below a function that shutdown computer using SDK

int Digital_StopComputer (void)
{
    int error = 0;
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;
   
    // Get a token for this process.
    if (!OpenProcessToken(GetCurrentProcess(),
               TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    {
        error = -1;
        errChk(error);
    }           
 
    // Get the LUID for the shutdown privilege.
 
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
               &tkp.Privileges[0].Luid);
 
    tkp.PrivilegeCount = 1;  // one privilege to set   
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
    // Get the shutdown privilege for this process.
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
           (PTOKEN_PRIVILEGES)NULL, 0);
      
    if (GetLastError() != ERROR_SUCCESS)
    {
        error = -1;
        errChk(error);
    }    
    //Reboot the system 
    if (!ExitWindowsEx(EWX_SHUTDOWN, 0))
    {
       error = -1;
       errChk(error);
    }    

Error :
    return error;
}

0 Kudos
Message 4 of 4
(3,108 Views)