1
So I have a script from my old XP installation that sets the IP address based on what the username is. Here is the script:
'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
This script works 100% on an XP machine. However whenever I move it to Windows 7 it doesn't do anything at all. I've placed it in the iplogon folder for group policy as well as the startup folder. Was there a big syntax change between XP and 7?
If you run it manually on a Windows 7 machine does it work? How about if you Run it "as Administrator"? Have you stepped through it with a VBA debugger to see how it runs? – Ƭᴇcʜιᴇ007 – 2013-12-27T15:39:49.397
Sorry, I guess I didn't include as much information as I should have.
I've run it manually and nothing happens. I'm running it on an administrator level account so it should automatically run as administrator, but I went to go and set "run as administrator" and the option isn't there on the right-click menu or under properties. – Austin – 2013-12-27T15:45:38.097
What if you run a command prompt as admin and then run the script from inside that? – Collin Grady – 2013-12-27T20:08:06.990