Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the DHCPEnabled WMI method

Status
Not open for further replies.

Sunny4Ever

IS-IT--Management
Nov 6, 2002
77
GB
Hi All

I am trying to use EnableDHCP method in WMI - I got this code sample from Microsoft:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Next
Wscript.Echo "Finished"

Which works perfectly, the problem I have is when I try and run this against a remote machine and replace the "."

The script does actually work and change a PC to DHCP enabled but it seems that this success is never returned to the script so any atempt to trap the return value will fail and the script just hangs .

Is this just a limitation of the EnableDHCP method or am I missing something???

Thanks,
Sunny
 
Hi,

I took a little search on msdn.microsoft.com and found some information about WMI security:


To connect to WMI and retrieve an object using a moniker

Call GetObject with a moniker in the input parameter.
set MyObject = GetObject("WinMgmts:{impersonationLevel=impersonate}!Win32_Service=""ALERTER""")
For more information about using the VBScript method GetObject in WMI scripts, see Creating an Instance and Retrieving an Instance.

In the previous snippet, "impersonate", or "impersonationLevel=3", is the default process security level. In Windows 2000 and later, it is not necessary to specify this level unless you need to change the process security to "delegate". For more information, see Setting the Default Process Security Level Using VBScript.


I hope this is of any help,

Greetz Hans
 
Hans

Thanks for your interest in this problem. I have found out why it hangs and it is quite obvious really:

-PC1 is on IP 100.100.100.100
-I run my remote EnableDHCP call against PC1 (which I am an administrator of)
-The IP for PC1 changes to one from DHCP pool thus reseting the Network connection between My PC and PC1.
-My Pc never gets the return code from the WMI call and my script will just wait (I have left it for 20mins and it still did not time out).

I can't see any way around this so I am looking at a workaround.

Thanks,
Sunny

 
I believe the problem here is once the IP address has changed you immediately lose connection with the pc and that's the reason why you don't get an alert that it has completed. On the local machine, you get the alert because it doesn't have to transmit across the network.

Jesse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top