VBS 拷贝 注册表键值

同事告诉我,由于某种bug,打印机的驱动程序在客户端无法正常安装,或者安装成功之后过了一段时间一些键值就会改变,希望我写个小程序检查并复制正确的键值。基本思路很简单,先备份一下键值,检查该键值是否为空,如果不为空,那么停止spooler服务,从远程服务器拷贝该键值,然后运行spooler服务。因为他打算用KACE来配置,KACE又不支持batch文件,所以我需要用VBS实现。


首先备份一下键值

Dim oShell

Set oShell = WScript.CreateObject ("WScript.Shell")

oShell.run "cmd.exe /c reg copy ""HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\HP Universal Printing PCL 6 (v5.6.1)"" ""HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\HP Universal Printing.backup"" /f"


然后读取该键值的值,注意这个键值是类型是个数组,而不是普通的字符串

Dim WSHShell, value

Set WSHShell = CreateObject("WScript.Shell")

value = WSHShell.RegRead( "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\HP Universal Printing PCL 6 (v5.6.1)\Dependent Files")


判断数组大小,是否为空,如果为空,先停止spooler服务


if ubound(value)<0 then


oShell.run "cmd.exe /k"

wscript.sleep 500

oShell.sendkeys "sc stop Spooler"+("{Enter}")

wscript.sleep 5000


然后拷贝正确的键值


oShell.sendkeys "reg copy ""\\10.71.82.199\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\HP Universal Printing PCL 6 {(}v5.6.1{)}"" ""HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\HP Universal Printing PCL 6 {(}v5.6.1{)}"" /f"+("{Enter}")

wscript.sleep 500


然后重新启动Spooler服务


oShell.sendkeys "sc start Spooler"+("{Enter}")

wscript.sleep 5000

'oShell.sendkeys "exit" +("{Enter}")


end if


搞定!

你可能感兴趣的:(windows,服务器,客户端,注册表,打印机)