-1

Could you please help me to write an excel macro which will check; is there any background Power Shell script is running in the machine?

Thanks, Aneesh

Community
  • 1
  • 1
Aneesh
  • 69
  • 1
  • 5
  • Usualy people post code they've already wrote and tryed. Please read [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question/284237#284237) – AntiDrondert Dec 12 '17 at 07:51

1 Answers1

0
Sub IsPowerShellRunning()
    Debug.Print IsProcessRunning("powershell.exe")
End Sub

Function IsProcessRunning(process As String) as Boolean
    Dim objList As Object

    Set objList = GetObject("winmgmts:") _
        .ExecQuery("select * from win32_process where name='" & process & "'")
    If objList.Count > 0 Then
        IsProcessRunning = True
    Else
        IsProcessRunning = False
    End If

End Function

(Source)

ashleedawg
  • 20,365
  • 9
  • 72
  • 105