4

I need to execute a file on a remote machine without logging into the machine. I created scheduled task for the same. PFB the code snippet

scheduled_task = "schtasks /Create /S <> /SC nologon /TN install /TR c:\Temp\msgbox1.vbs /ST " & Hour(now) & ":" & Minute(now)+1 & ":00 /Z" cmdprmpt = "cmd /c " & scheduled_task intReturnCode= oWshShell.Run (cmdprmpt,4,True)

However this code executes only when the user is logged on. Is there a way to execute the same whether the user is logged on or not. -- This can be done manually in Task Scheduler. Can this be automated?

1
  • You could always use a Windows Service instead of a Scheduled Task - that will run in non-interactive mode. Mar 25, 2019 at 2:53

1 Answer 1

4

I think that if you add

/RU <username> /RP <password>

to the call to schtasks.exe you will get "Run whether user is logged on or not" selected. You can also use the /NP instead, which will also give you "Run whether user is logged on or not", but also "Do not store password..." which will limit the accessible resources.

This at least works on the local computer, which is where I normally create tasks from code (part of an installation procedure)

7
  • I am getting an error when I try in the manner you told.
    – Dipac
    Nov 14, 2014 at 14:07
  • I just tried it against a remote computer without problems. Which kind of error are you getting? Are you trying from the command line or from the VBscript? If you only try from the VBScript, I would recommend first trying from the command line to make sure you get the right command structure before moving the call into the VBScript. Nov 14, 2014 at 14:38
  • I tried this schtasks /Create /S <<machine name>> /RU <<username>> /RP <<password>> /SC ONCE /TN install /TR <<file to execute>> /ST 16:21:00 /Z
    – Dipac
    Nov 14, 2014 at 15:20
  • error ERROR: The task XML is missing a required element or attribute. (40,4):EndBoundary:
    – Dipac
    Nov 14, 2014 at 15:22
  • I got the following error now ERROR: A specified logon session does not exist. It may already have been terminated. Network access: Do not allow storage of passwords and credentials for network authentication- Disabling this option would prevent the error
    – Dipac
    Nov 17, 2014 at 8:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .