Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

a question about SendRequest Function of InternetSession class

Posted on 2003-11-05
9
Medium Priority
?
203 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
Technology Partners: 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 600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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