Thread: [win32] CreateFile(_T{"LPT2"),.. works in user mode but fails in Admin mode

  1. #1
    Registered User
    Join Date
    Jul 2014

    [win32] CreateFile(_T{"LPT2"),.. works in user mode but fails in Admin mode

    The code below works correctly when executed in "user" mode (Compatibility Mode Windows XP SP2 ) and returns a handle to LPT2


    The identical code fails when given Admin privileges and returns invalid handle and error code 2 (file does not exist),

    Does anyone have an idea why this happens?

  2. #2
    Registered User
    Join Date
    Jul 2014
    I should have added that LPT2 is mapped to a network shared generic text/only printer via NET USE LPT2 \\servername\sharedname /user:adminname adminpassword where "servername" is another win7 pro workstation sharedname is the printer's sharename and adminname and adminpassword are the credentials for the administrative user on servername. The net use command is issued from an administrative command prompt.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    See the last comment here -> CreateFile function | DaniWeb

    Another thread with some diagnostic ideas to try -> Parallel port communication - C++ Forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mean median mode ungrouped data "help!!"
    By jannmichael7 in forum C++ Programming
    Replies: 4
    Last Post: 12-20-2011, 06:33 AM
  2. load user-mode dll into kernel-mode "process"
    By Yarin in forum Windows Programming
    Replies: 10
    Last Post: 12-12-2008, 04:56 PM
  3. User mode and Kernel mode
    By learner01 in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2006, 02:38 PM
  4. User-mode and Kernel-mode
    By Eibro in forum Tech Board
    Replies: 1
    Last Post: 06-30-2003, 09:27 PM
  5. Code to calculate "mode"
    By NCCMelissa in forum C Programming
    Replies: 5
    Last Post: 03-19-2002, 02:02 PM

Tags for this Thread