Setting a scheduled tasks to run a vbs script

Hi there,

So I'm trying to set a scheduled task with the below in a batch file, when our end users log onto the system..  However its shutting the computer down with out pop up message to click on Yes to shut it down or No to cancel

schtasks /create /sc daily /st 15:05:00 /tn shutdown /tr "cscript c:\shutdown.vbs"

Could someone help me out please.

Regards


Option Explicit

Dim objNetwork, strComputer, objWMIService, colOperatingSystems
Dim objOperatingSystem, objShell, intReturn

Const SHUTDOWN = 1
Const POWEROFF = 8

Set objShell = CreateObject("Wscript.Shell")
intReturn = objShell.Popup("Click ""Yes"" to shutdown, or ""No"" to prevent shutdown", _
  20, "Shutdown Computer", vbYesNo + vbInformation)

If (intReturn = vbNo) Then
  ' User clicked "No", abort.
  Wscript.Quit
End If

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Shutdown the local computer.
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
    strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
  ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
  'objOperatingSystem.Reboot()
  objOperatingSystem.Win32Shutdown(SHUTDOWN)
Next

Open in new window

gladminsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gladminsAuthor Commented:
I should also add if I manually set the scheduled tasks I do get the prompts..
DonNetwork AdministratorCommented:
You may need to use "AT" with the /Interactive switch


http://support.microsoft.com/kb/313565

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Daz_1234Commented:
Hi gladmins,

What user is the scheduled task running as?  If it is SYSTEM then dstewartjr is on the right track.   Scheduled tasks created using schtasks that run as SYSTEM will always run non-interactively, so any prompts will not be displayed.  One solution then is to use AT as dstewartjr advises.

When you run schtasks yourself, using the commandline you posted, they run as the user that set up the task, i.e. you, so you then *would* see all the dialogs.

Regards,
Daz
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.