Batch file to stop/start a program

BokehBokeh Member Posts: 1,636 ■■■■■■■□□□
We have a program that we need to close at a specific time, let our backup do its stuff, then restart the program later.

Best way would be to buy new backup software that does open files, but that is not an option at this time. So looking for a batch file that can stop/start via scheduler. Everything I have searched for shuts down entire machine, and we just need one program to close at midnight, and open at 4am.

Any help would be appreciated.

Comments

  • Hyper-MeHyper-Me Banned Posts: 2,059
    pskill would work as long as you dont mind the program coming to a screeching hault. :D
  • RobertKaucherRobertKaucher Member Posts: 4,299 ■■■■■■■■■■
    +1 for PSKill in this case. But as Hyper-Me pointed out it kills the process, it does not just shutdown the application.
  • TechJunkyTechJunky Member Posts: 881
    A simple vb script could accomplish what you want.

    Something like the below. I use this for one of the services we have here that we need to start to update and then kill.

    'Start Service
    strServiceName = "SSClientService"
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
    For Each objService in colListOfServices
    objService.StartService()
    Next

    WScript.sleep 7200000

    'Stop Service
    strServiceName = "SSClientService"
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
    For Each objService in colListOfServices
    objService.StopService()
    Next
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    +1 for the VBscript. You can use it check if the service/process is running and then shutdown that program. We use it on peoples laptop to check for a valid internet connection and Cisco VPN service running before allowing a connection.
  • phoeneousphoeneous Member Posts: 2,333 ■■■■■■■□□□
    Or just create two tasks in task scheduler linked to two different batch files, one with net stop <service> and the other with net start <service>. Set the time you want to tasks to kick off and voila.
  • DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    psexec will allow you to run a command remotly, so rather then PSkill you coudl gracefully shut down the program.

    but I am all for a secduled task.
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Hyper-MeHyper-Me Banned Posts: 2,059
    DevilWAH wrote: »
    psexec will allow you to run a command remotly, so rather then PSkill you coudl gracefully shut down the program.

    but I am all for a secduled task.

    PSEXEC is for executing, not shutting down.

    A simple net stop/net start batch would work, assuming the program runs as a service.
  • DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    Hyper-Me wrote: »
    PSEXEC is for executing, not shutting down.

    A simple net stop/net start batch would work, assuming the program runs as a service.


    he doesn't want to shut down he wants to close a program.

    now some programs have command line arguments to shut down gracefully. so you can use PSexec to run that remotley.

    or you can set up a batch file to close the program and then run that remotely using psexec. (useful for when the backup software is running from a remote server so you can easly sync them together.)

    net start and stop are great for services, but pskill is in my view an untidy way to kill a process.
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Hyper-MeHyper-Me Banned Posts: 2,059
    Right, you can psexec IF the programs exe supports a switch to close it.

    I didnt mean shut down the machine, I meant shut down the program. PSkill specifically kills a specified process.

    Assuming the program doesnt run as a service, a Net stop/net start batch wont suffice.
Sign In or Register to comment.