我必须使用 GPO 部署虚拟打印机软件。发布者提供的 MSI 安装程序工作正常,但在安装过程中没有将虚拟打印机设置为默认值的选项。
所以我创建了这个“简单”的 powershell 脚本来更改默认打印机。
## Get the Printer with WMI
$printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name = 'GreenPrint'"
## Set printer as default printer
$printer.SetDefaultPrinter()
安装后手动执行此脚本工作正常,但有没有办法通过使用转换文件 (.mst) 将此脚本包含在 MSI 的安装过程中。
感谢您的回答
使用 Powershell 完全安装
根据 Niklas Sjögren 的提议,我创建了一个 Powershell 脚本,它安装 MSI 包,然后将打印机设置为默认值。由于 GPO 没有提供仅在登录时运行一次脚本的选项,因此我使用注册密钥来检查我们是否需要处理。
我认为您最好在工作站的初始配置中使用这种脚本,而不是使用登录脚本!
## Custom variables
$CompanyName = ‘YourCompany’
$InstallDir = "Path\Installer.msi"
## Set registry information for the local machine
$CompanyRegPath = "HKLM:\Software\"+$CompanyName
if (Test-Path $CompanyRegPath)
{}
else
{New-Item -path "HKLM:\Software\" -name $CompanyName}
if (Test-Path $CompanyRegPath'\Green Print')
{}
else
{New-Item -path $CompanyRegPath -name "Green Print"}
if ((Get-ItemProperty $CompanyRegPath'\Green Print').IsDeployed -eq $null)
{Set-ItemProperty $CompanyRegPath'\Green Print' -name IsDeployed -Value 0}
#Retrieve registry information
$IsDeployed = (Get-ItemProperty $CompanyRegPath'\Green Print').IsDeployed
if ($IsDeployed -ne 0)
{}
else
{
## Install the virtual printer software
Start-Process $InstallDir /qn -Wait
## Get the Printer object with WMI
$printer = Get-WmiObject -Query "Select * from Win32_Printer Where Name = 'GreenPrint'"
## Set the Printer object as default printer
$printer.SetDefaultPrinter()
#Update the IsDeployed in registry
Set-ItemProperty $CompanyRegPath’\Green Print’ -name IsDeployed -Value -1
}