To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example illustrates 2 methods for shutting down Windows from within LabVIEW.
Description
Method 1: Using the System Exec VI
Shutdown is achieved by passing the system-level command: cmd.exe /C shutdown -r -m \\computername -t 5 -f
This command translates to shutting down the computer (named computername) with a timeout of 5 seconds, forcing all running applications to close without warning.
Method 2: Using the Call Library Function Node
This method accesses the user32.dll and utilizes the ExitWindowsEx function to perform a Windows shutdown. Drop a Call Library Node (CLN) and configure it as shown in the following picture. uFlags set to zero forces a shutdown of all processes and then logs off the user; setting dwReason to zero indicates the reason for shutdown is related to "some other issue." If the function return is not equal to zero, then the function executed successfully.
Requirements
Steps to Implement or Execute Code
Method 1
Method 2
Additional Information or References
You should always consider protecting code like this with dialogs that allow users to save and close things a they see fit prior to a shutdown.
VI Snippet of System Exec to Shutdown Windows 2012 NIVerified
VI Snippet of Call Library Function Node to Shutdown Windows 2012 NIVerified
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.