How to "Complete task" not "Kill" or "Complete"?
I have a 3G card to provide internet on a remote computer ... I need to run a program (provided with a card) to establish a connection ... since the connections are suddenly lost, I wrote a script that Kill the program and reopen it to restore connection, there are certain versions of this program that do not kill the connection when it is destroyed / terminated, only when they are closed properly.
so I am looking for a script program or program that "closes" the window "correctly" so that I can close it and reopen it if the connection is lost.
this is the code that kills the program
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'Telcel3G.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit
a source to share
If you need to use VBScript, one easy way would be to activate the application and then use SendKeys to restore it if minimized and send it "alt-f4". This is a hack, but it might be easier than finding the handle to the main window, and it might work well enough for you.
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'Telcel3G.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
dim WshShell
set WshShell = CreateObject("WScript.Shell")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
WshShell.AppActivate objProcess.ProcessId
WScript.Sleep 1000
WshShell.Sendkeys "% r"
WScript.Sleep 1000
WshShell.Sendkeys "%{F4}"
Next
a source to share