Sign in to follow this  
Followers 0
F8LDXSL4P

Run as logged user only task scheduler HELP

12 posts in this topic

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

Share this post


Link to post
Share on other sites



I take it that using Send commands is probably the best solution to this issue?

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I would like to use that but how do i get around the password argument?

2whdtf4.png

 

@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 by F8LDXSL4P

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by F8LDXSL4P

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by F8LDXSL4P

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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 off
if exist "exists.txt" del "exists.txt"
for /F %%A in (SNL.txt) do (

Echo %%A

schtasks.exe /create /f /tn "Start Spawner" /XML "I:\Schedualed Taks XML\Start Spawner.xml" /s %%A

schtasks.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>

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0