Solved

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

Posted on 2008-06-24
20
196 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:virus_ii
  • 12
  • 8
20 Comments
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21854189
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!
0
 

Author Comment

by:virus_ii
ID: 21854285
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...
0
 

Author Comment

by:virus_ii
ID: 21854292
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...
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21854310
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
0
 

Author Comment

by:virus_ii
ID: 21854385
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...
0
 

Author Comment

by:virus_ii
ID: 21854407
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...
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21854497
Have you tried creating an administrator equivalent user (e.g. DUMMYADMIN) to do the job?
It might be a workaround for the SID problem.
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21854506
And hey, I still use Windows 2000 too ;-) Nothing wrong with that, as far as I'm concerned.
0
 

Author Comment

by:virus_ii
ID: 21854568
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!
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21854828
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!
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:virus_ii
ID: 21854887
Will try, let you know...
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21855199
Great! If you need help with the syntax, please let me know.
0
 

Author Comment

by:virus_ii
ID: 21855239
Will be off tomorrow, back at work on Thursday. Will try during the course of the morning and let you know. Tx!
0
 

Author Comment

by:virus_ii
ID: 21881696
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?
0
 

Author Comment

by:virus_ii
ID: 21881702
I mean the 'schtasks' command; not the 'sctashs' command... (duh, spellcheck on strike)...
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 21881948
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!
0
 

Author Comment

by:virus_ii
ID: 21913346
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?
0
 
LVL 12

Accepted Solution

by:
RubenvdLinden earned 500 total points
ID: 21932241
Did you include the /u (user) and /p (password) parameters in the SCHTASKS command to use the administrator user to run the task?
0
 

Author Comment

by:virus_ii
ID: 21932304
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!
0
 

Author Closing Comment

by:virus_ii
ID: 31470069
As per above comment...
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now