Link to home
Start Free TrialLog in
Avatar of Viney Kumar
Viney Kumar

asked on

UrlDownloadToFile returns INET_E_RESOURCE_NOT_FOUND under SYSTEM account and when behind a proxy

Hi experts,

I have a very simple looking C++ code that uses URLDownloadToFile and fails when run from behind proxy and under SYSTEM account. It works fine if I either use direct connection or run under a user account. I am making following call:

URLDownloadToFile(NULL, wszURL, wszFullpath, 0, NULL);

I have a service that runs under SYSTEM credentials. This service launches a program, say, DownloadMyFile.exe that downloads a file using above call. This download works.

Then I connect my machine to proxy and specify the proxy thru IE options. After this URLDownloadToFile starts giving INET_E_RESOURCE_NOT_FOUND  (-2146697211) error.

Now when I double click on DownloadMyFile.exe, which makes it run under user credentials, it successfully works, even from behind proxy.

I tried this on Vista/Win7/XP and found same behavior.

Any clues?

Thanks!
Avatar of Viney Kumar
Viney Kumar

ASKER

Guys,

This is a very critical requirement for me. I will highly appreciate early replies.

Thanks,
Viney
Avatar of jkr
our problem is that services running under the 'LocalSystem' account have almost OS privileges, but are not allowed to use _any_ networking facilities. To overcome this, make sure to assign your service to run under a predefined user account (preferrably one belonging to the admin group) which does have network access (this is usually done by specifying an account name&password in the call to 'CreateService()', but you're also able to change this from the 'services' control panel applet).
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jkr is right and allready posted solutions about that...
I had the same problem but didn't solved it because I wanted the application - service - to be with no memory leaks...
By the time I solved the leak problem I didn't had a need for the service application...

George Tokas.
I tried following and had limited success.
-      Find PID of explorer.exe
-      Get token of logged-in user by calling OpenProcessToken() using above PID
-      Lauch copy of MyDownloadApp.exe calling CreateProcessAsUser() and using logged-on users token.
-      Now MyDownloadApp.exe runs under user credential and can successfully download

This solution is working on XP. But on Win7 it gives error INET_E_SECURITY_PROBLEM (0x800C000EL or -2146697202).

Before I get completely diverted, I will find out more on what DanRollins has suggested.
Have you tried running the service under a different account also?
Guys, finally I could solve my problem. My earlier post was almost the solution. One additional step that I took is that I tried downloading from a secure site. I changed the URL that was having a valid Verisign cert. That removed  INET_E_SECURITY_PROBLEM (0x800C000EL or -2146697202).
I think that DanRollins has given a valid answer....

George Tokas.
The solution given was an excellent lead to the right final solution. I needed to dig out more info. I could find out the final solution and posted here.