Novell Cool Solutions

Shutdown (reboot) Windows workstation only if no one is logged in



By:

June 8, 2011 5:52 pm

Reads:6,672

Comments:3

Score:Unrated

Print/PDF

I had a desire to shutdown workstations automatically, but only if no user was logged on. There isn’t a current ZENworks Requirement that is “User logged on” there is one regarding primary user, but I wanted to avoid shutdown regardless of logged on user.

I created a bundle that copies/installs the following script onto the workstation, and then runs the script (and passes any reason text as desired). I had to copy/install the script to the workstation because there is still a flaw in the ZCM script translator that doesn’t handle parts of the script properly if it was defined in the bundle action.

set ucount=1
set reason=%1
if %reason%.==. set reason=None
for /f "tokens=*" %%G in ('wmic ComputerSystem Get UserName ^| Find /c "\"') do (set ucount==%%G)
if %ucount% == 0 shutdown /s /t 5 /c %reason%

Should work for Windows XP and higher.

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...Loading...

Tags:
Categories: Technical, ZENworks Configuration Management

3

Disclaimer: This content is not supported by Novell. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.

3 Comments

  1. By:pehrensing

    Now that is very cool!! I wish I had the time to learn WMI scripting. It would probably enhance a lot of the things I’m asked to do on my workstations.

    • By:ptenhoopen

      Nice script.

      It looks like the script might contain an error in the line where ucount is set after the search of active users. It contains an extra equals sign.

      (set ucount==%%G) should be (set ucount=%%G)

      Thanks.

      Pat

  2. By:abens

    Why not use the quick task to shutdown/reboot workstation? Scripting and deploying bundle, seems like extra work to me.

Comment

RSS