Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating TCP/IP Port programatically [modified]

Creating TCP/IP Port programatically [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminwindows-adminjson
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msr_codeproject
    wrote on last edited by
    #1

    Hi I am trying to create a TCP/IP port programatically in win32. Here is my code.

    HANDLE hXcv;
    PRINTER_DEFAULTS pd = {NULL, NULL, SERVER_ACCESS_ADMINISTER};
    TCHAR szBuf[MAX_PATH] ={0};

    TCHAR szMsg[512];
    DWORD dwLastError;

    ::lstrcpy(szBuf, TEXT(",XcvMonitor Standard TCP/IP Port"));

    if(OpenPrinter(szBuf, &hXcv, &pd) != FALSE )
    {
    OutputDebugString(TEXT("Hello. It worked....!"));
    }
    else
    {
    dwLastError = GetLastError();
    wsprintf(szMsg, TEXT("OpenPrinter return error:%d\n"), dwLastError);
    OutputDebugString(szMsg);
    }

    > But the problem is OpenPrinter API failing and returning error code as 5 (ERROR_ACCESS_DENIED). > But when I try to create the port manually (print properties), port is created. > I have logged in as an administrator and I have all permissions. I am working on Windows Server 2008 R2 Statndard (64 bit OS) Note: OpenPrinter API working fine if I turn-OFF User Account Settings (UAC). Failing if UAC is ON Please tell me what's wrong with my code. Thank you in advance. Regards msr

    modified on Monday, February 14, 2011 6:29 AM

    S 1 Reply Last reply
    0
    • M msr_codeproject

      Hi I am trying to create a TCP/IP port programatically in win32. Here is my code.

      HANDLE hXcv;
      PRINTER_DEFAULTS pd = {NULL, NULL, SERVER_ACCESS_ADMINISTER};
      TCHAR szBuf[MAX_PATH] ={0};

      TCHAR szMsg[512];
      DWORD dwLastError;

      ::lstrcpy(szBuf, TEXT(",XcvMonitor Standard TCP/IP Port"));

      if(OpenPrinter(szBuf, &hXcv, &pd) != FALSE )
      {
      OutputDebugString(TEXT("Hello. It worked....!"));
      }
      else
      {
      dwLastError = GetLastError();
      wsprintf(szMsg, TEXT("OpenPrinter return error:%d\n"), dwLastError);
      OutputDebugString(szMsg);
      }

      > But the problem is OpenPrinter API failing and returning error code as 5 (ERROR_ACCESS_DENIED). > But when I try to create the port manually (print properties), port is created. > I have logged in as an administrator and I have all permissions. I am working on Windows Server 2008 R2 Statndard (64 bit OS) Note: OpenPrinter API working fine if I turn-OFF User Account Settings (UAC). Failing if UAC is ON Please tell me what's wrong with my code. Thank you in advance. Regards msr

      modified on Monday, February 14, 2011 6:29 AM

      S Offline
      S Offline
      ShilpiP
      wrote on last edited by
      #2

      There is nothing wrong in your code and also do not turn off UAC. Try to execute you application in admin privileges. select RequireAdminstration as a property. For future reference: Google this keyword "Windows7GATrainingKitForDevelopers.Setup.exe" and run this exe. Its a training kit for developer working on Windows 7. It is awesome.

      I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

      M 1 Reply Last reply
      0
      • S ShilpiP

        There is nothing wrong in your code and also do not turn off UAC. Try to execute you application in admin privileges. select RequireAdminstration as a property. For future reference: Google this keyword "Windows7GATrainingKitForDevelopers.Setup.exe" and run this exe. Its a training kit for developer working on Windows 7. It is awesome.

        I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

        M Offline
        M Offline
        msr_codeproject
        wrote on last edited by
        #3

        Hi, "select RequireAdminstration as a property" I have not understood the above statement. Cab you just explain me how to do this? Regards msr

        S 1 Reply Last reply
        0
        • M msr_codeproject

          Hi, "select RequireAdminstration as a property" I have not understood the above statement. Cab you just explain me how to do this? Regards msr

          S Offline
          S Offline
          ShilpiP
          wrote on last edited by
          #4
          1. Open Project property page Project->Property or use shortcut key (Alt + f7). 2) Select Linker->Manifest File, There is one property UAC Execution level. select this option as requireAdminstration. When you do this than your application is self elevated and run under admin privilege.

          I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

          M 1 Reply Last reply
          0
          • S ShilpiP
            1. Open Project property page Project->Property or use shortcut key (Alt + f7). 2) Select Linker->Manifest File, There is one property UAC Execution level. select this option as requireAdminstration. When you do this than your application is self elevated and run under admin privilege.

            I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

            M Offline
            M Offline
            msr_codeproject
            wrote on last edited by
            #5

            Hi, thanks for the reply. But in vs2008 there is no such option (Linker -> Manifest fie)for vc++ win32 projects. Regards msr

            S 1 Reply Last reply
            0
            • M msr_codeproject

              Hi, thanks for the reply. But in vs2008 there is no such option (Linker -> Manifest fie)for vc++ win32 projects. Regards msr

              S Offline
              S Offline
              ShilpiP
              wrote on last edited by
              #6

              No I am able to view this property on VS2008 with win32. What are you doing ?? Please explain....

              I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

              M 1 Reply Last reply
              0
              • S ShilpiP

                No I am able to view this property on VS2008 with win32. What are you doing ?? Please explain....

                I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)

                M Offline
                M Offline
                msr_codeproject
                wrote on last edited by
                #7

                But I am building a static library. I think Linker option is not applicable. Regards msr

                modified on Wednesday, February 16, 2011 11:15 PM

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups