【问题标题】:Change ip address using vbs on windows 7在 Windows 7 上使用 vbs 更改 IP 地址
【发布时间】:2012-07-11 20:33:32
【问题描述】:

我曾尝试使用此脚本更改 windows xp 上的 ipaddress,效果很好。

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 上工作

谢谢 克里斯

【问题讨论】:

    标签: windows shell windows-7 vbscript


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-09
      • 2019-09-19
      • 2023-03-06
      • 1970-01-01
      • 2011-06-09
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多