|
-
February 15th, 2011, 05:56 AM
#1
Creating TCP/IP Port programatically
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
-
February 15th, 2011, 06:07 AM
#2
Re: Creating TCP/IP Port programatically
I have no idea what that code says but try right clicking your app and selecting 'Run as Administrator'.
-
February 15th, 2011, 07:40 AM
#3
Re: Creating TCP/IP Port programatically
Hi this is the 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);
}
-
February 15th, 2011, 08:32 AM
#4
Re: Creating TCP/IP Port programatically
According to MSDN article OpenPrinter Function:
If a user does not have permission to open a specified printer or print server with the desired access, the OpenPrinter call will fail with a return value of zero and GetLastError will return the value ERROR_ACCESS_DENIED.
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|