F8LDXSL4P Posted September 26, 2014 Posted September 26, 2014 Hello im trying to schedule a task in task scheduler that will "Run Only When User Is Logged In" ... Seems easy since you just add /IT into the schtasks /create command line.. problem is this is a bug/glitch in windows. Since doing a schtasks /change /ru username /tn Task /IT will fix it, the problem is it will ask for the password after sending the command. How can i also send the password with the change command?? Ive tried using the following code: Run("C:\WINDOWS\system32\cmd.exe", "") WinWaitActive("C:\WINDOWS\system32\cmd.exe") $ssmessage1 = 'schtasks /change /tn TASK /it' $ssmessage2 = 'password' $ssmessage3 = 'exit' WinActivate("C:\WINDOWS\system32\cmd.exe") Send($ssmessage1 & "{ENTER}") WinActivate("C:\WINDOWS\system32\cmd.exe") Send($ssmessage2 & "{ENTER}") WinActivate("C:\WINDOWS\system32\cmd.exe") Send($ssmessage3 & "{ENTER}") Exit But doesn't really work the best. Is there a better way to do this? Thanks
F8LDXSL4P Posted September 29, 2014 Author Posted September 29, 2014 I take it that using Send commands is probably the best solution to this issue?
spudw2k Posted September 29, 2014 Posted September 29, 2014 You could bypass the CMD prompt by just using Run (probably better than Send). Run(@comspec & " /c schtasks.exe ....") Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
jdelaney Posted September 29, 2014 Posted September 29, 2014 Agreed with the cmd line. You can also create the task, export it, and use the XML to drive importing, later. Kind of like a template, which can be modified with XMLDOM. There's nothing you can't do through the xml, that can be done through the gui/cmd line. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
F8LDXSL4P Posted September 29, 2014 Author Posted September 29, 2014 (edited) I would like to use that but how do i get around the password argument? @jdelaney: Ive tried going the XML route and it does import "Run as logged user", but i have to enter the password (like pic above) to change the Start time. I tried changing the time with /st when creating a task with the XML but the /st parameter is not allowed when using XML import Edited September 29, 2014 by F8LDXSL4P
spudw2k Posted September 29, 2014 Posted September 29, 2014 (edited) Does /rp password work? You could also user StdInWrite to provide the password to the process. https://www.autoitscript.com/autoit3/docs/functions/StdinWrite.htm Edited September 29, 2014 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
F8LDXSL4P Posted September 29, 2014 Author Posted September 29, 2014 (edited) If I use schtasks /change /ru foradmin /rp password /tn Task /it ... it will say SUCCESS: The scheduled task "Task" has been changed but does not change it to "Run as logged user". Darn Windows bug EDIT Another thing i tried is this: schtasks /create /XML template.xml /tn TASK Works, Run as logged user.. Then did this: schtasks /change /ru foradmin /rp password /tn TASK /st 3:00:00 with and without /it Success, but changed it from Run as logged user to Run whether user is logged in or not... Edited September 29, 2014 by F8LDXSL4P
spudw2k Posted September 29, 2014 Posted September 29, 2014 I updated my post above...in case you didn't see it. You should be able to use StdInWrite. I posted a link to the online Help function reference. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
F8LDXSL4P Posted September 29, 2014 Author Posted September 29, 2014 (edited) So i tried this code.. Problem is it doesn't ask for the password and goes through successfully but still doesn't change the Run as logged user option. If i manually open command prompt and put the /change command in there it will ask for it.. Strange #include <Date.au3> #include <Constants.au3> $sNewDate = _DateAdd('n', 2, _NowCalc()) $timesplit = StringSplit($sNewDate, " ") $schtask = 'schtasks /create /ru foradmin /rp password /sc once /st ' & $timesplit[2] & ' /tn TASK /tr notepad.exe' $schtask2 = 'schtasks /change /ru foradmin /tn Task /it' $schtask3 = 'password' $wbpid = Run("C:\Windows\system32\cmd.exe", @SystemDir, @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($wbpid, $schtask) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid, $schtask2) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid, $schtask3) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid) Edited September 29, 2014 by F8LDXSL4P
jdelaney Posted September 29, 2014 Posted September 29, 2014 You should just setup the task to run as admin, with highest priviledges, and then run PAEXEC with the interactive flag. That will work for any logged in user. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Solution F8LDXSL4P Posted September 29, 2014 Author Solution Posted September 29, 2014 I figured it out! I had to create a task based on the XML template and then change the time to what i want. Didn't ask for the password when i changed the time but didnt change it from "Run only when user is logged in" to "Run whether user is logged in" either! @jdelaney: I needed it to run as the "foradmin" user as the task is launching a screenshot program and it wouldn't capture the user's desktop unless the "Run only when user is logged in" was selected. Thanks for all your help guys! Heres the solution code $sNewDate2 = _DateAdd('n', 2, _NowCalc()) $timesplit2 = StringSplit($sNewDate2, " ") $schtask = 'schtasks /create /XML template.xml /tn TASK' $schtask2 = 'schtasks /change /tn TASK /st ' & $timesplit2[2] $schtask3 = 'password' $wbpid = RunAs("foradmin", @ComputerName, "password", "", "C:\Windows\system32\cmd.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($wbpid, $schtask) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid, $schtask2) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid, $schtask3) StdinWrite($wbpid, @CRLF) StdinWrite($wbpid)
Pumpkinpizza Posted January 1, 2016 Posted January 1, 2016 Was using this script to create task across out 162 Render node servers, I found that if I specified a Username and Password the task would not "run interactively" and thus be hidden to the user, which also meant it didn't work.So I used the @echo offif exist "exists.txt" del "exists.txt"for /F %%A in (SNL.txt) do (Echo %%Aschtasks.exe /create /f /tn "Start Spawner" /XML "I:\Schedualed Taks XML\Start Spawner.xml" /s %%Aschtasks.exe /create /f /tn "Start BB Server" /XML "I:\Schedualed Taks XML\Start BB Server.xml" /s %%A) Here is an example of the xml file: NOTE the "<LogonType>InteractiveToken</LogonType>" line is important too. Refer to: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382075(v=vs.85).aspx <?xml version="1.0" encoding="UTF-16"?><Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2015-11-25T11:50:29.7325058</Date> <Author>BINYAN\Render</Author> </RegistrationInfo> <Triggers /> <Principals> <Principal id="Author"> <UserId>Binyan\Render</UserId> <LogonType>InteractiveToken</LogonType> <RunLevel>HighestAvailable</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>false</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <Priority>7</Priority> </Settings> <Actions Context="Author"> <Exec> <Command>"C:\Program Files (x86)\Autodesk\Backburner\server.exe"</Command> </Exec> </Actions></Task>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now