Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 178381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:13:17+00:00 2026-05-11T14:13:17+00:00

I have a scenario setup where I need to test to see if the

  • 0

I have a scenario setup where I need to test to see if the results of a .bat file execution returned results. The .bat file calls up another .exe and the .bat file has a CMD DOS window that outputs critical error info to that DOS box from the .exe. If the .exe does not start correctly, I am able to check the results in our SQL DB. I need to close the current .bat file and re-launch it. This seems fairly simple, I can get the ProcessID using the WMI call. I can terminate the process with a Terminate() command. This works for any .exe I use for testing: notepad, calc, iexplorer, etc. When I run the VBScript to kill the .bat file, it says it terminates the PID (which it does, since I cannot see the PID anymore), however, the DOS box is still open and the .exe called from the .bat file is still running. If I click on the ‘X’ on the DOS box or right-click on the title bar and select ‘Close’, the DOS box and the .exe are both killed. How do I get this script to work correctly. The server is running Windows Server 2003 (some are x32 and others are x64). Any ideas? Here is a version of my code, there have been several revs:

If colFiles.Count = 0 Then Wscript.Echo 'The file does not exist on the remote computer.' Else Wscript.Echo 'The file exists on the remote computer.' Set objWMIService = GetObject('winmgmts:' & '{impersonationLevel=impersonate}!\\' & strComputer & '\root\cimv2') Set colProcessList = objWMIService.ExecQuery('Select * from Win32_Process') For Each objItem in colProcessList If InStr(objItem.CommandLine, 'r15_A.bat') Then     Wscript.Echo 'Batch file: ' & objItem.CommandLine  & '  Process ID: ' & objItem.ProcessID & '  Parent ID: ' & objItem.ParentProcessID     Call TerminateProcess(objItem.ParentProcessID)     Call TerminateProcess(objItem.ProcessID) End If Next dim shell set shell=createobject('wscript.shell') shell.run BATDIR & BATFILE 'set shell=nothing End If   Function TerminateProcess(PID)  Set objWMIService = GetObject('winmgmts:\\.\root\CIMV2') Set colProcesses = objWMIService.ExecQuery('SELECT * FROM Win32_Process WHERE Handle = '' & PID & ''') For Each objProcess in colProcesses On Error Resume Next return = objProcess.Terminate() Set colProcesses = objWMIService.ExecQuery('SELECT * FROM Win32_Process WHERE Handle = '' & PID & ''')  If Error Then  TerminateProcess = FALSE Else TerminateProcess = TRUE msgBox colProcesses.Count End If Next  End Function 

I have even tried to use the SendKeys to send ALt-F4, X, C, etc. AppActivate does bring the correct DOS box to the front.

    Set WshShell = CreateObject('WScript.Shell')     WshShell.AppActivate 'r15_A'     'WshShell.SendKeys('+{F10}')     WshShell.SendKeys('C')    

Thanks in advance

EDIT————– Yes, I am going to have to kill the process that this .bat file calls. Only down side is this DOS box stays open. Annoying but I can live with it. In the end I wrote a script similar to my first one but only checks for the instance I want to kill by checking the CommandLine parameter: (The first bit of code with ‘-FAIL.txt’ test to see if a FAIL file is present, if it is, then the rest of the scipts executes)

Set colFiles = objWMIService. _ ExecQuery('Select * From CIM_DataFile Where Name = 'S:\\servers\\Logs\\' & LOGFILE & '-FAIL.txt'')  If colFiles.Count = 0 Then 'Wscript.Echo 'The file does not exist on the remote computer.' Else 'Wscript.Echo 'The file exists on the remote computer.' strComputer = '.' Set objWMIService = GetObject('winmgmts:' _ & '{impersonationLevel=impersonate}!\\' & strComputer & '\root\cimv2') Set colProcessList = objWMIService.ExecQuery _ ('Select * from Win32_Process Where Name = 'AppStart.exe'') For Each objProcess in colProcessList     IF instr(objProcess.CommandLine, 'robo05-A') > 0 THEN          'msgBox 'Found text'         objProcess.Terminate()         'This part restarts the failed .bat file.         wscript.sleep (200)          dim shell         set shell=createobject('wscript.shell')         shell.run BATDIR & BATFILE         'set shell=nothing     ELSE         'msgBox 'Not found'     END IF Next End If 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:13:17+00:00Added an answer on May 11, 2026 at 2:13 pm

    The problem your having is the the executable that is being called from within your batch file is still running. I tried to recreated your setup with a bat the just did a ping -t %computername%, and sure enough the vbscript killed the cmd.exe but not the ping (Please note the Parent PID was explorer.exe, so you probably don’t want to attempt killing that). Now I could easily kill ping.exe from task manager which then closed the window…but I only knew to do that because I knew what the bat was doing and what was left open. You could do a WMI search for the process that contains ‘ping.exe’, grab the PID and then close that and that would basically be doing the same thing. Of course in your situation ‘ping.exe’ is probably not the same executable as mine. If the exe changes every now and then then you could grab the commandline from your process find the parameter which contains the filepath to the r15_A.bat file, then use the filesystemobject to open this bat file, look for any executables which it calls which could possibly be still running and then kill those….but really that may be overkill for what your trying to accomplish.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario where I need to upload a file from one web
I have scenario where I need to host a web service (WCF) on Azure
Scenario I have a server, that has NO Visual Studio Installed. It literally has
I have a scenario in which I think I need to lock a table
I have the following setup (which works fine). Using CodeFirst (CTP4). A template has
I have setup mappings for a number of classes, however in some scenarios I
I have scenario, I have two update panels on the page (both have update
I have scenario where I have to use the same XSD element for different
Hi here is what I what I have: Scenario Outline: Seatching for stuff Given
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.