if machname "quit" then ' 如果返回值不等于"quit",則 wmitoip(machname) ' 運行函數wmitoip()設置機器信息 mreboot()'重啟機器 end if end if
'///重啟機器 sub mreboot() dim fso,f1,f2 Set fso = CreateObject("Scripting.FileSystemObject")
'刪除啟動組 if fso.fileexists("C:/Documents and Settings/Administrator/「開始」菜單/程序/啟動/fxp.lnk") then set f1=fso.getfile("C:/Documents and Settings/Administrator/「開始」菜單/程序/啟動/fxp.lnk") f1.delete end if
'刪除vbs文件 if fso.fileexists("e:/fxp.vbs") then set f2=fso.getfile("e:/fxp.vbs") f2.delete 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
'///修改機器ip、掩碼、網關、工作組、機器名 sub wmitoip(t) strComputer="." strmask="255.255.255.0" Dim 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 objWMIService=GetObject("winmgmts://" & strComputer & "/root/cimv2") Set colNetAdapters=objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress=Array(ipv) strSubnetMask=Array(strmask) strGateway = Array(gateway) '修改網關 'strGatewayMetric = Array(1) '躍點數 strDNS=Array("61.134.1.4")
For Each objNetAdapter in colNetAdapters errEnable=objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)'ip,掩碼 errGateways = objNetAdapter.SetGateways(strGateway) '網關 errDns=objNetAdapter.SetDNSServerSearchOrder(strDNS)'dns Next
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2") Set colComputers = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colComputers err = ObjComputer.Rename("No_" & t)'機器名 ReturnValue = objComputer.JoinDomainOrWorkGroup("S0" & left(t,1))'工作組 Next
復制代碼 代碼如下: '/////主程序 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,先刪了