Solved

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

Posted on 2008-06-24
20
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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
 

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

635 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