PDA

查看完整版本 : 关于自动修改机器号,IP,CS-KYE,网络号的VBS脚本


Tony
2005-06-22, 03:33 AM
'根据机器的网卡号,自动修改计算机名,IP地址,子网掩码,IPX网络号,美萍机号,CS CD-KEY.

'----------------------------------------------------------------
'以下文件可以根据情况修改:
const settime=10 '程序启动后等待多少秒再运行,推荐设置10
const setmpnum="不需要" '需不需要修改美萍机号选择(需要,不需要)
const setmacAa="大写" 'MAC文件字母大小写类型选择(大写,小写)
const setname="win" '计算机名前缀
const setip="192.168.0.1" 'IP前缀,如填入"192.168.0.2"则33号机的IP就为"192.168.0.233"
const setyan="255.255.255.0" '子网掩码
'-----------------------------------------------------------------
'以下文件最好不要更改:

'<Main> 主程序开始
dim mac,jihao
'进行延时操作
ptime(settime)
'读取本机网卡MAC号
mac=strGetNodeID()
'读取MAC文件列表,找出本机对应的机器号
jihao=mactonum()
'调用WMI修改IP,子网掩码,计算机名,IPX网络号
wmitoip(jihao)
'将信息写入注册表
voidWriteIPToReg(jihao)
'重启计算机
voidReStar()
'<Main End>主程序结束

'进行延时操作
sub ptime(p)
dim nows,nowm,nowh,strats
p=int(p)
nows=Second(now)
nowm=Minute(now)
nowh=hour(now)
strats=TimeSerial(nowh,nowm,nows+p)
do until time=strats
loop
end sub

'读取本机网卡MAC号
Function strGetNodeID()
Dim fso,theFile,ln
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run"cmd /c ipconfig.exe /all > c:\NodeID.txt", 0, TRUE
Set WshShell=Nothing
Set fso=CreateObject("Scripting.FileSystemObject")
Set theFile=fso.OpenTextFile("c:\NodeID.txt")
Do While theFile.AtEndOfStream <> True
ln=theFile.ReadLine
If InStr(ln,"Physical Address")<>0 Then
Exit Do
End If
Loop
Thefile.Close
fso.DeleteFile("c:\NodeID.txt")
Set fso=Nothing
ln=Right(ln,18)
ln=left(ln,17)
strGetNodeID=ln
if setmacAa="小写" then strGetNodeID=lcase(ln)
End Function

'读取MAC文件列表,找出本机对应的机器号
function mactonum()
dim files,file,nr,num
set files=CreateObject("Scripting.FileSystemObject")
if files.fileexists("c:\autoset\mac.txt") then
set file=files.opentextfile("c:\autoset\mac.txt")
else
msgbox("请在程序目录下放置MAC列表文件(文件名为:mac.txt)")
end if
num=0
Do While file.AtEndOfStream <> True
nr=file.ReadLine
num=num+1
If InStr(nr,mac)<>0 Then
Exit Do
End If
Loop
if num>0 and num<10 then
mactonum="0" & num
elseif num>=10 and num<100 then
mactonum=num
else
msgbox("输入超出范围!")
end if
end function

'生成CDKEY
function getcskey(j)
dim fso,ts,count
Set fso=CreateObject("Scripting.FileSystemObject")
if fso.fileexists("c:\autoset\cdkey.txt") then
Set ts=fso.OpenTextFile("c:\autoset\cdkey.txt",1)
for count=1 to jihao
ts.skipline
next
getcskey=trim(ts.ReadLine)
else
msgbox("请在程序目录下放置CS CD-KEY列表文件(文件名为:cdkey.txt)")
end if
end function

'调用WMI修改IP,子网掩码,计算机名,IPX网络号
sub wmitoip(ab)
strComputer="."
Set objWMIService=GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters=objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress=Array(setip & ab)
strSubnetMask=Array(setyan)
For Each objNetAdapter in colNetAdapters
errEnable=objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
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(setname & ab)
Next
Set objWMIService=GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers=objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
Set objNetworkSettings=objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPXVirtualNetworkNumber(ab)
end sub

'将信息写入注册表
sub voidWriteIPToReg(ab)
Dim WshShell
'生成CDKEY
cskey=getcskey(jihao)
Set WshShell=WScript.CreateObject("WScript.Shell")
'美萍机号
if setmpnum="需要" then WshShell.RegWrite"HKLM\Software\Mpsoft\Smenu\computernum",ab,"REG_SZ"
'CD-KEY
WshShell.RegWrite"HKCU\Software\Valve\CounterStrike\Settings\key",cskey,"REG_SZ"
'清除启动项
WshShell.RegDelete"HKLM\Software\Microsoft\Windows\CurrentVersion\Run\autoset"
Set Wshell=Nothing
End sub

'重启计算机
sub voidReStar()
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run"RUNDLL.EXE USER.EXE,EXITWINDOWSEXEC",0,False
Set Wshell=Nothing
End sub