I want to launch an EXE after completing the installation, so I wrote a custom launch condition like below:
[RunInstaller(true)]
public class InstallerClass : System.Configuration.Install.Installer
{
public InstallerClass() : base()
{
this.AfterInstall += new InstallEventHandler(InstallerClass_AfterInstall);
}
void InstallerClass_AfterInstall(object sender, InstallEvent开发者_开发技巧Args e)
{
Directory.SetCurrentDirectory(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
ProcessStartInfo psi = new ProcessStartInfo(
Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) + "\\MyApp.exe");
psi.WorkingDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
psi.Verb = "runas";
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
.
.
. }
Issue: MyApp.exe is creating http request to get some data from server. I get Timeout exception every time if MyApp.exe get Launch from here. If I run MyApp.exe separately, it successfully creates http request without timeout. Below is the code for http request:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Timeout = TimeOut;
request.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = WebRequest.DefaultWebProxy;
request.UseDefaultCredentials = true;
request.AllowAutoRedirect = true;
request.KeepAlive = false;
request.Method = "HEAD";
request.SendChunked = true;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
returnValue = response.StatusCode;
}
Why am I getting timeout exception? Where am I doing wrong?
When an installer runs it runs with special permissions/rights...
Perhaps you could log what the values of request.Credentials = CredentialCache.DefaultCredentials;
and request.Proxy = WebRequest.DefaultWebProxy;
are when running successfully versus the timeout case
精彩评论