Jump to content
Sign in to follow this  
TJ3

Windows Task Scheduler (or alternative)

Recommended Posts

TJ3

Please help, I've been doing my nut searching for the answer ... :)

I am using Windows Task Scheduler to launch an autoIT script.

I am logged into two user (admin) accounts on one machine. While logged into one account, I want the script to launch/execute in the other user account (logged in).

Whatever I do, I always hit the same problem: the script will only execute when I access the other account, it won't execute in the background.

The above would be enough, but if anyone knows how to schedule a task while the other user account is not logged in, that would be helpful (in case power fails and/or a reboot is needed).

Thanks, I would confer genius status on whoever can answer this ... :P

I've been round the round about with this:

i.e. trying to configure task scheduler,

alternatives to task scheduler.

:)

Edited by TJ3

Share this post


Link to post
Share on other sites
weaponx

Maybe use RunAsSet and the command line task scheduler (schtasks.exe) to add the task for the desired (not the admin) account, or the System account if it will let you.

http://www.microsoft.com/resources/documen...s/schtasks.mspx

EDIT: Actually according to that link, schtasks accepts params for desired account / password

Edited by weaponx

Share this post


Link to post
Share on other sites
weaponx

Here is an example, it will launch notepad in the desired account one minute after running it, make sure your Task Scheduler service is running and verify the task gets created by clicking Start > Programs > Accessories > System Tools > Scheduled Tasks

;Get time 1 minute from now
$starttime = _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 5)
$result = RunWait ('schtasks /create /tn "My App" /tr ' & @WindowsDir & '\notepad.exe /sc once /st ' & $starttime & ' /ru admin /rp password')
If @error Then
    MsgBox(0,"","ERROR: " & $result)
EndIf

Who's a genius now?

Share this post


Link to post
Share on other sites
TJ3

Here is an example, it will launch notepad in the desired account one minute after running it, make sure your Task Scheduler service is running and verify the task gets created by clicking Start > Programs > Accessories > System Tools > Scheduled Tasks

;Get time 1 minute from now
$starttime = _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 5)
$result = RunWait ('schtasks /create /tn "My App" /tr ' & @WindowsDir & '\notepad.exe /sc once /st ' & $starttime & ' /ru admin /rp password')
If @error Then
    MsgBox(0,"","ERROR: " & $result)
EndIf

Who's a genius now?

Thanks, but I get an error 'Unknown function name'

starttime = _DateTimeFormat ( _DateAdd( 'n',1, ^ ERROR

? What do you reckon?

Share this post


Link to post
Share on other sites
JustinReno

Just look _DateTimeFormat!! :)

CODE

#Include <Date.au3>

Share this post


Link to post
Share on other sites
weaponx

Yea! What he said!

Share this post


Link to post
Share on other sites
lordofthestrings

an alternative(and better than the exploitable taskscheduler)

linux comes with it's own flavor of taskscheduler that works in a bit of a different way..

cron uses a table to determine which scheduled process to launch next.

you can specify in greater detail (and from commandline) the launch times..

check to download cron.exe (ported to windows)

why did I just mention taskscheduler is exploitable

simple:

taskscheduler is a system service. meaning everything it launches runs basically as system service unless you specify differently.

so if you use taskscheduler to launch CMD.exe you will get a CMD with the rights of NT Authority system. (this is the grand kahuna of your windows, it has more rights than administrator, it can access every aspect of your OS. (every regkey etc))

this is a cool trick if you're only a limited admin of this computer.

another one of these exploitable features is the stinkykeys M$ invented (for some unclear reason)..

(press shift quick 5 times) check what process it launches, (sethc.exe), overwrite this with CMD.exe and you should be able to launch CMD as system service even if you're not admin of this computer. (I checked this again , and it seems patched, or hotfixed or whatever)

cron doesn't have these design flaws..

just wanted you to have this info also :)


Share this post


Link to post
Share on other sites
weaponx

The method I presented will spawn the process in the specified account.

Share this post


Link to post
Share on other sites
TJ3

Thanks, lordofthestrings.

That's the direction I would prefer. I got the cron program up and running, however it seems to suffer the same problem as the Task scheduler. Only when I access the other user account session will the script start. Even if the other user account is logged in in the background.

Do you reckon its something to do with mouseclicks? The script I want to run has automated mouseclicks. If using the mouse in one session, can an automated script use mouseclicks in the background logged-in session?

Any suggestions helpful.

Justin, thanks for the suggestion - patience, I only started using AutoIt a week and a half ago. :">

Weaponx, thanks - still no luck though. It says it cannot access the external program.

I executed the following script in the current account - hoping to execute the program in the logged in background user account. What am I missing? :)

#include <Date.au3>
;Get time 1 minute from now
$starttime = _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 5)
$result = RunWait ('schtasks /create /tn "My App" /tr ' & @WindowsDir & '\notepad.exe /sc once /st ' & $starttime & ' /ru *I insert background username here* /rp **I insert background password here*')
If @error Then
    MsgBox(0,"","ERROR: " & $result)
EndIf
Edited by TJ3

Share this post


Link to post
Share on other sites
TJ3

The method I presented will spawn the process in the specified account.

Hey, thanks. Please see my note in my previous post. The script has mouse movements and clicks - would that hinder your method?

If not, what do I need to change to make it work? I changed what I thought was obvious (as per previous post), but no luck in opening the notepad?.

Does your script need to be located anywhere special?

I tried running it in the background account and in the current account (looking at the background account).

Thanks,

This is madness ... this ... is ... AutoITTTTTTTT!!!!!

Share this post


Link to post
Share on other sites
TJ3

Sorry, maybe I'm just being unclear.

Basically I just want the family to be able to use one User Account, and I want automated/scheduled stuff going on in the Second User Account securely. If anyone would be so kind, a step by step "for dummies" guide would be really helpful. I'm at a loss.

Specification:

One machine.

Two User Accounts (both admin).

Both logged on at the same time.

First User Account is in use (though will be locked for most of the time when away from the desk). Second User Account is locked.

I want to schedule a script to run in the Second User Account (while it is locked). This script makes use of mouse clicks, mouse moves, etc.

Please! ... is there some standard way of doing this? I thought the whole point of this was to be able to leave the computer to its own devices ... but securely at that. I want to be able to leave the house and have the PC running automated stuff, securely.

Help! Much appreciated.

Edited by TJ3

Share this post


Link to post
Share on other sites
TJ3

"I'm in the dark here !"

Posted Image

Share this post


Link to post
Share on other sites
weaponx

With my script you might need to set the working dir for RunWait() to the folder schtasks.exe is in (@SystemDir). Also what version of windows are you running? It's not XP Home Edition is it?

Share this post


Link to post
Share on other sites
TJ3

With my script you might need to set the working dir for RunWait() to the folder schtasks.exe is in (@SystemDir). Also what version of windows are you running? It's not XP Home Edition is it?

It is XP Home Edition, does that make a difference?

I can get a cron job running ... and it calls the script from any user account, but it will activate it and start running whatever account I'm in. I only want it to run in one account and in the background.

I tried a whole manner of different changes with your script, still no luck.

** prays to the programmings gods **

Share this post


Link to post
Share on other sites
weaponx

Schtasks.exe is not provided in Home Edition...you can copy it from a Pro installation.

Share this post


Link to post
Share on other sites
TJ3

Schtasks.exe is not provided in Home Edition...you can copy it from a Pro installation.

Ahh! I see. Ok. I copied a version from Pro. Placed it in system32. Here's the code. What do you reckon? Schtasks seems to load up now. But only for a split second, then stops.

#include <Date.au3>
;Get time 1 minute from now
$starttime = _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 5)
$result = RunWait ('C:\WINDOWS\system32\schtasks.exe /create /tn "My App" /tr ' & 'C:\Documents and Settings\UserAccountName\Desktop\myautoitscript.exe /sc once /st ' & $starttime & ' /ru UserAccountName /rp UserPassword')
If @error Then
    MsgBox(0,"","ERROR: " & $result)
EndIf

Share this post


Link to post
Share on other sites
weaponx

It should only flash briefly. Try it with the account are logged in as and follow my previous instructions to verify the task was created from the Start menu (Post #3 http://www.autoitscript.com/forum/index.ph...t&p=402080).

Edited by weaponx

Share this post


Link to post
Share on other sites
TJ3

It should only flash briefly. Try it with the account are logged in as and follow my previous instructions to verify the task was created from the Start menu (Post #3 http://www.autoitscript.com/forum/index.ph...t&p=402080).

Do you mean the StartUp Menu or Windows Start menu? I can't see that it is being created in either.

I've tried placing the script in the target User Account, in the active User Account ...

** scratches head **

Also, your script starts up notebook.exe ... do you think it will be able handle mouse clicks/movements also? My scrips depend on them.

Thanks for your help with your method ... I'm trying many other ways as well ... including other trial software ... nothing seems to work? Real odd.

Share this post


Link to post
Share on other sites
TJ3

Hmm, how does this sound ... what I am requiring requires two users active at the same time ... when I click on "Users" in Windows Task Manager ... one of the Users is always Inactive.

So if I am in the Target User Account, the other User Account is inactive, and vice versa ... even if both are logged on.

Does that sound like the source of the problem? I've been going down the route of looking into things like Terminal Services and Server Software ...

If anyone can prevent me from going totally off the right track, please speak up!

If this does sound like the source of the problem, if anyone has any experience with this -please recommend software - Windows Server 2003? donno.

Thanks, guys.

Edited by TJ3

Share this post


Link to post
Share on other sites
TJ3

Sorry, I meant to say - when fast switching between the two User Accounts - though they are both logged on, the current User Account is always "Active" and the other User Account is always "Disconnected".

Any ideas?

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  

×