I’m working on some application which has auto-update function. The implemented idea is simple as following:
– There are some “starter” application which is installed to “Program Files/whatever/…”. It’s the application which is intended to be started by user.
– Each time the “starter” application is executed it checks server for updates and downloads it to “%APPDATA%/some/…”. And then it starts some application from that folder.
Above approach is working on my development machine (running Vista) and on some other machines under XP, but under some different machine (running Windows 7) it isn’t working. When “starter” executes the real application it crashes with some unknown problem (Signature = System.UnauthorizedAccess). When real application is executed manually from %APPDATA%/some/ folder then everything is working fine. I’ve tried to set same working directory in ProcessStartInfo, so “starter” will also execute real application in that folder, but this isn’t helped me.
How can I diagnose and/or fix that issue?
Update
More details on how I’m running main process from starter:
private static readonly string _ROOT = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyApp");
...
private static void Run()
{
string startPath = Path.Combine(_ROOT, "MyApp.exe");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = startPath;
startInfo.WorkingDirectory = _ROOT;
Process.Start(startPath);
}
This surely starts the correct process because application window can be seen, but some disk or network operation is probably denied by Windows and started process is crashed.
Update
The tracing shown that working directory wasn’t correct and that pointed to incorrect Process.Start(string) method call in my code. The correct line:
Process.Start(startInfo);
As to your problem, I give odds that the crash is either from a missing resource or dependency or its a permissions issue. Have you tried running the app using administrator permissions? Generally, every version of Windows since Xp got more and more restricted and this is especially true of the .net runtime. Are you dependent on third party libraries or DLLs?
As to diagnosing the problem, assuming you don’t have access to a debugger on the remote machine, your best bet is ample use of System.Diagnostics.Trace. You can make the tracing configurable from your app.config and have the trace redirect to a local file easy enough. Also make sure to check the Event Viewer for any application level exceptions.
With time, and enough trace statements, you should find the problem quickly enough.
Enabling Tracing is as easy as adding the following to your app.config.
Then throughout your code add: