如何使用cmd进入打印机选项,问题是使用PS,cmd,vbs等脚本自动化Win7中的打印机驱动程序更新(打印机设置)和打印机首选项?...

WMI can do it, but I have an issue, PCs are on, but logged off. If I try to run:

wmic /node:%strIP% printer where DeviceID="lp1" set DriverName="Lexmark Universal v2"

It fails with a message about a "generic failure". I RDP in and then run the same command from my end, and it works. Powershell version I am using is older, so it does not have some of the printer cmdlets, and updating PS is currently out of the question. Is there a way to remotely log someone in, without actually having to RDP in? Via PS, cmd, PSEXEC, etc?

The other avenue I've taken is using regedit, but I'm hitting some hicups with that, namely that I cannot figure out what to copy. In regedit, I can change the drivername and the setting that enable duplex and tray2 (in printer settings), but I cannot figure how to change the settings in printer preferences for printing double sided and doing so along the long edge.

What I did to figure out what to change, I did a find on the printer name in regedit as a data value and exported the keys before changing the settings. Then I exported it again AFTER changing the settings. I then used fc /c /a /u before.reg after.reg to get the changes. I chopped up the .reg to include only the changed values. Running the .reg seems to change everything, but the print both sides, along the long edge settings. It is a lexmark printer, so I am wondering if maybe preferences for it are stored elsewhere.

This is my most up to date PS1 script. I've commented out some lines as I tried different ways of doing things:

$Cred = Get-Credential

$Str = Read-Host "Please select a site ID [###] "

$PC = Read-Host "Please select a PC number [##] "

Clear-Host

$PCNm = "$Str-CCPC-$PC"

function Test-PsRemoting

{

try

{

$errorActionPreference = "Stop"

$result = Invoke-Command -ComputerName $PCNm { 1 }

}

catch

{

Write-Verbose $_

return $false

}

if($result -ne 1)

{

Write-Verbose "Remoting to $PCNm returned an unexpected result."

return $false

}

$true

}

If(!(Test-PsRemoting)){

PSEXEC \\$PCNm powershell Enable-PSRemoting -force 2>&1 >nul

Clear-Host

Write-Host "Enabled PsRemoting"

}else{Write-Host "PsRemoting already enabled"}

Invoke-Command -ComputerName $PCNm -Credential $Cred -ScriptBlock {

#$lp1 = Get-WMIObject -Query "SELECT * from Win32_Printer Where DeviceID='lp1'"

$lp1 = Get-WmiObject Win32_Printer | ?{$_.name -eq "lp1"}

$lp1.Scope.Options.EnablePrivileges = $true

$lp1.DriverName = "Lexmark Universal v2"

$lp1R = $lp1.Put()

#$lp2 = Get-WMIObject -Query "SELECT * from Win32_Printer Where DeviceID='lp2'"

$lp2 = Get-WmiObject Win32_Printer | ?{$_.name -eq "lp2"}

$lp2.Scope.Options.EnablePrivileges = $true

$lp2.DriverName = "Lexmark Universal v2"

$lp2R = $lp2.Put()

}

#$lp1 = Get-WMIObject -Impersonation Delegate -Authentication Call -Credential $Cred -ComputerName $PCNm -Query "SELECT * from Win32_Printer Where DeviceID='lp1'"

#$lp1.DriverName = "Lexmark Universal v2"

#$lp1.Put()

No matter which way I try it, invoke-command, or get-wmiobject, I get:

Exception calling "Put" with "0" argument(s): "Generic failure "

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

+ PSComputerName : 150-CCPC-02

解决方案wmic /node:servername /user:username /password:password path win32_something call methodname

Is how to do it.

Things with users are best done with logon scripts because that is how windows is designed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值