Creating a batch file to run Net command

Hi,

 I have a program called "workflow" in the Services.msc in Windows 2008 Server.
 It fails frequently (at least once every week) and I have been manually restarting the service  in Services.msc.

  I created a batch file "Restart_Workflow.bat" (with two lines of code: (1) net stop workflow
(2) net start workflow)  in the C drive and wanted to schedule it once a day so that it restarts "workflow" service automatically, but it does run.
  When I run this "Restart_Workflow.bat"  file, it fails to run  and I think it is because I have to run this "as administrator".  But I don't know how to make Command Window open during batch file execution.
 

 Can you help?
LVL 1
sgleeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SylvainDrapeauCommented:
Maybe it runs too fast and there is not enough time between stop and start ?

Try inserting a "ping localhost" between the two, it will give you 4-5 seconds between stop and start... may be enough.

If it is scheduled with Task Scheduler, you can provide another user account (administrator if you want) and a password in the first tab of the job (at the bottom).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sgleeAuthor Commented:
I added  "ping localhost" and actually I was able to see the error.

Access Error
As I suspected, somehow I need to be able to open Command Windows "As Administrator" to run these commands.
0
SylvainDrapeauCommented:
Like I said, run the task under the administrator account (see attached image). In this example, the user is Local\SQLAdmin, yours should be Local\Administrator.

Scheduled task properties
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

sgleeAuthor Commented:
Scheduled TaskI created a schedule that runs "Restart_Workflow.bat" once a day. Then I ran it manually, but failed with "access denied". Security Options already shown as Domain Admin account.
So I changed it to Local Admin, but to no avail.
Then I chose "Run with highest privileges" and it ran successfully.

Thanks for your help.
0
SylvainDrapeauCommented:
Great, only problem I still see is the account "Administrators" which seems to be a group instead of a user, and the inability to check "Run whether user is logged on or not" which will prevent the task from running if no one is logged on the console.

I would change the account to an administrator account (Local of Domain) and check "Run wheter user...". Then you should be good to go.
0
sgleeAuthor Commented:
Maybe that might explain why this "workflow" service fails to work from time to time?
Sometimes it fails to work a couple of times a day (it is rare). Sometime it fails several times a week.
0
SylvainDrapeauCommented:
That would be another question really... we'd need to see Windows Event Logs for the failed service and why you have to stop/restart it...

The scope of the current question was to troubleshoot your batch file, and it seems to be resolved.

I would advise to open a new question with as much detail as possible about the service that is failing, which application installed it and any relevant events in the Event Log.
0
sgleeAuthor Commented:
Good advise. Thank for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.