Solved

a question about SendRequest Function of InternetSession class

Posted on 2003-11-05
9
196 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 37
sumDigits challenge 9 123
either24  challenge 19 90
Bartender label printing - switch on and off graphics 3 10
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now