Question

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)?

Was it helpful?

Solution

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).

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top