Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   There has got to be a better way..... (http://www.programmingforums.org/showthread.php?t=10925)

randum77 Aug 2nd, 2006 1:40 PM

There has got to be a better way.....
 
Ok, presently this is the method I use for running an external *.exe from within a vbscript.

:

strComputer = "."
        Hidden_Window=5
        Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        set objStartup = objWMIService.Get("Win32_ProcessStartup")
        Set objConfig = objStartup.SpawnInstance_
        objConfig.ShowWindow = Hidden_Window
        Set objProcess = GetObject ("winmgmts:root\cimv2:Win32_Process")
        errReturn = objProcess.Create("D:\ISRA\COSS\Filewatch.exe", null, objConfig, intProcessID)


Is there a better way to run an external *.exe from within a VBScript? I need to run it, then kill it. I search for a bit but couldn't find anything useable. Thanks in advanced.

melbolt Aug 2nd, 2006 6:54 PM

Hi, give this a try.

:

  1. <script language = "vbscript">
  2. sub launcherSub()
  3. dim progName
  4. progName = "D:\ISRA\COSS\Filewatch.exe"
  5. set oShell = createobject("wscript.shell") 'create a shell
  6.  
  7. '***use the line below to call your app, defined above with the "progName" variable:
  8. oShell.run(progName)
  9. end sub
  10. </script>


check out this page for additonal parameters you can use with the run method. http://www.devguru.com/Technologies/...shell_Run.html

melbolt Aug 2nd, 2006 7:28 PM

oh, and you wanted to kill the process too.

:

  1. Option Explicit
  2. Dim objWMIService, objProcess, colProcess
  3. Dim strComputer, strProcessKill
  4. strComputer = "."
  5. strProcessKill = "'Filewatch.exe'"
  6.  
  7. Set objWMIService = GetObject("winmgmts:" _
  8. & "{impersonationLevel=impersonate}!\\" _
  9. & strComputer & "\root\cimv2")
  10.  
  11. Set colProcess = objWMIService.ExecQuery _
  12. ("Select * from Win32_Process Where Name = " & strProcessKill )
  13. For Each objProcess in colProcess
  14. objProcess.Terminate()
  15. Next
  16.  
  17. WScript.Quit


basically it queries running processes for the desired one and terminates it.

note: I'm not sure if this is being performed on the local machine or on a remote machine, the code above is for local, if you want to kill on remote machine, check the link below.

all this code was stolen from here, i take no credit but i did test them personally and they work
http://www.computerperformance.co.uk...ocess_stop.htm


All times are GMT -5. The time now is 12:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC