1

My WindowsForms application needs to access the Internet, but when I try to open a WebRequest the application crashes. I noticed when I run the application from a simple folder (My Documents for example) it works, but if I run from "Program Files" folder it doesn't. I know that the problem resides in the UAC permissions, but I don't understand why I cannot open a WebRequest in a application running from "Program Files".

There is any way to open a WebResquest from "Program Files" without the UAC permission elevation (using the manifest)?

2 Answers 2

1

Are you trying to save anything to the local folder where the app is running?

If your app is running from a folder under Program Files and you try to write to the directory where it is located, that might fail. The Program Files folder is one of the places UAC is required in order to write (I think).

2
  • A little late but that was the problem :) Jun 18, 2012 at 20:44
  • Oops... didn't even notice. Sorry!
    – Rich
    Jun 18, 2012 at 20:50
1

Tested with a simple commandline application and it seems to work properly. It was running from inside "Program Files", UAC was active, and I'm running Vista SP2.

WebRequest req = WebRequest.Create("http://www.google.com");
using(WebResponse resp = req.GetResponse())
{
    using(Stream str = resp.GetResponseStream())
    {
        using(StreamReader sr = new StreamReader(str))
        {
            string data = sr.ReadToEnd();
            Console.WriteLine("SUCCESS: " + data.Length + "bytes downloaded");
            Console.WriteLine("SAMPLE: " + data.Substring(0,100));
        }
    }
}

Can you give more details of the problem? Maybe post some source code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.