2

I have a visual studio installer project which installs a C# app, I have a custom action and code to run the process after install is complete.

Let's say the logged in user on windows machine is "john". Now when john runs the msi installer, I check the process in the taskmanager and it shows that msiexec.exe is the process name for installer and it is running as user "john"

The installer completes and runs the install app's process myapp.exe now when I check this process in taskmanager of windows it shows that myapp.exe is running as SYSTEM (which I do know what account is that and why its not running as john)

Problem When myapp.exe runs as SYSTEM user it can not create com component instance of a component (iTunes in my case) which was already running as user john. If the component was not running then creating isntance of the iTunes is sucessful, otherwise it fails.

Question So is it possible to make sure when installer runs as john, when it finishes it starts process myapp.exe as john and not as SYSTEM user ? Note that I do not asks user for password during installer.

Code that I run when installer completes

    // Event handler for 'Committed' event.
    private void MyInstaller_Committed(object sender, InstallEventArgs e)
    {
        try
        {                
            Directory.SetCurrentDirectory(Path.GetDirectoryName
            (Assembly.GetExecutingAssembly().Location));
            Process.Start(Path.GetDirectoryName(
              Assembly.GetExecutingAssembly().Location) + "\\MyApp.exe");
        }
        catch
        {
            // Do nothing... 
        }
    }
4

3 回答 3

3

这很可能发生,因为您正在延迟运行自定义操作。即它默认在SYSTEM用户帐户下运行。

一种解决方案是确保立即启动它,例如,您可以使用安装最后一个对话框中的“完成”按钮上的已发布事件来启动它。我不确切知道如何在 VS 设置项目中添加已发布的事件,或者是否可能,但您可以轻松地在使用专门的设置创作工具构建的包中添加一个。

于 2012-12-04T07:29:22.993 回答
0

在 Form_Load 事件中这样写:

字符串 lUserName=Environment.GetEnvironmentVariable("USERNAME");

然后,您将在安装 MSI 时获得 Windows 登录用户名,而不是获取系统用户帐户。

于 2013-06-06T10:03:01.220 回答
-1

就我个人而言,我确实设法通过使用explorer.exe我的应用程序可执行文件的路径运行参数化来解决这个问题:

Process.Start(
    new ProcessStartInfo
    {
        FileName = "explorer.exe",
        Arguments = Context.Parameters["target"],
        UseShellExecute = true
    });
于 2016-06-19T22:44:22.410 回答