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
Solved

Batch file that runs in the background

Posted on 2010-11-12
6
1,223 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
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.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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