Bug 688361

Summary: Fail to find printers when sDevice is mswinpr2 and user is not logged on.
Product: Ghostscript Reporter: Bruno Schneidhuber <b.schneidhuber>
Component: Other DriverAssignee: Henry Stiles <henry.stiles>
Status: RESOLVED WONTFIX    
Severity: minor CC: gsview
Priority: P3    
Version: 8.15   
Hardware: PC   
OS: Windows 2000   
Customer: Word Size: ---

Description Bruno Schneidhuber 2005-11-02 07:48:41 UTC
- OS: Windows 2000
- User <a> is logged on
- gswin32c.exe is run within the account of user <b>
- sDEVICE is mswinpr2
- sOutputFile ist "\\spool\<any printer>"

When you run gswin32c.exe the Printer-Dialog pops up as if <any printer> would
not exist.

An example when the above scenario happens is, when you use redmon to install a
PS-redirect-printer and share this printer.

- OS: Windows 2000
- User <a> is logged on
- Redmon configuration for <redirect-printer>:
  - Program: <path>\gswin32c.exe
  - Argument: -sDEVICE=mswinpr2 -sOutputFile="\\spool\<printer>" -dBATCH
-sPAPERSIZE=a4 -dNOPAUSE -dNoCancel -q -c quit
  - Output: Program handles output
  - Run Hidden
- e.g. samba-command: smbclient \\\\<computer>\\<redirect-printer>
-U<b>%<passwd> -P -c "print <path>/test.ps"


Proposed solution, that works for me in:
/*  $Id: gdevwpr2.c,v 1.15.2.1 2004/08/27 21:36:36 dan Exp $ */

In the function win_pr2_getdc "GetProfileString("Devices", NULL, "", devices,
4096)" is used to obtain the installed printers. Within the above scenario no
printers are returned and therefore a variable "p" ist set to the empty string,
which causes that p ist set to NULL in line 908.

My solution is (from line 907):

    if (*p == '\0') {
       OSVERSIONINFO OSVersion;
       OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

       if (GetVersionEx(&OSVersion)) {
         if (OSVersion.dwMajorVersion == 5) { /* tested only for win2k and winxp */
           char aKeyBuf[1024];
           HKEY    hk;
           DWORD   dwDisp;
           sprintf(aKeyBuf,"SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\Print\\Printers\\%s",device);
           if (!RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                               aKeyBuf,
                               0,
                               NULL,
                               REG_OPTION_NON_VOLATILE,
                               KEY_READ,
                               NULL,
                               &hk,
                               &dwDisp)) {
             p = device;
             RegCloseKey(hk);
           }
         }
       }
       if(*p == '\0') {
         p = NULL;
       }
    }