我目前工作的一個Autoupdater爲我的應用程序啓動時。 (使用安裝程序,更新和刪除工具的組合),我想設置C#:Directory.getCurrentDirectory()從瀏覽器
所有的東西自動:用C
- 開始菜單項
- 文件夾:\ Program Files文件\
- 配置文件夾(取決於漫遊/本地)
- 「程序&功能」中的軟件刪除條目
- 桌面快捷方式。
這工作都很好。爲了寫入程序文件和註冊表,該工具需要管理員權限。所以我在選擇了所需的軟件之後添加了AppLauncher的「重新啓動」。 只是這樣的事情:
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();
}
而且這一步工作得非常好,如果的某處的用戶節省了AppLauncher.exe在一個文件夾,雙擊啓動它點擊它。
如果用戶決定從瀏覽器中點擊「運行」,安裝程序運行到顯示異常,宣稱「AppLauncher.exe」找不到。我假設,即直接從瀏覽器將設置不同的WorkingDirectory啓動文件,因此
Directory.GetCurrentDirectory()
不會返回適當的值,該文件的位置。 如果用戶決定給文件另一個名字,它也可能不起作用。
那麼,我該怎麼辦這個?
有什麼樣File.GetCurrentFile():P
請參閱:http://stackoverflow.com/questions/218061/get-the-applications-path –