所以我从旧的 XP 安装中获取了一个脚本,该脚本可以根据用户名设置 IP 地址。以下是脚本:
'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
此脚本在 XP 机器上 100% 有效。但是,每当我将其移至 Windows 7 时,它都不起作用。我已将其放在组策略的 iplogon 文件夹以及启动文件夹中。XP 和 7 之间的语法是否有很大的变化?
答案1
语法很可能已经发生了重大变化。您必须记住,Windows 7 在速度方面带来了许多变化。查看您的错误日志以查看脚本运行情况,如果它似乎没有注意到某些事情或运行了不同的命令,那么这就是问题所在。此外,我记得很多与实际网络连接命令有关的“更新”,但这可能只是我的设备的问题。