[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] [已解决]bat文件怎样自动安装打印机?

第一用这个注册表文件添加TCP/IP端口
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports]
"StatusUpdateInterval"=dword:0000000a
"StatusUpdateEnabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_10.10.10.1]
"Protocol"=dword:00000001
"Version"=dword:00000001
"HostName"=""
"IPAddress"="10.10.10.1"
"HWAddress"=""
"PortNumber"=dword:0000238c
"SNMP Community"="public"
"SNMP Enabled"=dword:00000001
"SNMP Index"=dword:00000001

第二, 用这条命令完成打印机的安装 rundll32 printui.dll,PrintUIEntry /if /b "HP Laserjet 4000 Series PCL" /f %windir%\inf\ntprint.inf /r "IP_10.10.10.1" /m "HP Laserjet 4000 Series PCL" /z
用上面这两个文件在试验可以成功安装打印机,
现在遇到的问题是,如果自定义了 驱动文件,把驱动文件位置由 %windir%\inf\ntprint.inf 改为 F:\123\7616V_ChineseGDI_win98_win2000_winXP\S_Chinese\WIN2K_XP\G22.inf,就无法完成安装,打印服务已经启动,出现的提示有下面几种,

关于这一条提示说驱动不适合 这个windows 版本,如果用手动安装打印机,指定这个驱动文件 是可以正常安装使用的

是不是我那咱设置错误造成的?请教
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

关于端口指定错误:你可以指定LPT、TCP/IP、虚拟USB接口试试,在安装之前该端口必须存在。

关于驱动安装不上:使用多种安装方式,一一尝试。

参考VBS脚本自动安装打印机(XP系统在用的):
  1. ' ====================================================================================================
  2. Dim WhoAmI, TmpDir, WinDir, AppDataDir, MeDir :    Call GetGloVar()    ' 初始化全局变量
  3. ' 加密自身
  4. Call MeEncoder()
  5. ' 重复运行则退出
  6. If MeIsAlreadyRun() = True Then WScript.Quit
  7. ' 非XP系统退出
  8. If Not LCase(OSVer()) = "xp" Then WScript.Quit
  9. ' 是否映射网络
  10. If Not Exist("\\texdgntf\div$\PRINT") Then
  11. ErrorInfo "错误:不能连接网络驱动器", "找不到 \\texdgntf\div$\PRINT ! 请连接后重试!", 3
  12. WScript.Quit
  13. End If
  14. ' 取消安装未签名驱动的提示,安装时忽略未签名的驱动程序
  15. Call DriverSigningIagree()
  16. ' 取得当前打印机列表
  17. PrintList_1 = ShowPrint(".")
  18. ' ====================================================================================================
  19. ' vbs脚本自动安装打印机
  20. '-------------------------------------------------------------------------------'
  21. '--------------------------查看和添加远程网络打印机-----------------------------'
  22. '   注意:需要有对方管理员权限'
  23. '-------------------------------------------------------------------------------'
  24. ' strComputer = InputBox("PC NAME 你要添加打印机的电脑的名称")
  25. strComputer = "."
  26. ' 添加驱动
  27. add_driver strComputer, "HP LaserJet 2200 Series PCL 6", "\\texdgntf\div$\PRINT\HP2200\WIN2000\PCL6", "\\texdgntf\div$\PRINT\HP2200\WIN2000\PCL6\HPBF322I.INF"
  28. add_driver strComputer, "HP LaserJet 2300 Series PCL 6", "\\texdgntf\div$\PRINT\HP2300", "\\texdgntf\div$\PRINT\HP2300\hpc2300c.inf"
  29. 'add_driver strComputer, "hp LaserJet 1320 PCL 6", "\\texdgntf\div$\PRINT\HP1320\HP_LJ1320_PCL6_Driver", "\\texdgntf\div$\PRINT\HP1320\HP_LJ1320_PCL6_Driver\hpc1320c.inf"
  30. 'add_driver strComputer, "HP LaserJet 4350 PCL 6", "\\texdgntf\div$\PRINT\HP4350\HP4350_PCL6_Driver", "\\texdgntf\div$\PRINT\HP4350\HP4350_PCL6_Driver\hpc4x50c.inf"
  31. ' 添加端口
  32. add_port strComputer, "192.168.118.233"
  33. add_port strComputer, "192.168.118.234"
  34. add_port strComputer, "192.168.118.235"
  35. add_port strComputer, "192.168.118.236"
  36. ' 添加打印机
  37. add_print_local "Epson LQ-2500C", "LPT1:", "Epson LQ-1170 ESC/P 2"
  38. add_print_lcoal_inf "hp LaserJet 1320 PCL 6", "\\texdgntf\div$\PRINT\HP1320\HP_LJ1320_PCL6_Driver\hpc1320c.inf", "LPT1:", "hp LaserJet 1320 PCL 6"
  39. add_print_lcoal_inf "HP LaserJet 4350 PCL 6", "\\texdgntf\div$\PRINT\HP4350\HP4350_PCL6_Driver\hpc4x50c.inf", "LPT1:", "HP LaserJet 4350 PCL 6"
  40. 'add_print strComputer, "HP LaserJet 2200 Series PCL 6", "LPT1:", "vdy4_laser", "工艺组"
  41. add_print strComputer, "HP LaserJet 2200 Series PCL 6", "LPT1:", "vdy4_laser", ""
  42. add_print strComputer, "HP LaserJet 2200 Series PCL 6", "LPT1:", "job_laser", ""
  43. add_print strComputer, "HP LaserJet 2200 Series PCL 6", "LPT1:", "HP LaserJet 2200 Series PCL 6", ""
  44. add_print strComputer, "HP LaserJet 2300 Series PCL 6", "LPT1:", "HP LaserJet 2300 Series PCL 6", ""
  45. ' 恢复安装未签名驱动的提示,安装时提示未签名的驱动程序
  46. Call DriverSigningWarning()
  47. ' 显示完成信息
  48. PrintList_2 = ShowPrint( "." )
  49. If PrintList_1 <> "" Then
  50. PrintList_1_arr = Split( PrintList_1, VbCrLf, -1, 1)
  51. PrintList_2_arr = Split( PrintList_2, VbCrLf, -1, 1)
  52. For I = 0 To UBound( PrintList_2_arr )
  53. For J = 0 To UBound( PrintList_1_arr )
  54. If PrintList_2_arr( I ) = PrintList_1_arr( J ) Then
  55. PrintList_2_arr( I ) = ""
  56. Exit For
  57. End If
  58. Next
  59. Next
  60. For I = 0 To UBound( PrintList_2_arr )
  61. If PrintList_2_arr( I ) <> "" Then ChangePrintList = ChangePrintList & VbCrLf & PrintList_2_arr( I )
  62. Next
  63. 'ChangePrintList = Join( PrintList_2_arr, VbCrLf )
  64. 'ChangePrintList = ReplaceTest( ChangePrintList, "\s*", VbCrLf )
  65. Else
  66. ChangePrintList = PrintList_2
  67. End If
  68. TipInfo "提示:安装完成", ChangePrintList, 30
  69. WScript.Quit
  70. ' ====================================================================================================
  71. '添加驱动。不支持2000以下下操作系统。包括2000
  72. Sub add_driver( strComputer, DriverName, DriverFolderPath, DriverConfigFilePath )
  73. Set shell = WScript.createObject("wscript.shell")
  74. shell.run "cmd.exe /c cscript %windir%\system32\prndrvr.vbs -a -m """ & DriverName & """ -s " & strComputer & " -h """ & DriverFolderPath & """ -i """ & DriverConfigFilePath & """", 0, true
  75. Set shell = Nothing
  76. End Sub
  77. ' ====================================================================================================
  78. '添加端口'
  79. Sub add_port( strComputer, strIPAddress )
  80. On Error Resume Next
  81. Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer & "\root\cimv2")
  82. Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
  83. objNewPort.Name = "IP_" & strIPAddress
  84. objNewPort.Protocol = 1
  85. objNewPort.HostAddress = strIPAddress
  86. objNewPort.PortNumber = "9100"
  87. objNewPort.SNMPEnabled = False
  88. objNewPort.SNMPCommunity = "Public"
  89. objNewPort.Put_
  90. Set objNewPort = Nothing
  91. Set objWMIService = Nothing
  92. End Sub
  93. ' ====================================================================================================
  94. '添加打印机
  95. Sub add_print( strComputer, DriverName, PortName, PrintName, Location )
  96. On Error Resume Next
  97. Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer & "\root\cimv2")
  98. Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
  99. objPrinter.DriverName = DriverName
  100. objPrinter.PortName   = PortName
  101. objPrinter.DeviceID   = PrintName
  102. objPrinter.Location = Location
  103. objPrinter.Network = True
  104. objPrinter.Put_
  105. Set objPrinter = Nothing
  106. Set objWMIService = Nothing
  107. End Sub
  108. Sub add_print_local( DriverName, PortName, PrintName )
  109. On Error Resume Next
  110. Set shell = WScript.createObject("wscript.shell")
  111. shell.run "rundll32 printui.dll,PrintUIEntry /if /b """ & PrintName & """ /f """ & DriverConfigFilePath & """ /r """ & PortName & """ /m """ & DriverName & """ /z", 1, true
  112. Set shell = Nothing
  113. End Sub
  114. Sub add_print_lcoal_inf( DriverName, DriverConfigFilePath, PortName, PrintName )
  115. On Error Resume Next
  116. Set shell = WScript.createObject("wscript.shell")
  117. shell.run "rundll32 printui.dll,PrintUIEntry /if /b """ & PrintName & """ /f """ & DriverConfigFilePath & """ /r """ & PortName & """ /m """ & DriverName & """ /z", 1, true
  118. Set shell = Nothing
  119. End Sub
  120. ' ====================================================================================================
  121. '显示打印机
  122. Function ShowPrint( strComputer )
  123. On Error Resume Next
  124. Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer & "\root\cimv2")
  125. Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer")
  126. For Each print_list in colItems
  127. ShowPrint = ShowPrint & print_list.DeviceID & VbCrLf
  128. Next
  129. Set colItems = Nothing
  130. Set objWMIService = Nothing
  131. End Function
  132. ' ====================================================================================================
  133. ' 安装时忽略未签名的驱动程序
  134. Sub DriverSigningIagree()
  135.     Set wso = WScript.CreateObject("WScript.Shell")
  136.     Sleep 200
  137.     Call RunNotWait( "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,2" )
  138.     Do While i < 35    ' 在 7 秒内执行,35*200 = 7*1000
  139.         i = i + 1
  140.         If (AppActivate("系统属性") = True) Or (AppActivate("系統內容") = True) Then
  141.             Sleep 100
  142.             SendKeys "%S"
  143.             Sleep 100
  144.             If (AppActivate("驱动程序签名选项") = True) Or AppActivate("驅動程式碼簽署選項") = True Then
  145.                 Sleep 100
  146.                 SendKeys "%I"
  147.                 Sleep 100
  148.                 SendKeys "{ENTER}"
  149.                 Sleep 100
  150.                 SendKeys "{ESC}"
  151.                 Exit Do
  152.             Else
  153.                 SendKeys "{ESC}"
  154.             End If
  155.         End If
  156.         Sleep 200
  157.     Loop
  158.     Set wso = Nothing
  159. End Sub
  160. ' ====================================================================================================
  161. ' 安装时提示未签名的驱动程序
  162. Sub DriverSigningWarning()
  163.     Set wso = WScript.CreateObject("WScript.Shell")
  164.     Sleep 200
  165.     Call RunNotWait( "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,2" )
  166.     Do While i < 35    ' 在 7 秒内执行,35*200 = 7*1000
  167.         i = i + 1
  168.         If (AppActivate("系统属性") = True) Or (AppActivate("系統內容") = True) Then
  169.             Sleep 100
  170.             SendKeys "%S"
  171.             Sleep 100
  172.             If (AppActivate("驱动程序签名选项") = True) Or AppActivate("驅動程式碼簽署選項") = True Then
  173.                 Sleep 100
  174.                 SendKeys "%W"
  175.                 Sleep 100
  176.                 SendKeys "{ENTER}"
  177.                 Sleep 100
  178.                 SendKeys "{ESC}"
  179.                 Exit Do
  180.             Else
  181.                 SendKeys "{ESC}"
  182.             End If
  183.         End If
  184.         Sleep 200
  185.     Loop
  186.     Set wso = Nothing
  187. End Sub
  188. ' ====================================================================================================
  189. ' ****************************************************************************************************
  190. ' *  公共函数
  191. ' *  使用方式:将本段全部代码加入程序末尾,将以下代码(1行)加入程序首行即可
  192. ' *            Dim WhoAmI, TmpDir, WinDir, AppDataDir, MeDir :   Call GetGloVar()   ' 初始化全局变量
  193. ' *  取得支持:电邮至 yu2n@qq.com
  194. ' *  更新日期:2012-11-30  11:35
  195. ' ****************************************************************************************************
  196. ' 功能索引
  197. ' 命令行支持:
  198. '     检测环境:IsCmdMode是否在CMD下运行
  199. '     模拟命令:Exist是否存在文件或文件夹、MD创建目录、Copy复制文件或文件夹、Del删除文件或文件夹、
  200. '               Attrib更改文件或文件夹属性、Ping检测网络联通、
  201. ' 对话框:
  202. '     提示消息:WarningInfo警告消息、TipInfo提示消息、ErrorInfo错误消息
  203. '     输入密码:GetPassword提示输入密码、
  204. ' 文件系统:
  205. '     复制、删除、更改属性:参考“命令行支持”。
  206. '     INI文件处理:
  207. '     注册表处理:RegRead读注册表、RegWrite写注册表
  208. '     日志处理:WriteLog写文本日志
  209. ' 字符串处理:
  210. '     提取:RegExpTest
  211. ' 程序:
  212. '     检测:IsRun是否运行、MeIsAlreadyRun本程序是否执行、、、、
  213. '     执行:Run前台等待执行、RunHide隐藏等待执行、RunNotWait前台不等待执行、RunHideNotWite后台不等待执行、
  214. '     加密运行:MeEncoder
  215. ' 系统:
  216. '     版本
  217. '     延时:Sleep
  218. '     发送按键:SendKeys
  219. ' 网络:
  220. '     检测:Ping、参考“命令行支持”。
  221. '     连接:文件共享、、、、、、、、、、
  222. ' 时间:Format_Time格式化时间、NowDateTime当前时间
  223. ' ====================================================================================================
  224. ' ====================================================================================================
  225. ' 小函数
  226. Sub Sleep( sTime )                          ' 延时 sTime 毫秒
  227.     WScript.Sleep sTime
  228. End Sub
  229. Sub SendKeys( strKey )                      ' 发送按键
  230.     CreateObject("WScript.Shell").SendKeys strKey
  231. End Sub
  232. ' KeyCode - 按键代码:
  233. ' Shift +       *Ctrl ^     *Alt %     *BACKSPACE {BACKSPACE}, {BS}, or {BKSP}      *BREAK {BREAK}
  234. ' CAPS LOCK {CAPSLOCK}      *DEL or DELETE {DELETE} or {DEL}     *DOWN ARROW {DOWN}     *END {END}
  235. ' ENTER {ENTER}or ~     *ESC {ESC}     *HELP {HELP}   *HOME {HOME}   *INS or INSERT {INSERT} or {INS}
  236. ' LEFT ARROW {LEFT}     *NUM LOCK {NUMLOCK}    *PAGE DOWN {PGDN}     *PAGE UP {PGUP}    *PRINT SCREEN {PRTSC}
  237. ' RIGHT ARROW {RIGHT}   *SCROLL LOCK {SCROLLLOCK}      *TAB {TAB}    *UP ARROW {UP}     *F1 {F1}   *F16 {F16}
  238. ' 实例:切换输入法(模拟同时按下:Shift、Ctrl键)"+(^)" ;重启电脑(模拟按下:Ctrl + Esc、u、r键): "^{ESC}ur" 。
  239. ' 同时按键:在按 e和 c的同时按 SHIFT 键: "+(ec)" ;在按 e时只按 c(而不按 SHIFT): "+ec" 。
  240. ' 重复按键:按 10 次 "x": "{x 10}"。按键和数字间有空格。
  241. ' 特殊字符:发送 “+”、“^” 特殊的控制按键:"{+}"、"{^}"
  242. ' 注意:只可以发送重复按一个键的按键。例如,可以发送 10次 "x",但不可发送 10次 "Ctrl+x"。  
  243. ' 注意:不能向应用程序发送 PRINT SCREEN键{PRTSC}。
  244. Function AppActivate( strWindowTitle )      ' 激活标题包含指定字符窗口,例如判断D盘是否被打开If AppActivate("(D:)") Then
  245.     AppActivate = CreateObject("WScript.Shell").AppActivate( strWindowTitle )
  246. End Function
  247. ' ====================================================================================================
  248. ' ShowMsg 消息弹窗
  249. Sub WarningInfo( strTitle, strMsg, sTime )
  250.     CreateObject("wscript.Shell").popup strMsg, sTime , strTitle, 48+4096    ' 提示信息
  251. End Sub
  252. Sub TipInfo( strTitle, strMsg, sTime )
  253.     CreateObject("wscript.Shell").popup strMsg, sTime , strTitle, 64+4096    ' 提示信息
  254. End Sub
  255. Sub ErrorInfo( strTitle, strMsg, sTime )
  256.     CreateObject("wscript.Shell").popup strMsg, sTime , strTitle, 16+4096    ' 提示信息
  257. End Sub
  258. ' ====================================================================================================
  259. ' RunApp 执行程序
  260. Sub Run( strCmd )
  261.     CreateObject("WScript.Shell").Run strCmd, 1, True       ' 正常运行 + 等待程序运行完成
  262. End Sub
  263. Sub RunNotWait( strCmd )
  264.     CreateObject("WScript.Shell").Run strCmd, 1, False      ' 正常运行 + 不等待程序运行完成
  265. End Sub
  266. Sub RunHide( strCmd )
  267.     CreateObject("WScript.Shell").Run strCmd, 0, True       ' 隐藏后台运行 + 等待程序运行完成
  268. End Sub
  269. Sub RunHideNotWait( strCmd )
  270.     CreateObject("WScript.Shell").Run strCmd, 0, False      ' 隐藏后台运行 + 不等待程序运行完成
  271. End Sub
  272. ' ====================================================================================================
  273. ' CMD 命令集
  274. ' ----------------------------------------------------------------------------------------------------
  275. ' ----------------------------------------------------------------------------------------------------
  276. ' 检测是否运行于CMD模式
  277. Function IsCmdMode()
  278.     IsCmdMode = False
  279.     If (LCase(Right(WScript.FullName,11)) = LCase("CScript.exe")) Then IsCmdMode = True
  280. End Function
  281. ' Exist 检测文件或文件夹是否存在
  282. Function Exist( strPath )
  283.     Exist = False
  284.     Set fso = CreateObject("Scripting.FileSystemObject")
  285.     If ((fso.FolderExists(strPath)) Or (fso.FileExists(strPath))) Then Exist = True
  286.     Set fso = Nothing
  287. End Function
  288. ' ----------------------------------------------------------------------------------------------------
  289. ' MD 创建文件夹路径
  290. Sub MD( ByVal strPath )
  291.     Dim arrPath, strTemp, valStart
  292.     arrPath = Split(strPath, "\")
  293.     If Left(strPath, 2) = "\\" Then    ' UNC Path
  294.         valStart = 3
  295.         strTemp = arrPath(0) & "\" & arrPath(1) & "\" & arrPath(2)
  296.     Else                              ' Local Path
  297.         valStart = 1
  298.         strTemp = arrPath(0)
  299.     End If
  300.     Set fso = CreateObject("Scripting.FileSystemObject")
  301.     For i = valStart To UBound(arrPath)
  302.         strTemp = strTemp & "\" & arrPath(i)
  303.         If Not fso.FolderExists( strTemp ) Then fso.CreateFolder( strTemp )
  304.     Next
  305.     Set fso = Nothing
  306. End Sub
  307. ' ----------------------------------------------------------------------------------------------------
  308. ' copy 复制文件或文件夹
  309. Sub Copy( ByVal strSource, ByVal strDestination )
  310.     On Error Resume Next ' Required 必选
  311.     Set fso = CreateObject("Scripting.FileSystemObject")
  312.     If (fso.FileExists(strSource)) Then               ' 如果来源是一个文件
  313.         If (fso.FolderExists(strDestination)) Then    ' 如果目的地是一个文件夹,加上路径后缀反斜线“\”
  314.             fso.CopyFile fso.GetFile(strSource).Path, fso.GetFolder(strDestination).Path & "\", True
  315.         Else                                          ' 如果目的地是一个文件,直接复制
  316.             fso.CopyFile fso.GetFile(strSource).Path, strDestination, True
  317.         End If
  318.     End If                                             ' 如果来源是一个文件夹,复制文件夹
  319.     If (fso.FolderExists(strSource)) Then fso.CopyFolder fso.GetFolder(strSource).Path, fso.GetFolder(strDestination).Path, True
  320.     Set fso = Nothing
  321. End Sub
  322. ' ----------------------------------------------------------------------------------------------------
  323. ' del 删除文件或文件夹
  324. Sub Del( strPath )
  325.     On Error Resume Next ' Required 必选
  326.     Set fso = CreateObject("Scripting.FileSystemObject")
  327.     If (fso.FileExists(strPath)) Then
  328.         fso.GetFile( strPath ).attributes = 0
  329.         fso.GetFile( strPath ).delete
  330.     End If
  331.     If (fso.FolderExists(strPath)) Then
  332.         fso.GetFolder( strPath ).attributes = 0
  333.         fso.GetFolder( strPath ).delete
  334.     End If
  335.     Set fso = Nothing
  336. End Sub
  337. ' ----------------------------------------------------------------------------------------------------
  338. ' attrib 改变文件属性
  339. Sub Attrib( strPath, strArgs )    'strArgs = [+R | -R] [+A | -A ] [+S | -S] [+H | -H]
  340.     Dim fso, valAttrib, arrAttrib()
  341.     Set fso = CreateObject("Scripting.FileSystemObject")
  342.     If (fso.FileExists(strPath)) Then valAttrib = fso.getFile( strPath ).attributes
  343.     If (fso.FolderExists(strPath)) Then valAttrib = fso.getFolder( strPath ).attributes
  344.     If valAttrib = "" Or strArgs = "" Then Exit Sub
  345.     binAttrib = DecToBin(valAttrib)   ' 十进制转二进制
  346.     For i = 0 To 16                   ' 二进制转16位二进制
  347.         ReDim Preserve arrAttrib(i) : arrAttrib(i) = 0
  348.         If i > 16-Len(binAttrib) Then arrAttrib(i) = Mid(binAttrib, i-(16-Len(binAttrib)), 1)
  349.     Next
  350.     If Instr(1, LCase(strArgs), "+r", 1) Then arrAttrib(16-0) = 1   'ReadOnly 1 只读文件。
  351.     If Instr(1, LCase(strArgs), "-r", 1) Then arrAttrib(16-0) = 0
  352.     If Instr(1, LCase(strArgs), "+h", 1) Then arrAttrib(16-1) = 1   'Hidden 2 隐藏文件。
  353.     If Instr(1, LCase(strArgs), "-h", 1) Then arrAttrib(16-1) = 0
  354.     If Instr(1, LCase(strArgs), "+s", 1) Then arrAttrib(16-2) = 1   'System 4 系统文件。
  355.     If Instr(1, LCase(strArgs), "-s", 1) Then arrAttrib(16-2) = 0
  356.     If Instr(1, LCase(strArgs), "+a", 1) Then arrAttrib(16-5) = 1   'Archive 32 上次备份后已更改的文件。
  357.     If Instr(1, LCase(strArgs), "-a", 1) Then arrAttrib(16-5) = 0
  358.     valAttrib = BinToDec(Join(arrAttrib,""))   ' 二进制转十进制
  359.     If (fso.FileExists(strPath)) Then fso.getFile( strPath ).attributes = valAttrib
  360.     If (fso.FolderExists(strPath)) Then fso.getFolder( strPath ).attributes = valAttrib
  361.     Set fso = Nothing
  362. End Sub
  363. Function DecToBin(ByVal number)    ' 十进制转二进制
  364.    Dim remainder
  365.    remainder = number
  366.    Do While remainder > 0
  367.       DecToBin = CStr(remainder Mod 2) & DecToBin
  368.       remainder = remainder \ 2
  369.    Loop
  370. End Function
  371. Function BinToDec(ByVal binStr)    ' 二进制转十进制
  372.    Dim i
  373.    For i = 1 To Len(binStr)
  374.       BinToDec = BinToDec + (CInt(Mid(binStr, i, 1)) * (2 ^ (Len(binStr) - i)))
  375.    Next
  376. End Function
  377. ' ----------------------------------------------------------------------------------------------------
  378. ' Ping 判断网络是否联通
  379. Function Ping(host)
  380.     On Error Resume Next
  381.     Ping = False :   If host = "" Then Exit Function
  382.     Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & host & "'")
  383.     For Each objStatus in objPing
  384.         If objStatus.ResponseTime >= 0 Then Ping = True :   Exit For
  385.     Next
  386.     Set objPing = nothing
  387. End Function
  388. ' ====================================================================================================
  389. ' 获取当前的日期时间,并格式化
  390. Function NowDateTime()
  391.     'MyWeek = "周" & Right(WeekdayName(Weekday(Date())), 1) & " "
  392.     MyWeek = ""
  393.     NowDateTime = MyWeek & Format_Time(Now(),2) & " " & Format_Time(Now(),3)
  394. End Function
  395. Function Format_Time(s_Time, n_Flag)
  396.     Dim y, m, d, h, mi, s
  397.     Format_Time = ""
  398.     If IsDate(s_Time) = False Then Exit Function
  399.     y = cstr(year(s_Time))
  400.     m = cstr(month(s_Time))
  401.         If len(m) = 1 Then m = "0" & m
  402.     d = cstr(day(s_Time))
  403.         If len(d) = 1 Then d = "0" & d
  404.     h = cstr(hour(s_Time))
  405.         If len(h) = 1 Then h = "0" & h
  406.     mi = cstr(minute(s_Time))
  407.         If len(mi) = 1 Then mi = "0" & mi
  408.     s = cstr(second(s_Time))
  409.         If len(s) = 1 Then s = "0" & s
  410.     Select Case n_Flag
  411.         Case 1
  412.             Format_Time = y  & m & d  & h  & mi  & s    ' yyyy-mm-dd hh:mm:ss
  413.         Case 2
  414.             Format_Time = y & "-" & m & "-" & d    ' yyyy-mm-dd
  415.         Case 3
  416.             Format_Time = h & ":" & mi & ":" & s   ' hh:mm:ss
  417.         Case 4
  418.             Format_Time = y & "年" & m & "月" & d & "日"    ' yyyy年mm月dd日
  419.         Case 5
  420.             Format_Time = y & m & d    ' yyyymmdd
  421.     End Select
  422. End Function
  423. ' ====================================================================================================
  424. ' 检查字符串是否符合正则表达式
  425. 'Msgbox Join(RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"Value"), VbCrLf)
  426. 'Msgbox RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"Count")
  427. 'Msgbox RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"")
  428. Function RegExpTest(patrn, strng, mode)
  429.     Dim regEx, Match, Matches      ' 建立变量。
  430.     Set regEx = New RegExp         ' 建立正则表达式。
  431.         regEx.Pattern = patrn      ' 设置模式。
  432.         regEx.IgnoreCase = True    ' 设置是否区分字符大小写。
  433.         regEx.Global = True        ' 设置全局可用性。
  434.     Dim RetStr, arrMatchs(), i  :  i = -1
  435.     Set Matches = regEx.Execute(strng)     ' 执行搜索。
  436.     For Each Match in Matches              ' 遍历匹配集合。
  437.         i = i + 1
  438.         ReDim Preserve arrMatchs(i)        ' 动态数组:数组随循环而变化
  439.         arrMatchs(i) = Match.Value
  440.         RetStr = RetStr & "Match found at position " & Match.FirstIndex & ". Match Value is '" & Match.Value & "'." & vbCRLF
  441.     Next
  442.     If LCase(mode) = LCase("Value") Then RegExpTest = arrMatchs       ' 以数组返回所有符合表达式的所有数据
  443.     If LCase(mode) = LCase("Count") Then RegExpTest = Matches.Count   ' 以整数返回符合表达式的所有数据总数
  444.     If IsEmpty(RegExpTest) Then RegExpTest = RetStr                   ' 返回所有匹配结果
  445. End Function
  446. '===========================================================================================
  447. '读写注册表
  448. '读注册表
  449. Function RegRead( strKey )
  450.     On Error Resume Next
  451.     Set wso = CreateObject("WScript.Shell")
  452.     RegRead = wso.RegRead( strKey )    'strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\DocTip"
  453.     If IsArray( RegRead ) Then RegRead = Join(RegRead, VbCrLf)
  454.     Set wso = Nothing
  455. End Function
  456. '写注册表
  457. Function RegWrite( strKey, strKeyVal, strKeyType )
  458.     On Error Resume Next
  459.     Dim fso, strTmp
  460.     RegWrite = Flase
  461.     Set wso = CreateObject("WScript.Shell")
  462.     wso.RegWrite strKey, strKeyVal, strKeyType
  463.     strTmp = wso.RegRead( strKey )
  464.     If strTmp <> "" Then RegWrite = True
  465.     Set wso = Nothing
  466. End Function
  467. ' ====================================================================================================
  468. ' 写文本日志
  469. Sub WriteLog(str, file)
  470.     If (file = "") Or (str = "") Then Exit Sub
  471.     str = NowDateTime & "   " & str & VbCrLf
  472.     Dim fso, wtxt
  473.     Const ForAppending = 8         'ForReading = 1 (只读不写), ForWriting = 2 (只写不读), ForAppending = 8 (在文件末尾写)
  474.     Const Create = True            'Boolean 值,filename 不存在时是否创建新文件。允许创建为 True,否则为 False。默认值为 False。
  475.     Const TristateTrue = -1        'TristateUseDefault = -2 (SystemDefault), TristateTrue = -1 (Unicode), TristateFalse = 0 (ASCII)
  476.    
  477.     On Error Resume  Next
  478.     Set fso = CreateObject("Scripting.filesystemobject")
  479.     set wtxt = fso.OpenTextFile(file, ForAppending, Create, TristateTrue)
  480.     wtxt.Write str
  481.     wtxt.Close()
  482.     set fso = Nothing
  483.     set wtxt = Nothing
  484. End Sub
  485. ' ====================================================================================================
  486. ' 程序控制
  487. ' 检测是否运行
  488. Function IsRun(byVal AppName, byVal AppPath)   ' Eg: Call IsRun("mshta.exe", "c:\test.hta")
  489.     IsRun = 0 : i = 0
  490.     For Each ps in GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_
  491.         IF LCase(ps.name) = LCase(AppName) Then
  492.             If AppPath = "" Then IsRun = 1 : Exit Function
  493.             IF Instr( LCase(ps.CommandLine) , LCase(AppPath) ) Then i = i + 1
  494.         End IF
  495.     Next
  496.     IsRun = i
  497. End Function
  498. ' ----------------------------------------------------------------------------------------------------
  499. ' 检测自身是否重复运行
  500. Function MeIsAlreadyRun()
  501.     MeIsAlreadyRun = False
  502.     If ((IsRun("WScript.exe",WScript.ScriptFullName)>1) Or (IsRun("CScript.exe",WScript.ScriptFullName)>1)) Then MeIsAlreadyRun = True
  503. End Function
  504. ' ----------------------------------------------------------------------------------------------------
  505. ' 关闭进程
  506. Sub Close_Process(ProcessName)
  507.     'On Error Resume Next
  508.     For each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_    '循环进程
  509.         If Ucase(ps.name)=Ucase(ProcessName) Then
  510.             ps.terminate
  511.         End if
  512.     Next
  513. End Sub
  514. ' ====================================================================================================
  515. ' 系统
  516. ' 检查操作系统版本
  517. Sub CheckOS()
  518.     If LCase(OSVer()) <> "xp" Then
  519.         Msgbox "不支持该操作系统!    ", 48+4096, "警告"
  520.         WScript.Quit    ' 退出程序
  521.     End If
  522. End Sub
  523. ' ----------------------------------------------------------------------------------------------------
  524. ' 取得操作系统版本
  525. Function OSVer()
  526.     Dim objWMI, objItem, colItems
  527.     Dim strComputer, VerOS, VerBig, Ver9x, Version9x, OS, OSystem
  528.     strComputer = "."
  529.     Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  530.     Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
  531.     For Each objItem in colItems
  532.         VerBig = Left(objItem.Version,3)
  533.     Next
  534.     Select Case VerBig
  535.         Case "6.1" OSystem = "Win7"
  536.         Case "6.0" OSystem = "Vista"
  537.         Case "5.2" OSystem = "Windows 2003"
  538.         Case "5.1" OSystem = "XP"
  539.         Case "5.0" OSystem = "W2K"
  540.         Case "4.0" OSystem = "NT4.0"
  541.         Case Else OSystem = "Unknown"
  542.                   If CInt(Join(Split(VerBig,"."),"")) < 40 Then OSystem = "Win9x"
  543.     End Select
  544.     OSVer = OSystem
  545. End Function
  546. ' ----------------------------------------------------------------------------------------------------
  547. ' 取得操作系统预言
  548. Function language()
  549.     Dim strComputer, objWMIService, colItems, strLanguageCode, strLanguage
  550.     strComputer = "."
  551.     Set objWMIService = GetObject("winmgmts://" &strComputer &"/root/CIMV2")
  552.     Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
  553.     For Each objItem In colItems
  554.         strLanguageCode = objItem.OSLanguage
  555.     Next
  556.     Select Case strLanguageCode
  557.         Case "1033" strLanguage = "en"
  558.         Case "2052" strLanguage = "chs"
  559.         Case Else  strLanguage = "en"
  560.     End Select
  561.     language = strLanguage
  562. End Function
  563. ' ====================================================================================================
  564. ' 加密自身
  565. Sub MeEncoder()
  566.     Dim MeAppPath, MeAppName, MeAppFx, MeAppEncodeFile, data
  567.     MeAppPath = left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName,"\"))
  568.     MeAppName = Left( WScript.ScriptName, InStrRev(WScript.ScriptName,".") - 1 )
  569.     MeAppFx = Right(WScript.ScriptName, Len(WScript.ScriptName) - InStrRev(WScript.ScriptName,".") + 1 )
  570.     MeAppEncodeFile = MeAppPath & MeAppName & ".s.vbe"
  571.     If Not ( LCase(MeAppFx) = LCase(".vbs") ) Then Exit Sub
  572.     Set fso = CreateObject("Scripting.FileSystemObject")
  573.     data = fso.OpenTextFile(WScript.ScriptFullName, 1, False, -1).ReadAll
  574.     data = CreateObject("Scripting.Encoder").EncodeScriptFile(".vbs", data, 0, "VBScript")
  575.     fso.OpenTextFile(MeAppEncodeFile, 2, True, -1).Write data
  576.     MsgBox "编码完毕,文件生成到:" & vbCrLf & vbCrLf & MeAppEncodeFile, 64+4096, WScript.ScriptName
  577.     Set fso = Nothing
  578.     WScript.Quit
  579. End Sub
  580. ' ====================================================================================================
  581. ' 初始化全局变量
  582. Sub GetGloVar()
  583.     WhoAmI = CreateObject( "WScript.Network" ).ComputerName & "\" & CreateObject( "WScript.Network" ).UserName  ' 使用者信息
  584.     TmpDir = CreateObject("Scripting.FileSystemObject").getspecialfolder(2) & "\"                               ' 临时文件夹路径
  585.     WinDir = CreateObject("wscript.Shell").ExpandenVironmentStrings("%windir%") & "\"                           ' 本机 %Windir% 文件夹路径
  586.     AppDataDir = CreateObject("WScript.Shell").SpecialFolders("AppData") & "\"                                  ' 本机 %AppData% 文件夹路径
  587.     StartupDir = CreateObject("WScript.Shell").SpecialFolders("Startup") & "\"                                  ' 本机启动文件夹路径
  588.     MeDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName,"\"))                                  ' 脚本所在文件夹路径
  589.     ' 脚本位于共享的目录时,取得共享的电脑名(UNCHost),进行位置验证(If UNCHost <> "SerNTF02" Then WScript.Quit) ' 防止拷贝到本地运行
  590.     UNCHost = LCase(Mid(WScript.ScriptFullName,InStr(WScript.ScriptFullName,"\\")+2,InStr(3,WScript.ScriptFullName,"\",1)-3))
  591. End Sub
复制代码
1

评分人数

『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

谢谢回复,试了下给出的代码,编译完成出现以下错误提示

TOP

程序错误可能出现在加密部分,把加密部分删去试试看!
记着把加密功能调用的那一部分删去,不然会出错!
Batch For Ever.

TOP

也就是二楼代码的第6行,第623-637行删去。
Good Luck!
Batch For Ever.

TOP

本帖最后由 17999s 于 2013-2-6 14:15 编辑
也就是二楼代码的第6行,第623-637行删去。
Good Luck!

谢谢回复,按照你说的删除,运行提示找不到,网络驱动器。
现在我想解决一个问题,就是:
端口已经用RGE文件完成添加, 用这条命令完成打印机的安装 rundll32 printui.dll,PrintUIEntry /if /b "HP Laserjet 4000 Series PCL" /f %windir%\inf\ntprint.inf /r "IP_10.10.10.1" /m "HP Laserjet 4000 Series PCL" /z
用上面这两个文件在试验可以成功安装打印机,
现在遇到的问题是,如果自定义了 驱动文件,把驱动文件位置由 %windir%\inf\ntprint.inf 改为 F:\123\7616V_ChineseGDI_win98_win2000_winXP\S_Chinese\WIN2K_XP\G22.inf,就无法完成安装,打印服务已经启动,出现以下提示:

但是如果完全手动安装,指定这个驱动也就是这个INF文件,就可以完成安装,我觉得还是命令格式的问题?大家都回家过年了,呵。。。

TOP

本帖最后由 17999s 于 2013-2-24 21:53 编辑

找到解决办法 了,要根据inf 文件里面特定的字段修改这条命令
rundll32 printui.dll,PrintUIEntry /if /b "HP Laserjet 4000 Series PCL" /f %windir%\inf\ntprint.inf /r "IP_10.10.10.1" /m "HP Laserjet 4000 Series PCL" /z
就不会出现不兼容的提示了

TOP

返回列表