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

This is a discussion on [win32] CreateFile(_T{"LPT2"),.. works in user mode but fails in Admin mode within the Windows Programming forums, part of the Platform Specific Boards category; The code below works correctly when executed in "user" mode (Compatibility Mode Windows XP SP2 ) and returns a handle ...

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    2

    [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


    lpPrinter->hPort = CreateFile(_T("LPT2",GENERIC_WRITE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ, 0, CREATE_ALWAYS,0,0);


    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
    Posts
    2
    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
    Location
    The edge of the known universe
    Posts
    33,116
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05:33 AM
  2. load user-mode dll into kernel-mode "process"
    By Yarin in forum Windows Programming
    Replies: 10
    Last Post: 12-12-2008, 03: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, 01:02 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21