标题: 请教一个改IP+计算机名的VBS
[打印本页]
作者: yhshiro
时间: 2008-4-13 10:31
标题: 请教一个改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 ]
作者: slore
时间: 2008-4-13 10:47
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"
作者: bat-zw
时间: 2008-4-13 11:38
做为VBS门外汉,我不发表任何评论,唯有一个字顶了!!!
作者: yhshiro
时间: 2008-4-13 13:07
对不起说错了
我要的是这样的:
在运行后弹出来的对话框里输入几号~
然后在那几号前面加上再把那个字母和几号写入
Oshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ActiveComputerName\ComputerName",Name,"REG_SZ"
这里面
作者: abcd
时间: 2008-4-13 13:50
是几号,还是机号?
作者: yhshiro
时间: 2008-4-13 15:11
是机号
作者: yhshiro
时间: 2008-4-13 15:12
还要在机号前面加上LN
作者: abcd
时间: 2008-4-13 15:35
不是整个IP 吧?
num = Right(inp,cmpnmnum)是IP地址截取最后三位,是吧??
2楼的基本可以实现了啊。
顶多的问题是:IP地址后三位不全是数字。例如:192.168.0.1等。
作者: slore
时间: 2008-4-13 16:19
Dim Name
Name
= "
BM"
& InputBox("
请输入机号:","
机号"
)