Re: Quotes using WMI SQL Statement
- From: "scott" <sbailey@xxxxxxxxxxxxxxx>
- Date: Thu, 7 Feb 2008 14:06:06 -0600
thanks, that did it.
"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx> wrote in
message news:eB%23qzZYaIHA.5128@xxxxxxxxxxxxxxxxxxxxxxx
I would try:
Set colNetAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID ='" & _
sNetConnect & "'")
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Ruddy" <rodolfo.aguinaga@xxxxxxxxxxx> wrote in message
news:54EAAF45-D52F-489A-B51E-CE32FB923DDE@xxxxxxxxxxxxxxxx
Scott, seems to me you have a problem with quotes in the statement as the
last parenthesis shouldn't be part of the string and that's how you
coded.
I suggest you try before that a wscript.echo of the string, so you can
verify where exactly is the extra string.
Regards,
Ruddy
"scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message
news:#YA90YTaIHA.4160@xxxxxxxxxxxxxxxxxxxxxxx
I'm trying to pass a varible called "sNetConnect " to a sql statement
that gets WMI info from a Network Adapter class. In CODE 1 below, you
can see my hard-coded version that works. CODE 2 below is my problem.
I'm having problems inserting the correct single and double quotes
around the "sNetConnect" variable. Can someone please help me figure out
how the WMI SQL clause wants string variables passed to the
NetConnectionID property in CODE 2?
'CODE 1: Hard-Coded Works ***************************
sNetConnect = "Local Area Connection"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID = " & _
"'Local Area Connection'")
For Each colNetAdapter in colNetAdapters
iNetAdapterDeviceID = colNetAdapter.DeviceID
Next
Set colNicConfigs = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where Index= " & iNetAdapterDeviceID)
For Each objNicConfig in colNicConfigs
WScript.Echo "Win32_NetworkAdapter DeviceID: " & iNetAdapterDeviceID &
vbCrLf & _
"Win32_NetworkAdapterConfiguration Index: " & objNicConfig.Index &
vbCrLf & _
"Win32_NetworkAdapterConfiguration Description: " &
objNicConfig.Description
Next
'CODE 2: Uses Varible and Does Not Work ***************************
sNetConnect = "Local Area Connection"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID ='" & _
sNetConnect & "')" & """
' LINE ABOVE CAUSES END OF STATEMENT ERROR
For Each colNetAdapter in colNetAdapters
iNetAdapterDeviceID = colNetAdapter.DeviceID
Next
Set colNicConfigs = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where Index= " & iNetAdapterDeviceID)
For Each objNicConfig in colNicConfigs
WScript.Echo "Win32_NetworkAdapter DeviceID: " & iNetAdapterDeviceID &
vbCrLf & _
"Win32_NetworkAdapterConfiguration Index: " & objNicConfig.Index &
vbCrLf & _
"Win32_NetworkAdapterConfiguration Description: " &
objNicConfig.Description
Next
.
- References:
- Quotes using WMI SQL Statement
- From: scott
- Re: Quotes using WMI SQL Statement
- From: Ruddy
- Re: Quotes using WMI SQL Statement
- From: Richard Mueller [MVP]
- Quotes using WMI SQL Statement
- Prev by Date: Re: rename files in directory
- Next by Date: Re: rename files in directory
- Previous by thread: Re: Quotes using WMI SQL Statement
- Next by thread: Scripting Automator
- Index(es):
Relevant Pages
|