单位机房的系统需要重新安装,一共近300台设备,使用ghost网络克隆后,客户机重新设置ip是个麻烦的事情。我们使用的教学管理软件要求客户机必须有固定ip,单位5个机房如下(DNS:61.134.1.4,掩码为:255.255.255.0):
'/////主程序
dim msginf,machname'定义变量:对话框,机器名
msginf=msgbox("生成
注册表文件,是否继续?",65,"getreg") '信息提示
if msginf=1 then ' 如果按确定,则
machname=inputon() ' 用函数inputon()分析
if machname<>"quit" then ' 如果返回值不等于"quit",则
setreg(machname) ' 运行函数setreg()生成
注册表ip.reg
end if
end if
'///生成计算机名
function inputon() ' 函数inputon()
dim t ' 变量
while true ' 循环直到退出函数
t=inputbox("按一下规则输入:" & chr(13) & chr(13) & "第1位代表机房号" & chr(13) & "第2、3位代表机器号" & chr(13) & "教师机用00代表" & chr(13) & "如:123代表1号机房23号机" & chr(13) & "请确保输入正确!!","请输入3位机器标识!","") ' 输入机算机名,默认值为空
if t="" then ' 如果t等于空(按了取消键),则
inputon="quit" ' 返回值为"quit"
exit function ' 退出程序
end if
if len(t)=3 then ' 计算机号的长度为3位
if Cint(t)>=100 and Cint(t)<580 then ' 验证
inputon=t ' 返回需要的计算机名
exit function
end if
end if
wend
end function
'///生成注册文件
sub setreg(t) ' 生成
注册表,t为机器号
Dim fso, f1,f2,lt,rt' 变量
dim ipv,gateway,lan 'ip,网关,工作组
lt=cint(left(t,1))'机号左1位数字值
rt=cint(right(t,2)) ' 机号右两位数字值
if lt=1 or lt=2 then'判断网关
gateway="192.168.1.254"
else
gateway="192.168.3.254"
end if
if lt=1 then '1号机房
lan="S01"
ipv="192.168.1."
if rt=0 then '教师机
ipv=ipv+"100"
else'学生机
ipv=ipv+Cstr(rt)
end if
end if
if lt=2 then '2号机房
lan="S02"
ipv="192.168.1."
if rt=0 then '教师机
ipv=ipv+"200"
else'学生机
rt=rt+100
ipv=ipv+Cstr(rt)
end if
end if
if lt=3 then '3号机房
lan="S03"
ipv="192.168.3."
if rt=0 then '教师机
ipv=ipv+"80"
else'学生机
ipv=ipv+Cstr(rt)
end if
end if
if lt=4 then '4号机房
lan="S04"
ipv="192.168.3."
if rt=0 then '教师机
ipv=ipv+"160"
else'学生机
rt=rt+80
ipv=ipv+Cstr(rt)
end if
end if
if lt=5 then '5号机房
lan="S05"
ipv="192.168.3."
if rt=0 then '教师机
ipv=ipv+"240"
else'学生机
rt=rt+160
ipv=ipv+Cstr(rt)
end if
end if
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.fileexists("e:\ip.reg") then
set f2=fso.getfile("e:\ip.reg")
f2.delete
end if '如果存在ip.reg,先删了
set f1 = fso.CreateTextFile("e:\ip.reg", True) ' 建立文件ip.cfg
'f1.WriteLine("REGEDIT4") ' 以下为生成
注册表 f1.WriteLine("Windows Registry Editor Version 5.00")
f1.WriteBlankLines(1)
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName]")
f1.WriteLine(chr(34) & "ComputerName" & chr(34) & "=" & chr(34) & t & chr(34)) ' 计算机名
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0000]")
f1.WriteLine(chr(34) & "IPAddress" & chr(34) & "=" & chr(34) & ipv & chr(34)) ' IP
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0000]")
f1.WriteLine(chr(34) & "DefaultGateway" & chr(34) & "=" & chr(34) & gateway & chr(34)) ' 网关
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0000]")
f1.WriteLine(chr(34) & "IPMask" & chr(34) & "=" & chr(34) & "255.255.255.0" & chr(34)) ' 子网掩码
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP]")
f1.WriteLine(chr(34) & "Comment" & chr(34) & "=" & chr(34) & t & chr(34)) ' 计算机说明
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP]")
f1.WriteLine(chr(34) & "ComputerName" & chr(34) & "=" & chr(34) & t & chr(34)) ' 计算机名
f1.WriteLine("[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP]")
f1.Writeline(chr(34) & "Workgroup" & chr(34) & "=" & chr(34) & lan & chr(34)) ' 工作组
end sub