Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a bat script to start and stop exe 1

Status
Not open for further replies.

jojo11

Programmer
Feb 2, 2003
189
US
I am using fwink software for a webcam on main street in my town. It uses a wireless connection, and every so often it gets stuck trying to upload a file and never finishes. I believe it is because the wireless goes away for a few seconds and causes the issue.

I know that when I manually stop fwink and start it the issue is resolved so I want to automate an hourly restart of the app.

I figured I could write a batch script that stops and starts the executable fwink. I could call the batch script from windows scheduler. I cannot figure out the start/stop script commands that could do this.

I also was told I could accomplish my restart goal via scheduler itself but also couldn't figure that out.

Any help appreciated.

Thanks

-------------------------------------------
Ummm, we have a bit of a problem here....
 
does it run as a service? if so have you tried net stop & net start?

When I was born I was so suprised I didn't talk for 18 months
 
Copy and paste the following into Notepad and save as something like 'restart-fwink.vbs'.

Code:
Dim WSH, strComputer, strProgName
Set WSH = Wscript.CreateObject("WScript.Shell")

strComputer = "." ' The period means 'this PC'
strProgName = "C:\progra~1\Fwink\fwink.exe"

'End the fwink.exe process
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'fwink.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

'Allow 4 seconds for process to end and close popup automatically
WSH.Popup "Fwink has stopped.",4

'Start Fwink again
WSH.Run strProgName

Set WSH = Nothing
Set objWMIService = Nothing
Wscript.Quit

There's no error checking to see if Fwink starts again but I've tested it and it works.

Hope this helps...
 
The trick is to use taskkill.exe

Example #1: No scheduler used

---------example fwink.cmd

@echo off
:BEGIN
; place here the command to start fwink. I will as an example use fwkink.exe

START /B "C:\Program Files\Fwink\fwink.exe"

CMD /k 'TASKKILL /f /fi "CPUTIME GE 01:00:00" /im fwink*'

GOTO BEGIN

---------------

Method #2: Scheduler used

--------- fwink.cmd
TASKKILL /f /im fwink*

------------

Note: For Task Scheduler to be able to use TASKKILL or any other program requiring a parameter, create a simple .CMD file as above and schedule the .CMD file.




____________________________
Users Helping Users
 
Oops... forgot to add:

1) Open Scheduled Tasks (Start > Programs > Control Panel > Scheduled Tasks).

2) Double-click on 'Add Scheduled Task'.

3) Click on 'Next'.

4) Browse to the 'restart-fwink.vbs' file, select it then click on the 'Open' button.

5) Select the 'Daily' option then click 'Next'.

6) Select the 'Every Day' option then click 'Next'.

7) Enter a valid user name and password then click 'Next'. (Note the warning that scheduled tasks might not run if the account doesn't have a password.)

8) Put a tick in the 'Open advanced properties...' checkbox then click 'Finish'.

9) Select the 'Schedule' tab then click on the 'Advanced' button.

10) Put a tick in the 'Repeat task' checkbox then adjust the settings to every hour with a duration of 1 hour and 1 minute then click on the 'OK' button.

11) Click on the 'Apply' then 'OK' buttons.

12) Right-click on the task and select 'Run' to check it's working from the scheduler.

You may have to make adjustments to the schedule but this should do it.

Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top