2012-07-11 48 views
0

我已经尝试使用此脚本来更改Windows XP上的ipaddress并且它工作得很好。在Windows 7上使用vbs更改ip地址

Dim strIPAddress 
Dim strSubnetMask 
Dim strGateway 
Dim intGatewayMetric 
Dim strDns1 
Dim strDns2 

strIPAddress = "10.10.10.50" 
strSubnetMask = "255.255.255.0" 
strGateway = "10.10.10.1" 
intGatewayMetric = 1 
strDns1 = "10.10.10.9" 
strDns2 = "10.10.10.10" 

Set objShell = WScript.CreateObject("Wscript.Shell") 
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True 
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True 
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True 
Set objShell = Nothing 
WScript.Quit 

我有什么改变,以得到它的工作与Windows 7,请

感谢 克里斯

回答

0
Set WshShell = WScript.CreateObject("WScript.Shell") 
If WScript.Arguments.length = 0 Then 
Set ObjShell = CreateObject("Shell.Application") 
ObjShell.ShellExecute "wscript.exe", """" & _ 
WScript.ScriptFullName & """" &_ 
" RunAsAdministrator", , "runas", 1 
Else 
end if 

Dim strIPAddress 
Dim strSubnetMask 
Dim strGateway 
Dim intGatewayMetric 
Dim strDns1 
Dim strDns2 

strIPAddress = "10.0.0.25" 
strSubnetMask = "255.255.255.0" 
strGateway = "10.0.0.1" 
intGatewayMetric = 1 
strDns1 = "8.8.8.8" 
strDns2 = "10.0.0.1" 

Set objShell = WScript.CreateObject("Wscript.Shell") 
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True 
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True 
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True 
Set objShell = Nothing 
WScript.Quit