Solved

a question about SendRequest Function of InternetSession class

Posted on 2003-11-05
9
195 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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 …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

16 Experts available now in Live!

Get 1:1 Help Now