Article

lxzndr's picture
article
Reads:

4761

Score:
4
4
1
 
Comments:

3

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

(View Disclaimer)

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.


Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

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, test, test before you do anything drastic with it.




User Comments

pehrensing's picture

Scripting...

Submitted by pehrensing on 15 June 2011 - 11:17am.

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.

ptenhoopen's picture

Script error?

Submitted by ptenhoopen on 15 June 2011 - 11:51am.

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

abens's picture

Why Script

Submitted by abens on 15 June 2011 - 11:53am.

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

© 2013 Novell