中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-08 01:42
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 请教一个改IP+计算机名的VBS 查看 806 回复 8
楼 主 请教一个改IP+计算机名的VBS 发表于 2008-04-13 10:31 ·  中国 云南 昆明 电信
初级用户
★★
积分 130
发帖 59
注册 2007-12-25 20:32
18年会员
UID 106775
性别 男
状态 离线

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写这下面这段注册表里面


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 ]
2 发表于 2008-04-13 10:47 ·  中国 陕西 西安 电信
铂金会员
★★★★
积分 5,212
发帖 2,478
注册 2007-02-08 23:39
19年会员
UID 79003
性别 男
状态 离线
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"
3 发表于 2008-04-13 11:38 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105
发帖 1,276
注册 2008-03-08 13:00
18年会员
UID 112398
性别 男
状态 离线
做为VBS门外汉,我不发表任何评论,唯有一个字顶了!!!
批处理之家新域名:www.bathome.net
4 发表于 2008-04-13 13:07 ·  中国 云南 昆明 电信
初级用户
★★
积分 130
发帖 59
注册 2007-12-25 20:32
18年会员
UID 106775
性别 男
状态 离线
对不起说错了

我要的是这样的:
在运行后弹出来的对话框里输入几号~
然后在那几号前面加上再把那个字母和几号写入
Oshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ActiveComputerName\ComputerName",Name,"REG_SZ"

这里面
5 发表于 2008-04-13 13:50 ·  中国 北京 华为云
银牌会员
★★★
积分 1,436
发帖 739
注册 2007-10-11 17:44
18年会员
UID 99469
性别 男
状态 离线
是几号,还是机号?
6 发表于 2008-04-13 15:11 ·  中国 云南 昆明 电信
初级用户
★★
积分 130
发帖 59
注册 2007-12-25 20:32
18年会员
UID 106775
性别 男
状态 离线
是机号
7 发表于 2008-04-13 15:12 ·  中国 云南 昆明 电信
初级用户
★★
积分 130
发帖 59
注册 2007-12-25 20:32
18年会员
UID 106775
性别 男
状态 离线
还要在机号前面加上LN
8 发表于 2008-04-13 15:35 ·  中国 北京 华为云
银牌会员
★★★
积分 1,436
发帖 739
注册 2007-10-11 17:44
18年会员
UID 99469
性别 男
状态 离线
不是整个IP 吧?

num = Right(inp,cmpnmnum)是IP地址截取最后三位,是吧??

2楼的基本可以实现了啊。

顶多的问题是:IP地址后三位不全是数字。例如:192.168.0.1等。
9 发表于 2008-04-13 16:19 ·  中国 陕西 西安 电信
铂金会员
★★★★
积分 5,212
发帖 2,478
注册 2007-02-08 23:39
19年会员
UID 79003
性别 男
状态 离线
Dim Name
Name = "BM" & InputBox("请输入机号:","机号")
论坛跳转: