Windows Task Scheduler not running exe or bat. help please!

Wang191

[H]ard|Gawd
Joined
Nov 30, 2000
Messages
2,026
I'm having trouble scheduling a certain task. I want to know every time that I unlock my workstation. So I created a scheduled task with a trigger for "On Workstation Unlock". The action I set was "run program" and I linked it to a batch file that write the date and time into a file.
If I run the batch file by double clicking on it, it works fine. It doesn't ask for any privileges, it doesn't show me the UAC, it just works.

When I unlock my workstation, it runs the batch file (i added a puase command in there so i would see that it ran), but it doesn't actually write to the text file.

What gives? I also tried making an AutoIt script to write to the file because I have had better luck with running autoit commands from shortcuts, but that doesn't work either. It doesn't even seem to run.

Any help would be greatly appreciated.
I have clicked the elevated privlidges check button, I clicked run the operation when a user is away and put in my password. I checked off run as administrator on the batchfile and autoit exe as well.

no luck.
 
See if there is an event viewer log for unlocked workstation (under security?). If there is, do a right click on the event and attach a task. Maybe running the task that way will work.
 
No dice.
I saw it open the batch file but the batch file didn't write to the text file.
 
Try granting the user account full control of CMD.exe. Do it explicitly, not via group membership.

That is required when you have a service account kick off a batch file. Figured they'd fix that in 2k8/win7, but maybe they didn't.
 
How do I do that?
I went to windows/system32 and right click on cmd.exe but run as administrator is grayed out and I can't add my user to the permissions group.
 
How do I do that?
I went to windows/system32 and right click on cmd.exe but run as administrator is grayed out and I can't add my user to the permissions group.

Right click the file, choose properties
Hit the Security tab.
Hit the edit button.
Click add.
Type the name of the user account the service is running as, hit ok.
(don't recall if this is necessary) click the allow | modify box
Click ok; you'll get a warning about changing permission on system files - click yes


If you have permission to do that, it should now show the username in the list. If you get an error, then you don't have rights to change the permissions...
 
Yeah, I don't have permission to do that.
I'm looking into it to see if group policy is locking me out of that control. (It probably is)
Here at work I am local admin but there are a few things that they control via group policy. This seems like it's one of those things.
 
Ok, so they just changed the permissions on my account in group policy and gave me "modify" rights for cmd.exe.
I still can't change the properties for CMD to say run this as administrator...but if i'm an admin shouldn't it run with my rights?
 
I now have full access and it doesn't work.

The dos window opens but it doesn't write to the text file. It doesn't even indicate that it didn't write to the file.

I did change the properties in the AutoIt script executable to have "run as admin" checked and that one doesn't even seem to run.
 
crap.
It was user error.
It's not running the batch file from the location where my actual bat file is.
What i mean is, my batch file is in a folder called "log hours". it points to a local text file in the same folder.

But when task scheduler calls the file, it runs it from the c:windows/system32 folder. So it created a file in c:/windows/system32 called log.txt and wrote the values in that file instead of inside the "log hours" folder. Even though task scheduler was pointed to the batch file in the "log hours" folder.
 
The term your looking for is "working directory".

In the task scheduler, the setting is the "start in (optional)" setting. It's available on the same configuration page that you specify the command to run.
.
 
Thank you. I completely dismissed that setting because I assumed it would use the location of my bat file as the working directory.


I appreciate the help.
 
Back
Top