I am trying to create a script that will kill a process based on the process
name which is passed to the script as a cli argument. The following code
snippet works fine if the process name is hardcoded in the script, but I
can't assign the process name to a variable and use that in the ExecQuery
command.

Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'AIM.EXE'")

I would rather use WHERE Name= variable

Re: using variable in Where clause by Don

Don
Tue Jan 04 17:35:13 CST 2005


"rshackleford" <rshackleford@discussions.microsoft.com> wrote in message
news:B7BD9F77-BD4C-4DC6-9DC1-6225D25E7EB4@microsoft.com...
>I am trying to create a script that will kill a process based on the
>process
> name which is passed to the script as a cli argument. The following code
> snippet works fine if the process name is hardcoded in the script, but I
> can't assign the process name to a variable and use that in the ExecQuery
> command.
>
> Set colProcessList = objWMIService.ExecQuery _
> ("SELECT * FROM Win32_Process WHERE Name = 'AIM.EXE'")
>
> I would rather use WHERE Name= variable
>
>

Try this

Dim sMyVar
sMyVar = "AIM.EXE"
Set colProcessList = objWMIService.ExecQuery ("SELECT * FROM Win32_Process
WHERE Name = '" & sMyVar & "'")



Re: using variable in Where clause by rshackleford

rshackleford
Tue Jan 04 21:33:02 CST 2005



"Don Grover" wrote:

>
> "rshackleford" <rshackleford@discussions.microsoft.com> wrote in message
> news:B7BD9F77-BD4C-4DC6-9DC1-6225D25E7EB4@microsoft.com...
> >I am trying to create a script that will kill a process based on the
> >process
> > name which is passed to the script as a cli argument. The following code
> > snippet works fine if the process name is hardcoded in the script, but I
> > can't assign the process name to a variable and use that in the ExecQuery
> > command.
> >
> > Set colProcessList = objWMIService.ExecQuery _
> > ("SELECT * FROM Win32_Process WHERE Name = 'AIM.EXE'")
> >
> > I would rather use WHERE Name= variable
> >
> >
>
> Try this
>
> Dim sMyVar
> sMyVar = "AIM.EXE"
> Set colProcessList = objWMIService.ExecQuery ("SELECT * FROM Win32_Process
> WHERE Name = '" & sMyVar & "'")
>
>
>

that did it

thx!!