triphen
asked on
VBS Script
Hey guys,
I am trying to write a VB script to return a value or "DHCP" or "Static" depending on how the NIC is configured.
Windows 7 and Server 2008 R2
I am trying to write a VB script to return a value or "DHCP" or "Static" depending on how the NIC is configured.
Windows 7 and Server 2008 R2
ASKER
It returns 1 True, then about 10 Falses.
How many NIC cards do you have? Do you have VMWare installed?
ASKER
1, Yes
Let me check another machine.....good call
Is it possible to Return "DHCP" and "Static" vs True and False?
Let me check another machine.....good call
Is it possible to Return "DHCP" and "Static" vs True and False?
ASKER
Same result on another machine with only 1 NIC and no VM installed. Several Pop ups. True, False, False, False, False, False, False, True, False, False, etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This looks promising :)
I modified to this, since I will always be executing on local PC.
This works great!
Now one small problem. I am trying to use this with BGInfo by SysInternals. When loading this script I get:
Line 8, position 5 Object Required 'Wscript'
I modified to this, since I will always be executing on local PC.
'Query WMI
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = true")
'Output to console
For Each objItem in colItems
'Wscript.Echo "DeviceName: " & objItem.DHCPEnabled
If objItem.DHCPEnabled Then
Wscript.Echo "DHCP"
Else
Wscript.Echo "Static"
End If
Next
This works great!
Now one small problem. I am trying to use this with BGInfo by SysInternals. When loading this script I get:
Line 8, position 5 Object Required 'Wscript'
If you run the script you can send arguments so for example if you named it IsDHCPEnabled.vbs and you're querying a server named Server1, you would type in at the command line:
IsDHCPEnabled.vbs Server1
You have to have permission on the remote computer, otherwise it won't run
IsDHCPEnabled.vbs Server1
You have to have permission on the remote computer, otherwise it won't run
Scrap my last comment. I misunderstood your last post. I'm not sure why SysInternal is producing an error. Perhaps you have to reference the Wscript object in the IDE?
In BGInfo, you can create a custom Field and select WMI. Browse Path then select the class Win32_NetworkAdapterConfig uration and class property of DHCPEnabled Under the WMI query modify the query to read
SELECT DHCPEnabled FROM Win32_NetworkAdapterConfig uration WHERE IPEnabled = true
Evaluate it to make sure the query evaluates as expected then click OK. Make sure you name the field and then select it from the field list.
This should accomplish what you want within BGInfo
SELECT DHCPEnabled FROM Win32_NetworkAdapterConfig
Evaluate it to make sure the query evaluates as expected then click OK. Make sure you name the field and then select it from the field list.
This should accomplish what you want within BGInfo
ASKER
This worked for me and BGInfo...
Set objWMIService = GetObject("winmgmts:\\.\ro ot\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfig uration WHERE IPEnabled = true")
'Output to console
For Each objItem in colItems
'Wscript.Echo "DeviceName: " & objItem.DHCPEnabled
If objItem.DHCPEnabled Then
On Error Resume Next
Wscript.Echo "DHCP"
Echo "DHCP"
on error goto 0
Else
On Error Resume Next
Wscript.Echo "Static"
Echo "Static"
on error goto 0
End If
Next
Set objWMIService = GetObject("winmgmts:\\.\ro
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfig
'Output to console
For Each objItem in colItems
'Wscript.Echo "DeviceName: " & objItem.DHCPEnabled
If objItem.DHCPEnabled Then
On Error Resume Next
Wscript.Echo "DHCP"
Echo "DHCP"
on error goto 0
Else
On Error Resume Next
Wscript.Echo "Static"
Echo "Static"
on error goto 0
End If
Next
ASKER
Thank you! Couldn't have done it without you :)
No problem! Glad you got it working!
Open in new window
This will return true or false depending on wheter or not DHCP is enabled