大佬教程收集整理的这篇文章主要介绍了vbscript – 在Windows 10上运行的系统上设置本地计算机名称和静态IP地址,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Windows 7上成功使用了以下脚本,但它在Windows 10上不起作用
要重命名Windows 7计算机:
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputers = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") Dim objComputer 'as Win32_ComputerSystem For Each objComputer In colComputers err = objComputer.Rename("NewName") Next
要设置Windows 7静态IP:
Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array("192.168.1.xxx") strsubnetMask = Array("255.255.255.x") strGateway = Array("192.168.1.xxx") strGatewayMetric = Array(1)
我找不到适用于Windows 10的脚本版本.
首先以格式化方式创建文本文件,删除引号之间存在的内容并添加配置但不要更改其他任何内容然后保存此文件,例如“IP.txt”:
newComputerName="ALHAMDULILLAH" Name="wi-fi" Address="192.168.1.7" Mask="255.255.255.0" Gateway="192.168.1.1" DNS1="2.2.2.2" DNS2="8.8.8.8"
然后使用此脚本更改计算机的名称
' run script as administrator If WScript.Arguments.Length=0 Then CreateObject("Shell.Application").ShellExecute "Wscript.exe",Chr(34)&WScript.ScriptFullName&Chr(34)&" HOLLOPOST",Null,"runas",1 WScript.Quit End If ' Get the new computer name from Text File myTextFilePath="C:\USERS\ENG\DESKTOP\IP.TXT" 'add here the full path of text fill T = CreateObject("Scripting.FileSystemObject").OpenTextFile(myTextFilePath).ReadAll a=Split(T,vbcrlf) For i=0 To UBound(a) If InStr(1,a(i),"newComputerName",1)>0 Then newComputerName=right(a(i),len(a(i))-16) End If Next ' change Computer Name for registry Dim sh : Set sh = CreateObject("Wscript.Shell") Dim strRegPath : strRegPath="HKLM\system\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname" sh.RegWrite strRegPath,newComputerName WScript.Sleep 1000 strRegPath="HKLM\system\CurrentControlSet\control\ComputerName\ComputerName\ComputerName" sh.RegWrite strRegPath,newComputerName WScript.Sleep 1000 ' restart the Computer For Each ComputerObject In GetObject("Winmgmts:{(Shutdown)}").InstancesOf("Win32_OperatingSystem"): ComputerObject.Win32Shutdown(6) : Next
然后在重新启动计算机后使用第二个脚本更改IP配置和DNS:
' run script as administrator If WScript.Arguments.Length=0 Then CreateObject("Shell.Application").ShellExecute "Wscript.exe",1 WScript.Quit End If 'Get Ip configuration from Text file myTextFilePath="C:\USERS\ENG\DESKTOP\IP.TXT" T = CreateObject("Scripting.FileSystemObject").OpenTextFile(myTextFilePath).ReadAll a=Split(T,vbcrlf) For i=0 To UBound(a) If InStr(1,"Name",1)>0 Then myInterfaceName=a(i) ElseIf InStr(1,"Address",1)>0 Then myIP=a(i) ElseIf InStr(1,"Mask",1)>0 Then myMask=a(i) ElseIf InStr(1,"Gateway",1)>0 Then myGateway=a(i) ElseIf InStr(1,"DNS1",1)>0 Then myPreferredDNS=right(a(i),len(a(i))-5) ElseIf InStr(1,"DNS2",1)>0 Then myAlternatedDNS=right(a(i),len(a(i))-5) End If Next ' change Computer IP and DNS Set sh=CreateObject("WScript.Shell") sh.Run "cmd.exe /c netsh interface ipv4 set address """&myInterfaceName&""" static "&myIP&" "&myMask&" "&myGateway &" 1",False sh.Run "cmd.exe /c netsh interface ipv4 Set dnsservers """&myInterfaceName&""" static "&myPreferredDNS&" primary",False sh.Run "cmd.exe /c netsh interface ipv4 Add dnsservers """&myInterfaceName&""" "&myAlternatedDNS&" Index=2",False sh.Run "cmd.exe /k netsh interface ipv4 show config",1,False
以上是大佬教程为你收集整理的vbscript – 在Windows 10上运行的系统上设置本地计算机名称和静态IP地址全部内容,希望文章能够帮你解决vbscript – 在Windows 10上运行的系统上设置本地计算机名称和静态IP地址所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。