Link to home
Start Free TrialLog in
Avatar of virus_ii
virus_iiFlag for South Africa

asked on

Creating a script to run an application as specific user at a specific interval

I am a 'scripting virgin'; have played around with batch files but can't get my machines to do what I want from within a batch file. I have 'sort of' gotten it working with the default Task Scheduler but it required a slight tweak on each machine.

I log on with a local user (not admin) account and I have an application that I need to run on both my Windows 2000 and Windows XP machine at logon and every 30 minutes on the half hour thereafter. I need the application to be run as a specific user (local Admin) with a specific password. The Administrator name and password are the same on both machines.

Lets say that the application is called BIS.EXE and is located at "C:\Program Files\BIS\BIS.EXE". Lets also say that the admin account is called ADMINISTRATOR and the password is PASSWORD. Obviously not the case, but there to make life easier in this case.

Thanks,

virus_ii
Avatar of RubenvdLinden
RubenvdLinden

I would recommend to use the task scheduler. With a small tweak you can schedule a task to run every 30 minutes.

- Create the task and schedule it to run every day. Use the Administrator credentials to run the task.
- Select the properties of the newly scheduled task, select the Schedule tab, then press the 'Advanced' button
- Select the 'Repeat Task' radio button and set it to every 30 minutes.

To run the task at startup, simply create a copy of the task and schedule it to run at logon only.

I hope this helps!
Avatar of virus_ii

ASKER

Hi RubenvdLinden,

I have tried this, but then when I SYSPREP the machine and give it a new name, the task fails to run because the SID of the Administrator is different (although the username/password combination are the same) and the tasks don't run without the account credentials being updated.

Sorry, I should have mentioned the SYSPREP thing, my bad.

If I can get a script that will do the above, it should (I think) be independant of the SID, and use the username/password only. I hope that makes sense...
I have also tried to 'batch' the command and use the runas command (the default one and one I downloaded) but neither do what I want them to...
Do you actually get a message that the SID is incorrect?
It also might be this problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;253942
No actual error, but after the sysprep'd machine goes through it's mini-setup and finally gets back to the desktop (I have lost count of the number of times I've seen it over the last couple of days) and go into the task scheduler, I can see that both tasks still exist but they fail to run. I then go into the task, put in the password again and reboot. Then it works. So I am assuming it has something to do with the SID which gets 're-generated' during sysprep...

I am trying to get an image of a machine that requires MINIMAL and user/end tech (sometimes surprisingly similar!) involvment; aksing the end tech to do something like put in the password gives them too many points of failure. Sometimes I think that binary gives them too many options, but that's just mean isn't it? :)

I had a look at the above link, but it doesn't look like the problem since my tasks don't run after reboot because of the password thingy...
And, yes, we still use Windows 2000. Hey, we finally got rid of the last Windows 98 machine about 18 months ago... OS2 is IN THE PROCESS (ie we still have some) of being replaced. "If it still works, don't $%@&^% with it" takes on a whole new meaning here...
Have you tried creating an administrator equivalent user (e.g. DUMMYADMIN) to do the job?
It might be a workaround for the SID problem.
And hey, I still use Windows 2000 too ;-) Nothing wrong with that, as far as I'm concerned.
We're not allowed to have any additional local admin accounts on machines, set by our audit department. This is why I was looking for a script file to put into the <All Users>\Startup folder with a batch file that is set to delete itself after the script is run (so that the file containing the admin account credentials gets deleted) and then force a reboot. I can do all of the above except the script part...

ASIDE: just read the funniest quote attributed to Ray Stanton "You can't patch for stupidity". Boy does that sometimes apply :-)

ASIDE AGAIN: Go watch an Aussie film called KENNY (2006). LMAO!
The SCHTASKS.EXE command utility from Windows XP / Windows 2003 should be able to do the job.
More info can be found here: http://support.microsoft.com/kb/814596

Unfortunately, by default it will not run on Windows 2000. There's a modified version on the net however that will work: http://smallvoid.com/article/win2k-task-scheduler-schtasks.html

I hope this helps!
Will try, let you know...
Great! If you need help with the syntax, please let me know.
Will be off tomorrow, back at work on Thursday. Will try during the course of the morning and let you know. Tx!
Update:

Right, the command works fine. Providing that the user logged on is an admin. If I log on with a 'user' the command doesn't run because the sctashs command requires admin priv's to run. Still looking for  solution...

Any ideas?
I mean the 'schtasks' command; not the 'sctashs' command... (duh, spellcheck on strike)...
You could try adding the SCHTASKS command to the cmdlines.txt of your SysPrep installation.
If that doesn't work, you can set the SysPrep installation to logon automatically as 'administrator' (one time only) and put a batch file with the SCHTASKS command in the GuiRunOnce section of SYSPREP.INF:

@echo off
START /WAIT SCHTASKS <your parameters>
SHUTDOWN /L /R /C


SHUTDOWN makes sure the computer reboots so you do not need to logoff the administrator manually.
The Shutdown command is not included in Windows 2000 by default. You can download it here: http://www.dynawell.com/reskit/microsoft/win2000/shutdown.zip

I usually add it to the SYSTEM32 folder.


I hope this helps!
No matter where I put it, the 'schtasks' and 'BSI.EXE' require admin rights to run. If I run it from the user account it does not run. I schedule it from (while logged on as) the ADMINISTRATOR and reboot, and it works fine if I log back in as ADMINISTRATOR, but does not run if I log in as USER.

If I log in as USER (task does not run) and back out, and in again as ADMIN (the task runs fine) and have a look at the APPLICATION event log, there is a 'access denied' at the time that the USER logs in, but none for the ADMIN.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of RubenvdLinden
RubenvdLinden

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
Hi Ruben

Solved the problem, but not using a script. I RTFM'd the help file and found what I was doing wrong. I'll accept your last comment as the answer though since you did help me out.

Thanks!
As per above comment...