I'm currently working on an Autoupdater for my Applications. (combined with an installer, updater and removal tool)
I'd like to setup all the Stuff automatically:
- Startmenu Entry
- Folder in C:\Program Files\
- Config Folder in App Data (depending on Roaming / local)
- Software Removal-Entry in "Programs & Features"
- Desktop Shortcut.
This works all very well. For writing to Program Files and the registry the tool needs Administrator privilegs ofc. So I added a "restart" of the AppLauncher, after the desired software has been picked. Just something like this:
ProcessStartInfo pi = new ProcessStartInfo(Directory.GetCurrentDirectory() + @"\AppLauncher.exe");
pi.Verb = "runas";
pi.Arguments = "install " + this.appItem.APID;
Process p = new Process();
p.StartInfo = pi;
try
{
p.Start();
Application application = Application.Current;
application.Shutdown();
}
catch (Exception ex)
{
MessageBox.Show("Unable to install the application.\n\n" + ex.ToString(), "Error",
application.Shutdown();
}
Also this step works very well, if the User saves the AppLauncher.exe somewhere in a Folder and starts it by double clicking it.
If a User decides to hit "run" from the Browser, The installer runs into the shown exception, saying "AppLauncher.exe" not found. I Assume, that starting the File right from the browser will setup a different WorkingDirectory and therefore
Directory.GetCurrentDirectory()
will not return the appropriate value, where the file is located. It may also NOT work, if the user decides to give the file another name.
So, what can I do on this?
Is there something like File.GetCurrentFile() :P