Dear Catalin,
I appreciate your prompt response. I'm reaching out regarding the PowerShell script I've been working on to add a virtual printer driver. Despite my efforts, it seems that the script isn't functioning as expected.
Code: Select all
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32Helper {
[DllImport("winspool.drv", EntryPoint="AddPrinterDriverA", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint AddPrinterDriver(string pName, uint Level, ref TDriverInfo3 pDriverInfo);
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TDriverInfo3 {
public uint cVersion;
[MarshalAs(UnmanagedType.LPWStr)]
public string pName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pEnvironment;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDriverPath;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDataFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pConfigFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pHelpFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDependentFiles;
[MarshalAs(UnmanagedType.LPWStr)]
public string pMonitorName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDefaultDataType;
}
"@
# Appel des fonctions pour installer une imprimante
$driverName = "MyDriver"
# Appel de la fonction SetDefaultPrinter pour définir l'imprimante par défaut
[System.UInt32] $result1 = 0
#[Win32Helper]::SetDefaultPrinter($printerName)
# Définition des structures pour le moniteur, le pilote et l'imprimante
$driverInfo = New-Object TDriverInfo3
$driverInfo.cVersion = 3
$driverInfo.pName = $driverName
$driverInfo.pEnvironment = "Windows x64"
$driverInfo.pDriverPath = "PSCRIPT5.DLL"
$driverInfo.pDataFile = "ADIST5.PPD"
$driverInfo.pConfigFile = "PS5UI.DLL"
$driverInfo.pHelpFile = "PSCRIPT.HLP"
$driverInfo.pDependentFiles = "PSCRIPT.NTF"
$driverInfo.pMonitorName = "MyMonitor"
$driverInfo.pDefaultDataType = "RAW"
[System.UInt32] $result3 = [Win32Helper]::AddPrinterDriver($driverName, 3, [ref] $driverInfo)
if ($result3 -eq 0 ) {
Write-Host "L'imprimante a été installée avec succès."
} else {
Write-Host "Erreur lors de l'installation de l'imprimante."
}
Unfortunately, I'm not receiving any error messages during script execution, which makes troubleshooting a bit challenging. After running the script, I checked the registry, but I couldn't find any indication that the driver was successfully installed. This is quite perplexing, especially considering that a similar process using Inno Setup has been successful in the past.
Do you have any insights or suggestions on how I can debug this issue further? I've double-checked to ensure that the script is being executed with administrative privileges, but I'm still unable to identify the root cause of the problem.
Thank you once again for your assistance and support.
Best regards,
zchaibi