Mam więc skrypt ze starej instalacji XP, który ustawia adres IP na podstawie nazwy użytkownika. Oto skrypt:
'Get Username
set objNetwork = wscript.CreateObject("wscritp.network")
User=objNetwork.Username
'Set IP address based on username
Select Case User
Case "user1"
arrIPAddress = Array("192.168.1.9")
Case "user2"
arrIPAddress = Array("192.168.1.10")
Case "user3"
arrIPAddress = Array("192.168.1.11")
Case "user4"
arrIPAddress = Array("192.168.1.12")
Case "user5"
arrIPAddress = Array("192.168.1.13")
End Select
'non-changing values
arrSubnetMask = Array("255.255.255.0")
'arrGateway = Array("192.168.1.1")
'arrGatewayMetric = Array(1)
'Below obtained from MSDN site WMI Tasks: Networking, slightly modified
strComputer = "."
setobjWMIService = GetObject _
("winmgmts:\\ " & strComputer & "\root\cimv2")
set colNetAdapters = objWMIService.ExecQuery _
("select * from Win32_NetworkAdapterConfiguration where ipenabled = rue")
for each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
Next
set ipconfigset = objwmiservice.execquery _
("select IPAddress from Win32_NetworkAdapterConfiguration where ipenabled = true")
for each ipconfig in ipconfigset
if not isnull(ipconfig.ipaddress) then
for i=lbound(ipconfig.ipaddress) _
to unbound(ipconfig.ipaddress)
wscript.echo "Logged in as " & User & ", IP Address: " & ipconfig.ipaddress(i)
next
end if
next
Ten skrypt działa w 100% na komputerze XP. Jednak po przeniesieniu go do systemu Windows 7 nic nie robi. Umieściłem go w folderze iplogon dla zasad grupy, a także w folderze startowym. Czy nastąpiła duża zmiana składni między XP a 7?