?
Solved

Batch file that runs in the background

Posted on 2010-11-12
6
Medium Priority
?
1,227 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
[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
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 2000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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