眉山东坡论坛

 找回密码
 注册账号

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4620|回复: 1
收起左侧

[精品软件] NCRE考试系统准备(客户端安装)程序

[复制链接]
发表于 2015-3-17 09:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转东坡论坛

您需要 登录 才可以下载或查看,没有帐号?注册账号

x
每次计算机等级考试时都需要在学生机上安装客户端软件挺麻烦的,写了个安装软件,经过几期修正用着还顺手,分享给大家:


  1. 'wscript.exe  d:\考试端程序NCRExx.vbs
  2. 'taskkill  /f /im  wscript.exe
  3. '每次都要更改的变量:
  4. '   net.MapNetworkDrive "K:", "[url=file://\\xxx.xxx.xxx.6\Ncrexx]\\xxx.xxx.xxx.6\Ncrexx","True",,username[/url] '驱动器,路径,用户名,true,密码,user
  5. '   if oldver<>"2014A" then '删除老信息以便安装新版
  6. '要求:
  7. '    服务器IP为192.168.xx.6
  8. '    需安装的软件、大漠组件放入共享的K盘
  9. '    如果未安装.net,请把dotNetFx40_Full_x86_x64.exe放入共享的K盘
  10. '   
  11. Dim WshShell,x,y,str,i,sn,Mark,Debug
  12. Set WshShell=WScript.CreateObject("WScript.Shell")
  13. username=WshShell.ExpandEnvironmentStrings("%USERNAME%")
  14. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  15. Set objWMIService = GetObject("winmgmts:\\.")
  16. Set WMI=GetObject("winmgmts:\\.\root\cimv2")
  17. Set ws=createobject("wscript.shell")
  18. set ie=wscript.createobject("internetexplorer.application","event_") '创建ie对象'
  19. ie.fullscreen=0 '不使用全屏
  20. ie.menubar=0 '取消菜单栏'
  21. ie.addressbar=0 '取消地址栏'
  22. ie.toolbar=0 '取消工具栏'
  23. ie.statusbar=0 '取消状态栏'
  24. ie.width=360 '宽'
  25. ie.height=600 '高'
  26. ie.resizable=0 '不允许用户改变窗口大小'
  27. ie.navigate "about:blank" '打开空白页面'
  28. 'ie.left=fix((ie.document.parentwindow.screen.availwidth-ie.width)/2) '水平居中'
  29. ie.left=fix(20) '水平居中'
  30. ie.top=10
  31. ie.visible=0
  32. ie.visible=1 '窗口可见'

  33. with ie.document '以下调用document.write方法
  34.     .write "<html><head><title>NCRE安装程序</title></head><body bgcolor=#dddddd><br><center><font face=黑体>"
  35.     .write "<font size=5><b>&nbsp;&nbsp;NCRE考试系统准备程序</b> </font></font><font size=2><a target=_BLANK href=http://bbs.dp168.com/thread-90732-1-1.html>"
  36.     .write "论坛</a></font></center><br>"
  37.     .write "<br>"
  38.     .write "如果是非考试时间,请直接关闭本窗口。<br>"
  39.     progname=""
  40.     On Error Resume Next
  41.         Set objFSO = CreateObject("Scripting.FileSystemObject")
  42.         progname=objFSO.GetFile(Wscript.scriptfullname).name
  43.     On error goto 0
  44.     if progname="" then
  45.         ie.quit
  46.         .write "注册scrrun.dll,未注册此文件出现 CreateObject-FileSystem出错<br>"
  47.         ws.Run "regsvr32"&" /S C:\Windows\system32\scrrun.dll"
  48.         wscript.sleep 5000 '以使regsvr32 /s scrrun.dll有时间完成
  49.             ws.Run "wscript.exe "& chr(34) & Wscript.scriptfullname & chr(34) '重新运行并退出
  50.             wscript.sleep 500
  51.             wscript.quit
  52.     end if
  53.     Set objHTML=CreateObject("htmlfile")
  54.     Set net = CreateObject("WScript.Network")
  55. '从文件名判断是第几次考试
  56.     progname=ucase(objFSO.GetFile(Wscript.scriptfullname).name)
  57.     tmp1=instr(progname,"NCRE")+4
  58.     if tmp1=0 then msgbox "根据本文件名看不出这是第几次考试,请更名为*NCREXX*后再运行。":ie.quit:wscript.quit
  59.     ver=mid(progname,tmp1,2)
  60.     .write "这是NCRE考试的第" & ver & "次"
  61.     if ver<38 or ver>99 then msgbox "根据本文件名看不出这是第几次考试,请更名为*NCREXX*后再运行。":ie.quit:wscript.quit
  62.    
  63.     .write "程序位置:" & progfolder & "<br>"
  64.     desktop=WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop") & ""
  65.     .write "桌面位置:" & desktop & "<br>"
  66.     while CPU_busy >5 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  67.     prog=WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
  68.     username=WshShell.ExpandEnvironmentStrings("%username%")
  69.     .write "程序文件夹:" & prog & "<br>"
  70.     .write "当前用户名:" & username & "<br>"
  71.     newname=""
  72.     on error resume next
  73.         newname=WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName")
  74.     on error goto 0
  75.    
  76.     if len(newname)<>3 or left(newname,1)<>"K" then
  77.         on error resume next
  78.             do while newname<1 or newname>99
  79.                 newname=inputbox("请输入本座位号(不用输入K和前面的0):","眉职院Ncre座位调整程序")
  80.             loop
  81.         on error goto 0
  82.         newname=trim(newname):if newname<10 then newname="0" & newname
  83.         newname="K" & newname
  84.         if (Rename(username,newname))=-1 then msgbox "更名出错,请检查程序是否正确及兼容性问题。":ie.quit:wscript.quit '更名
  85.         .write "'加入自动登陆" & newname & "<br>"
  86.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName",newname
  87.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon",1
  88.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword",""
  89.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\ForceAutoLogon",1
  90.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA",0
  91.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\PromptOnSecureDesktop",0
  92.         WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin",0
  93.         .write "'取出程序现在的文件夹名字<br>"
  94.         str=WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Startup")
  95.         if not progfolder=str then
  96.             prog=right(wscript.scriptfullname,len(wscript.scriptfullname)-len(progfolder)-1)
  97.             .write  "程序文件夹=" & progfolder & chr(13) & "注册表中取出为:" & str & chr(13) & "程序的名字是:" & prog
  98.             objFSO.copyfile wscript.scriptfullname,str & "","True" '这里的str是暂借用常量,实际是开始文件夹
  99.             objFSO.deletefile wscript.scriptfullname,true '自删除
  100.             ie.quit
  101.             wscript.sleep 20000
  102.             'ws.Run "wscript.exe " & chr(34) & str & "" & prog & chr(34) '重新运行并退出,str是暂借用常量
  103.             'wscript.sleep 200
  104.         end if
  105.     end if
  106. '重映射网络盘
  107.     Wait_Net_ok()
  108.     ip=Split(Get_IP(),"."):if ip(0)<>"192" then msg="未找到网络驱动器, IP地址取出不正确,"
  109.     str=ip(0) & "." & ip(1) & "." & ip(2) & ".6"
  110.     on error resume next
  111.             net.RemoveNetworkDrive "K:"
  112.             wscript.sleep 3000
  113.             net.MapNetworkDrive "K:", "\" & str & "\Ncre"&trim(ver),"True",,username '驱动器,路径,用户名,true,密码,user
  114.     on error goto 0
  115.     wscript.sleep 3000
  116.     str=ip(0) & "." & ip(1) & "." & ip(2) & ".6"
  117.     if not objFSO.FileExists ("K:\NUL") then msg="未找到网络驱动器, 但IP分配是正确的,"
  118.     if not objFSO.FileExists ("K:\NUL") then
  119.       msgbox msg & "Ping " & str & "值:" & Net_state(url)
  120.     end if
  121.     x=CreateObject("HtmlFile").ParentWindow.Screen.AvailWidth
  122.     y=CreateObject("HtmlFile").ParentWindow.Screen.AvailHeight
  123.     On Error Resume Next
  124.         .write "'注册大漠<br>"
  125.         Set dm= CreateObject("dm.dmsoft")
  126.         base_path = dm.GetBasePath() '检查是否注册大漠组件dm.dll,以更好支持鼠标、窗口、OCR等功能
  127.         '大模组件需要生成一个OCR专用的宋体9号字和10号字字库表,可以用大漠工具生成或与我联系索要。
  128.         If base_path="" Then
  129.             Mark="" '检查文件是否齐全
  130.             .write progfolder & "\dm.dll" & "<br>"
  131.             if not objFSO.FileExists ("c:\windows\system32\dm.dll") then
  132.                   Mark=progfolder
  133.                   .write "'复制大漠组件<br>"
  134.                   if not objFSO.FileExists (Mark & "\dm.dll") then Mark="k:"
  135.                   if not objFSO.FileExists (Mark & "\dm.dll") then msgbox "找不到dm组件,请把大漠组件复制入K盘。":ie.quit:wscript.quit
  136.                   objFSO.copyfile Mark & "\dm.dll","c:\windows\system32","True"
  137.                   objFSO.copyfile Mark & "\simsong9.txt","c:\windows\system32","True"
  138.                   objFSO.copyfile Mark & "\simsong10.txt","c:\windows\system32","True"
  139.                   objFSO.movefile progfolder & "\dm.dll","c:\windows\system32"  '将下面三个文件移动到%ProgramFiles%,system32可能没权限
  140.                   objFSO.movefile progfolder & "\simsong9.txt","c:\windows\system32"
  141.                   objFSO.movefile progfolder & "\simsong10.txt","c:\windows\system32"
  142.                   if not objFSO.FileExists ("c:\windows\system32\dm.dll") then msgbox ("复制失败")
  143.                   .write "'已复制"
  144.             end if
  145.             .write "'  正在注册"
  146.             ws.Run "regsvr32"&" /S "& chr(34) & "dm.dll" & chr(34) '因没有注册大漠组件dm.dll
  147.             .write "重新运行"& chr(34) & Wscript.scriptfullname & chr(34) & "<br>"
  148.             ws.Run "wscript.exe "& chr(34) & Wscript.scriptfullname & chr(34) '重新运行并退出
  149.             Close_Process("PinyinUp.exe")
  150.             Close_Process("ImeUtil.exe")
  151.             Close_Process("userNetSchedule.exe")
  152.             Close_Process("SohuNews.exe")
  153.             Close_Process("SGTool.exe")
  154.             objFSO.deleteFile "C:\Program Files\SogouInput\6.5.0.9181\PinyinUp.exe"
  155.             objFSO.deleteFile "C:\Program Files\SogouInput\6.5.0.9181\ImeUtil.exe"
  156.             objFSO.deleteFile "C:\Program Files\SogouInput\6.5.0.9181\userNetSchedule.exe"
  157.             objFSO.deleteFile "C:\Program Files\SogouInput\6.5.0.9181\SohuNews.exe"
  158.             objFSO.deleteFile "C:\Program Files\SogouInput\6.5.0.9181\SGTool.exe"
  159.             objFSO.deleteFile ws.CurrentDirectory & "dm.dll"
  160.             objFSO.deleteFile ws.CurrentDirectory & "simsong9.txt"
  161.             objFSO.deleteFile ws.CurrentDirectory & "simsong10.txt"
  162.             .write "'  注册完成,正在退出"
  163.             wscript.sleep 30000
  164.             ie.quit:wscript.quit
  165.         End If
  166.     On error goto 0
  167.     .write "'大漠组件正常<br>"
  168.     'ws.CurrentDirectory = progfolder & ""
  169.     dm.SetPath progfolder  & ""'设programfile文件夹为DM默认工作文件夹

  170.     Set dm= CreateObject("dm.dmsoft")
  171.     base_path = dm.GetBasePath()
  172.     dm.SetPath prog
  173.     'WshShell.Run "sc config w32time start= auto"
  174.     'while CPU_busy >4 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  175.     'WshShell.Run "net start w32time"
  176.     'while CPU_busy >4 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  177.     'ip=Split(Get_IP(),"."):if ip(0)<>"192" then msgbox "未找到网络驱动器, IP地址取出不正确,"
  178.     'str=ip(0) & "." & ip(1) & "." & ip(2) & ".6"
  179.     'WshShell.Run "net time \" & str & " /set /y"
  180.     if not objFSO.FileExists ("C:\Windows\Microsoft.NET\Framework\v4.0.30319\nul") then
  181.         .write "'本机未安装.net4<br>"
  182.         do while not objFSO.FileExists ("k:\dotNetFx40_Full_x86_x64.exe")
  183.              msgbox ("本机未安装.NET4而且K盘也没有这个文件,请复制入K盘继续")
  184.         loop
  185.         WshShell.Run "k:\dotNetFx40_Full_x86_x64.exe /q /norestart /ChainingPackage FullX64Bootstrapper"
  186.         wscript.sleep 60000
  187.         while is_Process("dotNetFx40_Full_x86_x64.exe"):wscript.sleep 1000:Wend
  188.         while CPU_busy >3 or Hard_busy >8000: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  189.         if not objFSO.FileExists ("C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe") then msgbox ".net4未安装成功":ie.quit:wscript.quit
  190.     end if
  191.     oldver=""
  192.     on error resume next
  193.         oldver=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NCRE一二级考试系统\DisplayVersion")
  194.     on error goto 0
  195.     ver_year=int((ver-37)/2)+2013 '这两句根据版本次计算出是哪一年的上半年还是下半年,得出类似“2014A”字串。
  196.     if ver_year=(ver-37)/2+2013 then ver_year=ver_year & "A" else ver_year=ver_year & "B"
  197.     if not objFSO.FileExists ("C:\Program Files\NCRE一二级考试系统\nul") or oldver<>ver_year then
  198.         if oldver<>ver_year then
  199.             .write "'删除老信息以便安装新版<br>"
  200.             on error resume next
  201.                 WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NCRE一二级考试系统"
  202.             on error goto 0
  203.         end if
  204.         .write "'本机未安装一二级考试系统<br>"
  205.         do while not objFSO.FileExists ("k:\NCRE一二级考试系统.exe")
  206.              msgbox ("本机未安装NCRE一二级考试系统.exe而且K盘也没有这个文件,请复制入K盘继续")
  207.         loop
  208.         WshShell.Run "k:\NCRE一二级考试系统.exe"
  209.         wscript.sleep 5000
  210.         while CPU_busy >4 or Hard_busy >8000: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  211.               ws.Appactivate("NCRE一二级考试系统 安装程序") '激活窗口标题
  212.               dm.MoveTo (x/2),(y/2) '移动并点击正中窗口的空白区域
  213.               dm.LeftClick '用鼠标点击
  214.         while is_Process("NCRE一二级考试系统.exe")
  215.             while CPU_busy >5 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  216.             ws.Sendkeys "%n"
  217.         Wend
  218.         dm.MoveTo (x/2),(y/2) '移动并点击正中窗口的空白区域
  219.         dm.LeftClick '用鼠标点击
  220.         ws.Sendkeys "%n"
  221.         while is_Process("NCRE一二级考试系统.exe")
  222.             while CPU_busy >5 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  223.             ws.Sendkeys chr(27)
  224.             while CPU_busy >5 or Hard_busy >10240: wscript.sleep 200:Wend '如果CPU忙或者硬盘忙则等待
  225.             ws.Sendkeys "Y"
  226.         Wend
  227.         .write "考试环境已成功安装,请点击桌面上的图标进入,桌面上有考试目录的快捷方式,可以点击进入。<br>"
  228.     end if
  229.     .write "考试环境已成功安装,请关闭本窗口后点击桌面上的“NCRE一二级考试系统”进入考试。<br>"
  230.     wscript.sleep 3000
  231.     ie.quit:wscript.quit
  232. '==========================================已更改用户名后的总退出出口======================================
  233. end with
  234.         
  235. dim wmi '显式定义一个全局变量'
  236. set wnd=ie.document.parentwindow '设置wnd为窗口对象'
  237. set id=ie.document.all '设置id为document中全部对象的集合'
  238. sub event_onquit 'ie退出事件处理过程'
  239.   wscript.quit '当ie退出时,脚本也退出'
  240. end sub
  241. do while true '由于ie对象支持事件,所以相应的,'
  242.   wscript.sleep 400 '脚本以无限循环来等待各种事件。'
  243. loop
  244. 'sc config w3svc start= DISABLED
  245. 'sc config iisadmin start= DISABLED
  246. 'DEMAND
  247. 'net stop smtpsvc
  248. 'smtpsvc






  249. '======================================================== 功能区 ========================================================
  250. FunctiOn Net_state(url) '检查网络Ping值,单位毫秒
  251.     Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus where Address = '" & url & "'")
  252.     For Each objPing in colPings
  253.         Net_state=objPing.ResponseTime
  254.     Next
  255. End Function
  256. Function Get_IP() '取IP
  257.     Set IPConfigSet = GetObject("winmgmts:\\.\root\cimv2")
  258.     Set colItems = IPConfigSet.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
  259.     For Each objItem in colItems
  260.         For Each objAddress in objItem.IPAddress
  261.             If objAddress <> "" then Get_IP = objAddress
  262.             exit for
  263.         Next
  264.     Next
  265.     Set IPConfigSet=Nothing
  266. End Function

  267. FunctiOn Close_Process(ProcessName) '关闭程序
  268. Set prog=getobject("winmgmts:\\.").instancesof("win32_process")
  269.   For Each i In prog
  270.     If LCase(i.name)=LCase(ProcessName) Then i.terminate()
  271.   Next
  272. End Function
  273. FunctiOn is_Process(ProcessName) '程序是否在运行
  274. Set prog=getobject("winmgmts:\\.").instancesof("win32_process")
  275.   is_Process=0
  276.   For Each i In prog
  277.     If LCase(i.name)=LCase(ProcessName) Then
  278.       is_Process=1
  279.     End If
  280.   Next
  281. End Function

  282. FunctiOn CPU_busy() 'CPU使用率
  283.     'On Error Resume Next
  284.     Set objProc = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")
  285.     CPU_busy=objProc.LoadPercentage 'CPU使用率
  286.     'On Error goto 0
  287. End Function

  288. FunctiOn Hard_busy() '硬盘忙闲
  289.     Dim vName,IDE,cPPP,sNow
  290.     Set IDE = WMI.ExecQuery("Select * from Win32_DiskDrive WHERE InterfaceType='IDE'")
  291.     Set cPPP = WMI.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE Name<>'_Total'")
  292.     DskPs="c:"
  293.     Dim A
  294.         Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = '"& DskPs &"'")
  295.         For Each B In A
  296.             R1 = B.DiskReadBytesPersec
  297.             W1 = B.DiskWriteBytesPersec
  298.             If RA0 = "" Then RA0 = B.DiskReadBytesPersec Else RA1 = R1 End If
  299.             If WA0 = "" Then WA0 = B.DiskWriteBytesPersec Else WA1 = W1 End If
  300.         Next
  301.     Set A = Nothing
  302.     WScript.Sleep(500)
  303.     Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = '"& DskPs &"'")
  304.     For Each B In A
  305.         R2 = B.DiskReadBytesPersec
  306.         W2 = B.DiskWriteBytesPersec
  307.     Next
  308.     Set A = Nothing
  309.     read=R2-R1
  310.     write=W2-W1
  311.     'msgbox  "半秒实时读取:" & read & "/s 实时写人:" & write
  312.     Hard_busy = read + write
  313. End Function
  314. Function Reboot() '重启
  315.     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
  316.     Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
  317.     For Each objOperatingSystem in colOperatingSystems
  318.       ObjOperatingSystem.Reboot()
  319.     Next'重启结束
  320. End Function
  321. Function Rename(oldname,newname) '更名
  322.     'msgbox "oldname=" & oldname & ",newname=" & newname
  323.     Rename=-1
  324.     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  325.     Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount where Name='"& oldname & "'",,48)
  326.     For Each colItem In colItems
  327.         'msgbox "find oldname"
  328.         Rename=colItem.Rename(newname)
  329.     Next
  330. End Function

  331. FunctiOn Wait_Net_ok() '网络已通
  332.     Mark=0
  333.     While Mark=0
  334.         Set mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
  335.         For Each mo In mc
  336.               Mark=mo.IPEnabled
  337.               If Mark=True Then
  338.                   wscript.sleep 500
  339.                   Exit For
  340.               End If
  341.         Next
  342.         wscript.sleep 300
  343.     Wend
  344.     Wait_Net_ok=1
  345. End Function
复制代码

发表于 2016-3-6 10:49 | 显示全部楼层
这样也行?用按键精灵更方便些吧?
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|网站地图|关于我们|小黑屋|爱好群|眉山东坡论坛 ( 蜀ICP备05001993号-1 )

GMT+8, 2018-1-20 22:55

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表