VBS - Prozess (.exe) Abfrage

  • VBScript

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von rYnow.

    VBS - Prozess (.exe) Abfrage

    Hallo,

    ich bin ein totaler Anfänger in VB-Script. Ich möchte über VBS abfragen ob eine .exe bereits läuft. Wenn Sie Läuft soll sie eine Variablie übergeben werden....

    Das ist mein Anfagen:

    Visual Basic-Quellcode

    1. Set Shell = WScript.CreateObject("WScript.Shell")
    2. Result = Shell.AppActivate("Microsoft Excel")
    3. If Result = True Then Prozessewert=1


    Soweit funktioniert das, aber nur wenn das Excell Fenster aktiv ist. Ich möchte aber auf die Prozesse im Taskmanager zurückgreifen und am besten alle in eine Variable übergeben. Leider scheitere ich auch beim Googeln....

    Vielen Dank für eure Hilfe


    Edit by Manschula: Willkommen im Forum! Wenn ich das richtig sehe, handelt es sich hier um VBScript; hierfür haben wir eigens ein Unterforum eingerichtet --> Thema verschoben

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Manschula“ ()

    Willkommen im Forum :)

    Du musst zuerst wissen wie der Prozess heisst. Im Fall Excel "EXCEL.EXE".

    Hab das Skript getestet, bei mir funktionierts:

    Visual Basic-Quellcode

    1. option explicit
    2. DIM strComputer,strProcess
    3. strComputer = "." ' local computer
    4. strProcess = "EXCEL.EXE"
    5. ' Check if Calculator is running on specified computer (. = local computer)
    6. if isProcessRunning(strComputer,strProcess) then
    7. wscript.echo strProcess & " is running on computer '" & strComputer & "'"
    8. else
    9. wscript.echo strProcess & " is NOT running on computer '" & strComputer & "'"
    10. end if
    11. ' Function to check if a process is running
    12. function isProcessRunning(byval strComputer,byval strProcessName)
    13. Dim objWMIService, strWMIQuery
    14. strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
    15. Set objWMIService = GetObject("winmgmts:" _
    16. & "{impersonationLevel=impersonate}!\\" _
    17. & strComputer & "\root\cimv2")
    18. if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
    19. isProcessRunning = true
    20. else
    21. isProcessRunning = false
    22. end if
    23. end function


    Sourcecode von: wisesoft.co.uk/scripts/vbscrip…a_process_is_running.aspx

    Für das nächste Mal:
    Wenn du googelst, und auf Deutsch nix findest, versuchs mit Englisch. Erster Versuch (vbs process running check), Erste Seite, Treffer ;)

    Mfg Dancger
    MESS WITH THE BEST, DIE LIKE THE REST! :evil:
    n'paar Links: DNS Tools, Steal WA DB, Droidsheep...
    WOW Super Antwort. Vielen Vielen Dank!!!!

    Meine Lösung sieht wie folg aus:

    Visual Basic-Quellcode

    1. option explicit
    2. DIM strComputer,strProcess
    3. strComputer = "."
    4. strProcess = "notepad.EXE"
    5. if isProcessRunning(strComputer,strProcess) then
    6. strProcess = "True"
    7. else
    8. strProcess = "False"
    9. end if
    10. function isProcessRunning(byval strComputer,byval strProcessName)
    11. Dim objWMIService, strWMIQuery
    12. strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
    13. Set objWMIService = GetObject("winmgmts:" _
    14. & "{impersonationLevel=impersonate}!\\" _
    15. & strComputer & "\root\cimv2")
    16. if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
    17. isProcessRunning = true
    18. else
    19. isProcessRunning = false
    20. end if
    21. end function