问题是使用PS,cmd,vbs等脚本自动化Win7中的打印机驱动程序更新(打印机设置)和打印机首选项? [英] Issues automating printer driver update (printer settings) and printer preferences in Win7, using a PS,cmd,vbs,etc script?

查看:1216
本文介绍了问题是使用PS,cmd,vbs等脚本自动化Win7中的打印机驱动程序更新(打印机设置)和打印机首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WMI可以做到,但我有一个问题,PCs已打开,但已注销。如果我尝试运行:

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"

它失败,并显示有关通用失败的消息。我RDP入,然后从我的结束运行相同的命令,它的工作原理。 Powershell版本我使用的是较旧的,所以它没有一些打印机cmdlet,并且更新PS目前是不存在的问题。有没有办法远程登录某人,实际上不需要RDP?通过PS,cmd,PSEXEC等?

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?

我采用的另一个途径是使用regedit,但我打了一些hicups,也就是说,我不知道要复制什么。在regedit中,我可以更改启用双面打印和tray2(在打印机设置中)的驱动程序名称和设置,但我无法确定如何更改打印机首选项中的双面打印设置以及沿着长边打印。

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.

我做了什么来确定要更改的内容,我在regedit中查找打印机名称作为数据值,并在更改设置之前导出了键。然后我在更改设置后再次导出。然后我使用 fc / c / a / u before.reg after.reg 获取更改。我砍了.reg只包括更改的值。运行.reg似乎改变了一切,但打印的两边,沿着长边的设置。这是一个lexmark打印机,所以我想知道是否有偏好可以存储在其他地方。

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.

这是我最新的PS1脚本。我已经评论了一些行,因为我尝试了不同的方式做事情:

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()

无论以何种方式尝试它,invoke-command或get-wmiobject,我都得到:

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

如何做。

用户最好使用登录脚本,因为这是Windows的设计。

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

这篇关于问题是使用PS,cmd,vbs等脚本自动化Win7中的打印机驱动程序更新(打印机设置)和打印机首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆