Link to home
Start Free TrialLog in
Avatar of MJSAHLI
MJSAHLIFlag for United States of America

asked on

Trying to create and run a Scheduled Task via Command Line as local administrator will not run unless logged in as administrator.

I am trying to create and run a scheduled task via command line with local administrator credentials.  here is the example:

schtasks /create /ru administrator /rp <password> /st 00:00:00 /sc ONCE /tn scriptname /tr 'programname.exe'
schtasks /run /tn scriptname

This task is created successfully and shows up in the GUI but will not run = status could not start

If I login as the administrator in this example it works fine and runs fine but it's when I'm signed in as a normal user it fails every time.

Avatar of samiam41
samiam41
Flag of United States of America image

With the command you have listed, doesn't that create the task to run "once" with the credentials supplied?

Also, what permissions does the script have that you are mentioning?  Does the user that is logged in have permissions to the script?
Avatar of MJSAHLI

ASKER

Yes I want it to only run once.  The local users have the rights needed to run the task.  
So the user can browse to the path and execute the script without using task scheduler?  Are you creating this on a remote pc?

This site is where I get my syntax commands from and I noticed that there is a disclaimer about user permissions in it.

http://www.ss64.com/nt/schtasks.html

Where is the "programname.exe" located?  Network share/local?
Avatar of Joseph Daly
This is the syntax I used to create a recurring scheduled task using admin credentials on my machines. It is probably easily modified to do what you like.

schtask /create /tn "Taskname" /tr "program or batchyou want to run" /sc weekly /d mon,tue,wed,thu,fri /st 12:10:00 /ru "username" /rp "password"
Avatar of MJSAHLI

ASKER

samiam41:
So the user can browse to the path and execute the script without using task scheduler?  Are you creating this on a remote pc?

 - Yes the user can go to the location which is a network share an run the exe just fine.

- The .exe is actually a compiled AutoIT Script to run the setup of a software package that doesn't have the silent install option so I'm going to be deploying this to all machines in our network.  

Background:
We use a KACE KBOX for system management.  The problem with them is that they run everything as localsystem and I can't get the .exe file that I created to launch at all because it's trying to access the network.  So their idea is to run a task as administrator or a user with access to the network and then call the .exe that I want to run from the network.  

Again all this works fine as long as the user that is logged on is the same account that creates the scheduled task.

So why then when both users (administrator and user1) are local administrators and a task is created via command line when authenticated as administrator then it will run if the task username is administrator.  But if the task is created with user1 authenticated and the task user as administrator it fails.
Why not just make the exe into a service and let your SYSTEM account control it.  That would eliminate this problem.
ASKER CERTIFIED SOLUTION
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJSAHLI

ASKER

That's what I just was working on.  Thanks!
Are you serious?  Hahahahaha....