vbs 脚本设置与获取默认打印机
'设置默认打印机
oldDefault = GetDefaultPrinter
WScript.Echo oldDefault
Set WshNetwork = CreateObject("WScript.Network")
'Set defal = WshNetwork.GetDefaultPrinter()
WshNetwork.SetDefaultPrinter oldDefault
'查询默认打印机
Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
WScript.Echo strPrinter
oldDefault = GetDefaultPrinter
WScript.Echo oldDefault
Set WshNetwork = CreateObject("WScript.Network")
'Set defal = WshNetwork.GetDefaultPrinter()
WshNetwork.SetDefaultPrinter oldDefault
'查询默认打印机
Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
WScript.Echo strPrinter
'查询默认打印机
Function GetDefaultPrinter()
Set oShell = CreateObject("WScript.Shell")
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
sDefault = ""
On Error Resume Next
sDefault = oShell.RegRead(sRegVal)
sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)
On Error Goto 0
GetDefaultPrinter = sDefault
End Function
'注:以上均为摘抄自网络,此文为备份,以备查阅
评论
发表评论