views:

125

answers:

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

+1  A: 

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?

Badaro