Solved

Batch file that runs in the background

Posted on 2010-11-12
6
1,220 Views
Last Modified: 2012-05-10
Hi,
Currently I have a batch file which is an infinite loop that runs in the background.  Task scheduler starts it, and it runs in the background without me needing to be logged in.

However, if kill the process, I can't figure out a way to start this back up in the background.

If I right click and run the task, it opens in a window.
I even found a simple VBScript to run a batch file using vbhide to hide the window.  However, using this, I'm unable to log out!

How can I emulate task scheduler behavior without explicitly using task scheduler?

Thanks,
Jamie
0
Comment
Question by:jamorlando
6 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34124841
You can try to download Windows 2003 Resource Kit and use InstSrv and SrvAny commands to set up your batch as service.

Try, maybe it would solve your problem.

Resource Kit you will find here
http://www.microsoft.com/downloads/en/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

and hot to set up batch as service, Microsoft's article explains it well
http://support.microsoft.com/kb/137890

Regards,
Krzysztof
0
 
LVL 7

Accepted Solution

by:
fhmc earned 500 total points
ID: 34126255
why not execute the task w/ another user's credentials?

so, say a windows xp box...
you typically logon as domain\user
create a new local user 'x'
place the .bat file in a local file path that you've assigned local user 'x' privileges to
create a new task that executes the batch file as user x
when the task fires it should not appear in your desktop window as it's being executed as another user.
0
 
LVL 4

Expert Comment

by:Vishal Patel
ID: 34135239
HI,
Try this out. Copy following four lines to any word editor and save this file as .vbs & run it. It will keep running without any visible output.

Dim oWsh, commands
Set oWsh = WScript.CreateObject ( "WScript.Shell")
command = "your command(with arguments) or batchfile(with fullpath) goes here"
oWsh.Run command, 0


0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:jamorlando
ID: 34135929
@iSiek, thanks .. I've dabbled in creating services before but maybe I'll give it another shot

@fhmc, wouldn't that user have to be logged in at all times for the loop to continue to run?

@vjpatel, I'm not sure but I think:
oWsh.Run command, 0
is the same as
oWsh.Run command, vbhide
Which means that if the user logs out, the script stops running.
0
 
LVL 7

Assisted Solution

by:fhmc
fhmc earned 500 total points
ID: 34136317
No user would log on at all, per se.  A user account would be associated to the scheduled task that would run independent of all desktop logons, though you would see the process in task manager when the "show processes from all users" box was checked.

You can quickly test this by:

clicking start->run->tasks->ok

create a new task
name it
in the run field type:  ping -t 127.0.0.1
in the runas field use an account name that's not currently logged in
save
execute the task

you should not see a ping window open, but you will see ping.exe in your running process list via task manager as a different user.

log out of windows then log back in.  ping should still be running and not on the screen.
This task could be configured to fire at startup similar to a service or run on a custom schedule.

Hope this helps
0
 

Author Comment

by:jamorlando
ID: 34138598
@fhmc, this was the clever, simple solution I was looking for.
Tried it out and it works perfectly.

Now if the process stops, I can manually start it again without having to reboot the machine!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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