title: addmonitor win32 call fails with lasterror 5
body: <p>I have created a very small win32 console application (AddPrintMonitor.exe) that does nothing more than makes a call to AddMonitor.  Here is a small snippet:</p>
  
  <pre><code>MONITOR_INFO_2 m_MonitorInfo2;
  m_MonitorInfo2.pName = lpMonitorName;
  TCHAR env[12] = TEXT("Windows x64");
  m_MonitorInfo2.pEnvironment = env;
  m_MonitorInfo2.pDLLName     = lpDllName;
  
  
  if ( !AddMonitor(NULL, 2, (LPBYTE) &amp;m_MonitorInfo2) )
  {
      DWORD error = GetLastError();
      std::cout &lt;&lt; "Last error = " &lt;&lt; error &lt;&lt; "\n";
      return PRINTER_ERR_API;
  }
  </code></pre>
  
  <p>When I run this as a member of the Administrators group is fails.  GetLastError() returns 5.  When I run it as "The Administrator" it succeeds with no issues.  I am running on Windows 7 x64.  I am trying to install the redmonnt.dll and I do have the 64 bit version of that dll.  This task is part of a larger install for a PostScript driver.  I've only isolated out the AddMonitor portion to eliminate other external issues.</p>
  
  <p>Error 5 is an access violation or security issue.  My first question is why can't a member of the administrators group carry out this function call?  What's the difference between the actual administrator and a member of the administrators group given this context?</p>
  
  <p>Other details to note.  I am using InstallShield 12 (old) for my Printer installation (addmonitor is only part).  I am adding a monitor, port, driver and printer all through win32 function calls.   Prior to running my AddPrinterMonitor.exe I made sure that the redmonnt.dll does exist in the system32 directory.  Actually, whether the dll is present there or not makes no difference for the error I see.  I did see posts about setting SeLoadDriverPrivilege.  This is a dead end for me as I checked and the administrators group can Load/Unload device drivers.</p>
  
  <p>Also, I am using win32 calls to get this done.  This worked (I mean all of it worked) without any problems on Win2K, WinXP and Windows Server 2003.  With the newer OS's like Windows 7 there are several difficulties.  Is there a better way that I've overlooked?  I been very frustrated trying to get this to work, so I've begun to question the approach for Vista and higher.</p>
  
  <p>More initialization code:</p>
  
  <pre><code>#define MONITOR_NAME            "My Redirected Port"
  #define MONITOR_FILE            "redmonnt.dll"
  </code></pre>
  
  <p>MONITOR_NAME is passed to lpMonitorName and MONITOR_FILE is passed to lpDllName</p>
  
  <p>thanks</p>