Praveen
Praveen

Reputation: 261

VBScript to check if process is running (using wildcard)

I need to check if a process is running. The thing here is that my process names may vary each time it is triggered.

The process name trend is something like this: _process3452 _process2345 _process1234

As you can see, _process is same. There's a random number that is added each time it is launched. I know how to check for a process if I know exact process name. But, I don't know how to use wildcard.

Can someone help me with this.

Upvotes: 2

Views: 1860

Answers (1)

Dave
Dave

Reputation: 4356

If you are using a WMI query, you can use the like keyword and % to act as a wildcard:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process where Name like '_process%'")

For Each objProcess in colProcess
strList = strList & vbCr & objProcess.Name
Next

Upvotes: 5

Related Questions