W
Wendell W. Pinegar
One of our older apps that uses the Crystal Report 8.5 runtime wasn't working properly when running on a Windows Server 2016 RDP server. The app crashed every time we tried to print something from one of the built-in reports. In troubleshooting this issue we discovered that the default printer has always been stored in the registry key "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device". This has been the location of the default printer in the registry in absolutely forever and this registry key is set correctly in Windows Server 2008 R2 and Server 2012 R2.
We found that this registry setting isn't being set if the default printer is an auto-created session printer. However, if we select any of the locally attached printers on the server such as the "Microsoft Print to PDF" or "Microsoft XPS Document Writer" the registry key does get set properly. Once this registry key is created and set properly the Crystal Report 8.5 runtime works perfectly and the app prints just fine.
The inconsistent behavior of Server 2016 shows that this is definitely a bug.
To temporarily resolve this issue we've written a Powershell script to sets this registry key based on the current default printer when the user signs on and we launch the Powershell script as part of the app's startup.
# Clear any existing errors.
#
"Waiting for printers to be created"
#Start-Sleep 5
$error.clear()
$registrykey = "Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"
# Set the location
#
Set-Location -Path $registrykey -ErrorAction SilentlyContinue
# Retrieve the default printer properties.
#
$wmiDefaultPrinter = Get-WmiObject -query "SELECT * FROM WIN32_PRINTER WHERE Default = TRUE"
# If the default printer exists then set the registry values.
#
if ($wmiDefaultPrinter -ne $null)
{
"Setting the Windows default printer registry key"
Set-ItemProperty -Path $registrykey -Name "Device" -Value ($wmiDefaultPrinter.Name+",winspool,Ne00:")
Write-Host "Your default printer is" $wmiDefaultPrinter.Name
} else {
Set-ItemProperty -Path $registrykey -Name "Device" -Value "Microsoft Print to PDF,winspool,Ne01:"
}
Wendell W. Pinegar
Continue reading...
We found that this registry setting isn't being set if the default printer is an auto-created session printer. However, if we select any of the locally attached printers on the server such as the "Microsoft Print to PDF" or "Microsoft XPS Document Writer" the registry key does get set properly. Once this registry key is created and set properly the Crystal Report 8.5 runtime works perfectly and the app prints just fine.
The inconsistent behavior of Server 2016 shows that this is definitely a bug.
To temporarily resolve this issue we've written a Powershell script to sets this registry key based on the current default printer when the user signs on and we launch the Powershell script as part of the app's startup.
# Clear any existing errors.
#
"Waiting for printers to be created"
#Start-Sleep 5
$error.clear()
$registrykey = "Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"
# Set the location
#
Set-Location -Path $registrykey -ErrorAction SilentlyContinue
# Retrieve the default printer properties.
#
$wmiDefaultPrinter = Get-WmiObject -query "SELECT * FROM WIN32_PRINTER WHERE Default = TRUE"
# If the default printer exists then set the registry values.
#
if ($wmiDefaultPrinter -ne $null)
{
"Setting the Windows default printer registry key"
Set-ItemProperty -Path $registrykey -Name "Device" -Value ($wmiDefaultPrinter.Name+",winspool,Ne00:")
Write-Host "Your default printer is" $wmiDefaultPrinter.Name
} else {
Set-ItemProperty -Path $registrykey -Name "Device" -Value "Microsoft Print to PDF,winspool,Ne01:"
}
Wendell W. Pinegar
Continue reading...