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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determin and echo locational DHCP Server

Status
Not open for further replies.

chouck

MIS
Jan 30, 2005
32
US
I'm trying to determine and echo the locational DHCP server for users who travel throughout my company. This is what I have come up with so far, but it doesn't work properly. Since the DHCPServer property of Win32_NetworkAdapter Configuration is a string, I figured this would be easy, but has turned out far more difficult than I thought. Thanks in advance!

Code:


strpc = "."
Set behrwmiservice = GetObject("winmgmts:\\"& strpc & "\root\cimv2")
Set locationdhcpserv = behrwmiservice.ExecQuery _
("Select DHCPServer from Win32_NetworkAdapterConfiguration")

wscript.echo locationdhcpserv.DHCPServer

 
chouck,

The query returns a collection, you've to echo for each item within it.
[tt]
'or this to narrow down useful returns,
'but there is nothing wrong with your original line
Set locationdhcpserv = behrwmiservice.ExecQuery _
("Select DHCPServer from Win32_NetworkAdapterConfiguration [blue]where ipenabled=true[/blue]")
[green]for each obj in locationdhcpserv
wscript.echo obj.DHCPServer
next[/green]
[/tt]
regards - tsuji
 
Thanks for the reply, I knew I was hitting all around it, but was missing that last little part.

This works and the ("where ipenabled=true") works for narrowing it down. Thanks
 
ok, here is my second dilema: when a user that is traveling between company locations connects to a dhcp server that is not from his own location, i want his Z:\ to map to a local file server to the location that he is at. this is what i have so far, but becuase dhcp server property is a collection, i get more than one dhcp server address. Again, any help is greatly appreciated :) here is the code:


option explicit
dim objpc, objshell, objnet, objwmiservice
dim ipitems, dhcpitem


on error resume next
objpc = "."
const apps = "apps"
set objshell = createobject("wscript.shell")
set objnet = createobject("wscript.network")
Set objwmiservice = GetObject _
("winmgmts:\\" & objpc & "\root\cimv2")
Set ipitems = objwmiservice.ExecQuery _
("Select DHCPServer From Win32_NetworkAdapterConfiguration " & _
"Where IPEnabled = True")

For Each dhcpItem in ipitems
Wscript.Echo dhcpitem.dhcpserver

if dhcpitem.dhcpserver = "1.2.3.4" then
wscript.echo "user is physically at site a"
objnet.removenetworkdrive "z:"
wscript.echo "drive deleted"
objnet.mapnetworkdrive "z:", "\\site_a\applications"
wscript.echo "z:\ is now mapped to the site a appsfolder"

elseif dhcpitem.dhcpserver = "2.3.4.1" then
wscript.echo "user is physically at site b"
objnet.removenetworkdrive "z:"
wscript.echo "drive deleted"
objnet.mapnetworkdrive "z:", "\\site_b\applications"
wscript.echo "z:\ is now mapped to the site b appsfolder"

elseif dhcpitem.dhcpserver = "3.4.1.2" then
wscript.echo "user is physically at site c"
objnet.removenetworkdrive "z:"
wscript.echo "drive deleted"
objnet.mapnetworkdrive "z:", "\\site_c\applications"
wscript.echo "z:\ is now mapped to the site c appsfolder"

elseif dhcpitem.dhcpserver = "4.1.2.3" then
wscript.echo "user is physically at site d"
objnet.removenetworkdrive "z:"
wscript.echo "drive deleted"
objnet.mapnetworkdrive "z:", "\\site_d\applications"
wscript.echo "z:\ is now mapped to the site d appsfolder"

elseif dhcpitem.dhcpserver = "1.2.3.5" then
wscript.echo "user is physically at site e"
objnet.removenetworkdrive "z:"
wscript.echo "drive deleted"
objnet.mapnetworkdrive "z:", "\\site_e\applications"
wscript.echo "z:\ is now mapped to site e apps folder"

end if
Next
 
chouck,
What are the os, servers and workstations?
- tsuji
 
tsuji,

The clients are all windows 2000. the dhcp servers are a mixture of winnt 4.0 and win2k.
 
chouck,

For that config, maybe you can try this to determine the dhcpserver.
[tt]
dim ndt : ndt=0
dim dhcpsrv : dhcpsvr=""
dim odic
set odic=createobject("scripting.dictionary")

Set ipitems = objwmiservice.ExecQuery _
("Select DHCPLeaseObtained,DHCPServer From Win32_NetworkAdapterConfiguration " & _
"Where IPEnabled = True and DHCPEnabled = True")
For Each dhcpItem in ipitems
odic.add dhcpItem.DHCPLeaseObtained,dhcpItem.DHCPServer
Next

for i=0 to odic.count-1
if cdbl(odic.keys(i))>ndt then
dhcpsrv=odic.items(i)
ndt=odic.keys(i)
end if
next

'Start mapping hereafter based on the ipaddress of dhcpsrv obtained
[/tt]
- tsuji

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top