User Tools

Site Tools


vbscript

VBScript

Changing computer name for WNT/W2k/WXP

sNewName = "put new name here" 

Set oShell = CreateObject ("WSCript.shell" ) 

sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" 
sCompNameRegPath = sCCS & "Control\ComputerName\" 

With oShell 
.RegDelete sTcpipParamsRegPath & "Hostname" 
.RegDelete sTcpipParamsRegPath & "NV Hostname" 

.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName 
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName 
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName 
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName 
End With ' oShell 

MsgBox "Computer name changed, please reboot your computer"

Changing ip/mask/gate

Недостатки:

  • Не настраивает dns клиент
  • Одинаково настраивает все адаптеры в системе
Option Explicit
Dim objWMIService
Dim objNetAdapter
Dim strComputer
Dim arrIPAddress
Dim arrSubnetMask
Dim arrGateway
Dim colNetAdapters
Dim errEnableStatic
Dim errGateways

strComputer = "."
arrIPAddress = Array("10.240.2.40")
arrSubnetMask = Array("255.255.255.0")
arrGateway = Array("10.240.2.200")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
     errEnableStatic = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
     errGateways = objNetAdapter.SetGateways(arrGateway)
Next
vbscript.txt · Last modified: 2013/05/22 13:50 (external edit)