Solved

a question about SendRequest Function of InternetSession class

Posted on 2003-11-05
9
200 Views
Last Modified: 2013-11-20
   I write a ATL Service program using VC 6.0, and some problems happened are very strange.
    This program connect a website page in Internet. by post method using the SendRequest function of InternetSession class. All the connecting codes are writed in a function called "SendOrder" in a dll file, and the Service program use the function of this dll. The "SendOrder" will be run every  time pre minute in the service program. The operation system is WIn2000 professional. My computer connect Internet through the WinGate proxy Server in another computer.
   When I run this service program from the WIndows Service Manager, The first three time connections are successful, but from the fouth connection, the "SendOrder" function will be broken and every code after the SendRequest will no longer run. I don't know what cause this program?
  But if I run the Service program  directly by clicking the exe file, all the connections will ok.
  who can help me?
0
Comment
Question by:Iaskyou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692596
Are u calling Close() after each session (pHTTPFile->Close()) ?
Rosh :)
0
 

Author Comment

by:Iaskyou
ID: 9692982
yes, I have close the session.
In addition, I correct some errors in my words.
The first three time connections are failed, but I get catch exception from the SendRequest calling. However,   from the fouth connection, it seems that the SendRequest return nothing everycode after SendRequest does not run before the "SendOrder" function of dll is finished.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9693094
Can u show some code
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Iaskyou
ID: 9698457
I know the reason. When I run the service program from the Service Manager, The authority of user is "LocalSystem". But when I run the service exe file directly, the authority of user is the login administrator. So when the service is run from Service Manager, the SendRequest method failed. But How can I set the authority of the service program by code?
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 150 total points
ID: 9699193
You can check the admin previlege like this

#define BUFF_SIZE   1024
BOOL IsAdmin()
{
    HANDLE          hToken = NULL;
    PSID            pAdminSid = NULL;
    BYTE            buffer[BUFF_SIZE];
    PTOKEN_GROUPS   pGroups = (PTOKEN_GROUPS)buffer;
    DWORD           dwSize;             // buffer size
    DWORD           i;
    BOOL            bSuccess;
    SID_IDENTIFIER_AUTHORITY siaNtAuth = SECURITY_NT_AUTHORITY;

    // get token handle
    if ( !OpenProcessToken ( GetCurrentProcess ( ), TOKEN_QUERY, &hToken ) )
        return false;
   
    bSuccess = GetTokenInformation ( hToken, TokenGroups,
                                    (LPVOID)pGroups, BUFF_SIZE,
                                    &dwSize );
    CloseHandle ( hToken );
    if ( !bSuccess )
        return false;
    if ( !AllocateAndInitializeSid ( &siaNtAuth, 2,
                                     SECURITY_BUILTIN_DOMAIN_RID,
                                     DOMAIN_ALIAS_RID_ADMINS,
                                     0,0,0,0,0,0, &pAdminSid ) )
        return false;

    bSuccess = FALSE;
    for ( i = 0; (i < pGroups->GroupCount) && !bSuccess; i++ )
    {
        if ( EqualSid ( pAdminSid, pGroups->Groups[i].Sid ) )
            bSuccess = TRUE;
    }
    FreeSid ( pAdminSid );
   
    return bSuccess;
}
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9699208
"HOWTO: Program a Secure Server on Microsoft Windows NT" please check this on MSDN.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question