2010-07-01 63 views
3

我已經編寫了一個適用於x86和x64 MS Windows系統的打印機驅動程序。我還寫了一個安裝程序,通過AddPrinterDriver和AddPrinter函數安裝打印機驅動程序。如何在Windows XP下以編程方式添加其他打印機驅動程序(x86/x64),2003,7,2008

到目前爲止,一切都很好。問題是,如果我想將此打印機從x64系統共享到x86系統,則x64打印服務器需要安裝用於x86系統的其他驅動程序。

現在我可以只安裝通過「打印機屬性」其他驅動程序 - >「共享」 - >「其他驅動程序」,並選擇適當的.inf文件,但我想通過我的安裝程序來做到這一點。

有人知道如何做到這一點嗎?

感謝您的幫助!

回答

2

所以我自己找到了解決方案。必須有一個更好更簡單的方法,但它的工作原理。

安裝驅動程序時,還要將正確的體系結構文件複製到其他體系結構中。 x86驅動程序到x86假脫機程序驅動程序目錄,x64到x64假脫機程序驅動程序目錄等。

然後在調用AddPrinterDriver和AddPrinter之前,必須爲每個其他需要支持的體系結構添加一些註冊表值。然後調用AddPrinterDriver和AddPrinter僅用於安裝驅動程序的操作系統的基礎架構。

註冊表值必須被添加到

系統\ CurrentControlSet \控制\打印\環境\ {TARGET_ENVIROMENT} \驅動\版-3 \ {NAME_OF_YOUR_DRIVER}

由此{TARGET_ENVIROMENT}是你想要支持的另一種環境,例如「Windows NT x86」; 「Windows x64」; 「Windows IA64」和{NAME_OF_YOUR_DRIVER}必須與您用於AddPrinterDriver的驅動程序名稱匹配。您必須添加的值是AddPrinterDriver將添加到您的系統環境中的值的副本。您可以在下面的代碼示例中詳細瞭解它們。在那之後只需要調用AddPrinterDriver並添加打印機的系統架構和額外的驅動程序也將出席。

在Win32中,你可以使用以下到x64系統上安裝用於x86和x64的驅動程序(這個例子,沒有錯誤檢查):

DWORD uSize; 
    BYTE driver_dir_x86[MAX_PATH]; 
    BYTE driver_dir_x64[MAX_PATH]; 

    GetPrinterDriverDirectory(NULL,"Windows NT x86",1,driver_dir_x86,MAX_PATH,&uSize); 
    GetPrinterDriverDirectory(NULL,"Windows x64",1,driver_dir_x64,MAX_PATH,&uSize); 


    CopyFile(".\x86\printer_driver.dll",driver_dir_x86); 
    CopyFile(".\x86\PRINTER.PPD",driver_dir_x86); 
    CopyFile(".\x86\PRINTERUI.DLL",driver_dir_x86); 
    CopyFile(".\x86\PRINTER.HLP",driver_dir_x86); 

    CopyFile(".\x64\printer_driver.dll",driver_dir_x64); 
    CopyFile(".\x86\PRINTER.PPD",driver_dir_x64); 
    CopyFile(".\x86\PRINTERUI.DLL",driver_dir_x64); 
    CopyFile(".\x86\PRINTER.HLP",driver_dir_x64); 

    //Insert x86 additional drivers to registry 
    RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Print\\Environments\\Windows NT x86\\Drivers\\Version-3\\", 0, KEY_ALL_ACCESS, &hkey); 
    RegCreateKey(hkey, "My_Printer_Drivername", &hsubkey);  { 
    RegSetValueEx(hsubkey, "Dependent Files", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "Previous Names", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "ColorProfiles", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "CoreDependencies", 0, REG_MULTI_SZ, (BYTE*)"", lstrlen("")+1); 
    DWORD Val = 3; 
    RegSetValueEx(hsubkey, "Version", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD)); 
    Val = 0; 
    RegSetValueEx(hsubkey, "TempDir", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD)); 
    Val = 2; 
    RegSetValueEx(hsubkey, "Attributes", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD)); 
    Val = 0; 
    RegSetValueEx(hsubkey, "PrinterDriverAttributes", 0, REG_DWORD, (BYTE*)&Val, sizeof(DWORD)); 
    RegSetValueEx(hsubkey, "Configuration File", 0, REG_SZ, (BYTE*)"PRINTERUI.DLL", lstrlen("PRINTERUI.DLL")+1); 
    RegSetValueEx(hsubkey, "Data File", 0, REG_SZ, (BYTE*)"PRINTER.PPD", lstrlen("PRINTER.PPD")+1); 
    RegSetValueEx(hsubkey, "Driver", 0, REG_SZ, (BYTE*)"printer_driver.dll", lstrlen("printer_driver.dll")+1); 
    RegSetValueEx(hsubkey, "Help File", 0, REG_SZ, (BYTE*)"PRINTER.HLP", lstrlen("PRINTER.HLP")+1); 
    RegSetValueEx(hsubkey, "Monitor", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "Datatype", 0, REG_SZ, (BYTE*)"RAW", lstrlen("RAW")+1); 
    RegSetValueEx(hsubkey, "Manufacturer", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "OEM URL", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "HardwareID", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "Provider", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "Print Processor", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "VendorSetup", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "InfPath", 0, REG_SZ, (BYTE*)"", lstrlen("")+1); 
    RegSetValueEx(hsubkey, "DriverDate", 0, REG_SZ, (BYTE*)"01/01/2010", lstrlen("01/01/2010")+1); 
    RegSetValueEx(hsubkey, "DriverVersion", 0, REG_SZ, (BYTE*)"1.0.0.0", lstrlen("1.0.0.0")+1); 
    RegSetValueEx(hsubkey, "MinInboxDriverVerDate", 0, REG_SZ, (BYTE*)"01/01/2010", lstrlen("01/01/2010")+1); 
    RegSetValueEx(hsubkey, "MinInboxDriverVerVersion", 0, REG_SZ, (BYTE*)"1.0.0.0", lstrlen("1.0.0.0")+1); 
    RegCloseKey(hsubkey); 
    RegCloseKey(hkey); 

    //Add x64 printer driver 
    DRIVER_INFO_3 di3; 
    ZeroMemory(&di3, sizeof(DRIVER_INFO_3)); 
    di3.cVersion = 0x03; 
    di3.pConfigFile = "PRINTERUI.DLL"; 
    di3.pDataFile = "PRINTER.PPD";  
    di3.pDependentFiles = ""; 
    di3.pDriverPath = "printer_driver.dll"; 
    di3.pEnvironment = "Windows x64"; 
    di3.pHelpFile = "PRINTER.HLP"; 
    di3.pMonitorName = NULL; 
    di3.pName = "My_Printer_Drivername"; 
    di3.pDefaultDataType = TEXT("RAW"); 
    AddPrinterDriver(NULL, 3, (LPBYTE)&di3); 
相關問題