Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionally rebooting a PC as a scheduled task

Status
Not open for further replies.

DayLaborer

Programmer
Jan 3, 2006
347
US
This question was originally posted as thread779-1381193 in the XP Pro forum and someone there suggested I post it in this forum instead.


This question pertains to my Windows XP Pro PC that has "Fast User Switching" enabled.

I would like to schedule a task to execute a small script that would reboot my PC only if:
- there are no users with programs running at the time (even if they're suspended)
and
- no one is "active" (i.e. actively logged-in)

In other words, if there are users who are logged in ("Disconnected" - i.e. not "active") but do not have any programs running, I want to reboot. But if any users are either actively logged-in or are "Disconnected" but have programs running, I don't want anything to happen.

What would the contents of such a script file be?

Thanks so much,
Eliezer
 
Use WMI and the Win32_Process class to see the processes and their owners.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
DM,

I am not a VBSer at all... Any pointers/tips/links as to how to actually implement this (ala "for dummies")?

Thanks!
Eliezer
 
Could anyone please point me to an example of how to do this?

Even if I could figure out the code from the link that DM posted (and I have serious doubts if I could), I wouldn't know how to get it to run...

Thanks,
Eliezer
 
Here is a quick example, but unless you take the time to try and understand then you'll have a hard time modifying it to your needs.

Code:
Option Explicit

Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & _
										strComputer & "\root\cimv2")
Dim colProcesses : Set colProcesses = objWMIService.ExecQuery(_
									  "Select * From Win32_Process")
Dim objProcItem, errRtn, strUser, strDomain
For Each objProcItem In colProcesses
	errRtn = objProcItem.GetOwner(strUser, strDomain)
	WScript.Echo objProcItem.Name & vbTab & "Owner is: " & strUser 
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Let me try a simpler question: can I have the batch file reboot the PC only if no one is logged-in - regardless of whether the users are "active" or "disconnected", but if any user is logged-in, it won't reboot?

Thanks!
Eliezer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top