Example Code

Sleep, Shutdown, Restart and Lock Windows programmatically

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example uses the System Exec VI or Call Library Function Node to either sleep, shutdown, restart or lock a windows PC.

 

Description

This simple event driven VI uses the System Exec VI or Call Library Function Node to either sleep, shutdown, restart or lock a windows PC.

 

Call the "LockWorkstation" method within the "user32.dll" using a "Call Library Function Node"

Call the "SetSuspendState" method within the "powrprof.dll" using a "Call Library Function Node". Needs parameters 0,1,0.

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code 

  1. Start the VI
  2. Click one of the buttons and the relevant task should execute.

 

Additional Information or References

Front Panel

1.PNG

 

VI Snippets

2.png

4.png

5.png

 

 

Tested on windows 7.  Written in LabVIEW 2011 with silver buttons then saved for previous in LabVIEW 8.6

 

 

 

 **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.

Comments
programmindragon
Member
Member
on

The version that claims to be 8.6 is actually 2011 (11.0).  Could you please revert it.  Thank you.

Ron Deavers, CLD
lewboi
Member
Member
on

sorry dragon,  v8.6 is there now.  Thank you for letting me know.

kv8vsa
Member
Member
on

Hi Lewis. How about 8.0 too

lewboi
Member
Member
on

Done

Fred_A
Member
Member
on

Must we have administrator privileges on the computer to do that ?

yura_beno
Member
Member
on

Would this work on windows 8?

Also, I'm trying to get a LV exe to run during Connected Standby. Is it possible at all?