To create a scheduled task which can execute without user logged on --using vbscript
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)
Related videos on Youtube
Dipac
Updated on September 18, 2022Comments
-
Dipac over 1 year
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?
-
Dipac over 9 yearsI am getting an error when I try in the manner you told.
-
Lars Lind Nilsson over 9 yearsI 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.
-
Dipac over 9 yearsI 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 over 9 yearserror ERROR: The task XML is missing a required element or attribute. (40,4):EndBoundary:
-
Dipac over 9 yearsI 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
-
Lars Lind Nilsson over 9 yearsThe ".. XML is missing..." error can can happen if you are using Windows Vista and using the /Z parameter. Either skip the /Z parameter to add the /V1 parameter to force the task to be created in Pre Vista mode.
-
Lars Lind Nilsson over 9 yearsThe "..specified logon session does not exist..." error can be caused by a security setting on the remote computer not allowing storage of password. I believe that it can be controlled in Administrative Tools -> Local Security Policy -> Local Policies -> Security Options -> "Network access: Do not allow storage of passwords and ...". I belive this should be set to disabled to be able to use the /RU and /RP.