Solved

Batch file that runs in the background

Posted on 2010-11-12
6
1,218 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:jamorlando
Comment Utility
@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
Comment Utility
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
Comment Utility
@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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

9 Experts available now in Live!

Get 1:1 Help Now