在Windows 7上使用vbs更改IP地址

时间:2012-07-11 20:33:32

标签: windows shell windows-7 vbscript

我已尝试使用此脚本更改Windows XP上的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一起使用

由于 克里斯

1 个答案:

答案 0 :(得分: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