How Can I Shutdown Windows from LabVIEW?

Updated Nov 9, 2018

Reported In

Software

  • LabVIEW

Issue Details

I want to shutdown my Windows PC from my LabVIEW application, how can I do this?

Solution

To shutdown Windows using a LabVIEW application you can use the following options:

Option 1:

Use the System Exec.vi

 


This executes a system command. Use the System Exec VI to execute or launch other Windows–based applications, command-line applications, (Windows) batch files, or (Mac OS X and Linux) script files from within VIs. With the System Exec VI, you can include any parameters within your command string that the executing command supports.

The example code attached below demonstrates how to shutdown Windows either immediately or after 1 minute.
 

To shutdown immdiately the command line needed is:
cmd.exe /C shutdown -s -t 0
To shutdown after one minute use:
cmd.exe /C shutdown -s

Option 2:

You can call the relevant Windows API function using the call library function
When calling a Windows API function from LabView, ensure that the "stdcall(WINAPI)" option is checked under "Calling convention" in the call library function properties.

ExitWindows 
The ExitWindows function logs off the current user, which does not completely shutdown the system. This function sends the "WM_QUERYENDSESSION" message to all applications to determine if they can be terminated.

ExitWindowsEx  
The ExitWindowsEx function either logs off the current user, restarts the system, or completely shuts down the system. This function sends the "WM_QUERYENDSESSION" message to all applications to determine if they can be terminated.

These two functions reside within "user32.dll", which is located in
c:\windows\system
on Windows 95/98/Me,
c:\winnt\system32
on Windows NT/2000,

SetSuspendState
The SetSuspendState function either sleeps or hibernates a system if a full shutdown is not required.
This function is only supported from Windows XP onward and can be found in 
C:\Windows\System32

An example call library function configuration is shown below for the SetSuspendState command:

WAS THIS ARTICLE HELPFUL?

Not Helpful