|
yhshiro
初级用户
积分 130
发帖 59
注册 2007-12-25
状态 离线
|
『楼 主』:
请教一个改IP+计算机名的VBS
Quote: | Oshell = CreateObject("WScript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
set wshshell = wscript.CreateObject("wscript.shell")
On Error Resume Next
Dim IP,NetMask,Gateway,DNS1,DNS2,DNS3,DNS4,Name
cmpnmnum=3
Gateway="192.168.10.254"
DNS1="192.168.10.21"
DNS2="192.168.11.21"
DNS3="202.160.241.21"
DNS4="98.160.10.101"
inp=Inputbox ("请输入机号")
if (len(inp)<>(cmpnmnum)) then
msgbox("输入错误")
oShell.run "C:\s.vbs",0, false
wscript.quit
end if
area="LN"
area=UCase(area)
num=right(inp,cmpnmnum)
IF (num < 201) THEN
IP="192.168.10."+cstr(cint(num))
if (num < 101) THEN
NetMask="255.255.254.0"
else
NetMask="255.255.254.0"
end if
ELSE
IP="192.168.11."+cstr(cint(num)-200)
NetMask="255.255.248.0"
END IF
Name=area+cstr(num)
ipxz=1
for i = 1 to cmpnmnum
ipxz=ipxz*10
Next
IPX=asc(area)*ipxz+num
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IP)
strSubnetMask = Array(NetMask)
strGateway = Array(Gateway)
strDNS = Array(DNS1,DNS2,DNS3,DNS4)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
ObjComputer.Rename(Name)
Next
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPXVirtualNetworkNumber(IPX) |
|
我想把上面输入的机号加上LN写这下面这段注册表里面
Quote: | ws.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ActiveComputerName\ComputerName",Name,"REG_SZ"
ws.RegWrite "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname",Name,"REG_SZ"
ws.RegWrite "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Hostname",Name,"REG_SZ" |
|
[ Last edited by yhshiro on 2008-4-13 at 02:25 PM ]
|
|
2008-4-13 10:31 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
2 楼』:
Set Oshell = CreateObject("WScript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Set wshshell = wscript.CreateObject("WScript.Shell")
on Error Resume Next
Dim IP,NetMask,Gateway,DNS1,DNS2,DNS3,DNS4,Name
cmpnmnum = 3
Gateway = "192.168.10.254"
DNS1 = "192.168.10.21"
DNS2 = "192.168.11.21"
DNS3 = "202.160.241.21"
DNS4 = "98.160.10.101"
inp = InputBox ("请输入机号")
If (Len(inp) <> (cmpnmnum)) Then
MsgBox "输入错误"
oShell.run "C:\s.vbs",0, False
wscript.quit
End If
area = "LN"
area = UCase(area)
num = Right(inp,cmpnmnum)
If (num < 201) Then
IP = "192.168.10." + CStr(CInt(num))
If (num < 101) Then
NetMask = "255.255.254.0"
Else
NetMask = "255.255.254.0"
End If
Else
IP = "192.168.11." + CStr(CInt(num) - 200)
NetMask = "255.255.248.0"
End If
Name = area + CStr(num)
ipxz = 1
For i = 1 To cmpnmnum
ipxz = ipxz * 10
Next
IPX = Asc(area) * ipxz + num
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IP)
strSubnetMask = Array(NetMask)
strGateway = Array(Gateway)
strDNS = Array(DNS1,DNS2,DNS3,DNS4)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colComputers
ObjComputer.Rename(Name)
Next
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPXVirtualNetworkNumber(IPX)
Dim Name
Name = "BM250"
Oshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ActiveComputerName\ComputerName",Name,"REG_SZ"
Oshell.RegWrite "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname",Name,"REG_SZ"
Oshell.RegWrite "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Hostname",Name,"REG_SZ"
|
|
2008-4-13 10:47 |
|
|
bat-zw
金牌会员
永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
|
2008-4-13 11:38 |
|
|
yhshiro
初级用户
积分 130
发帖 59
注册 2007-12-25
状态 离线
|
『第
4 楼』:
对不起说错了
我要的是这样的:
在运行后弹出来的对话框里输入几号~
然后在那几号前面加上再把那个字母和几号写入
Oshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ActiveComputerName\ComputerName",Name,"REG_SZ"
这里面
|
|
2008-4-13 13:07 |
|
|
abcd
银牌会员
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
|
2008-4-13 13:50 |
|
|
yhshiro
初级用户
积分 130
发帖 59
注册 2007-12-25
状态 离线
|
|
2008-4-13 15:11 |
|
|
yhshiro
初级用户
积分 130
发帖 59
注册 2007-12-25
状态 离线
|
|
2008-4-13 15:12 |
|
|
abcd
银牌会员
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
『第
8 楼』:
不是整个IP 吧?
num = Right(inp,cmpnmnum)是IP地址截取最后三位,是吧??
2楼的基本可以实现了啊。
顶多的问题是:IP地址后三位不全是数字。例如:192.168.0.1等。
|
|
2008-4-13 15:35 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
9 楼』:
Dim Name
Name = "BM" & InputBox("请输入机号:","机号")
|
|
2008-4-13 16:19 |
|
|