如何确保安装我的 msi 时 devenv.exe 没有运行

发布于 2024-07-16 18:12:25 字数 288 浏览 5 评论 0原文

我正在为 Visual Studio 2008 编写 VSPackage,并使用 WiX 生成的 Msi 来部署它。 安装结束时,我根据需要运行“devenv.exe /setup”以使 VS 注意到我的包。 但是,如果有任何 Visual Studio 副本正在运行,此命令将不会成功。

目前,我告诉人们在安装之前必须关闭 Visual Studio 的所有副本,但我希望它万无一失。 当有人运行我的 .msi 时,如何检查是否有任何 Visual Studio (devenv.exe) 副本正在运行,并阻止他们安装我的项目?

I am writing a VSPackage for Visual Studio 2008, and am deploying it with a WiX generated Msi. As the end of the install, I am running "devenv.exe /setup" as required to get VS to notice my package. However, this command will not succeed if there are any copies of Visual Studio running.

Currently, I tell people they have to close all copies of Visual Studio before installing, but I would prefer it be foolproof. How can I check when someone runs my .msi if any copies of Visual Studio (devenv.exe) are running, and block them from installing my project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

め七分饶幸 2024-07-23 18:12:25
while(devenvIsRunning()) {} //in main routine of Installer class

static bool devenvIsRunning() //uses this subroutine
        {
            Process[] procList = Process.GetProcesses();
            foreach (Process p in procList)
            {
                if (p.ProcessName == "devenv")
                {
                    MessageBox.Show("An instance of Visual Studio is still running.\nPlease close all open instances of Visual Studio before continuing.");
                    return true;
                }
            }
            return false;
        }
while(devenvIsRunning()) {} //in main routine of Installer class

static bool devenvIsRunning() //uses this subroutine
        {
            Process[] procList = Process.GetProcesses();
            foreach (Process p in procList)
            {
                if (p.ProcessName == "devenv")
                {
                    MessageBox.Show("An instance of Visual Studio is still running.\nPlease close all open instances of Visual Studio before continuing.");
                    return true;
                }
            }
            return false;
        }
青芜 2024-07-23 18:12:25

WiX 工具集有一个 CloseApps CustomAction,可以为您关闭窗口。 不幸的是,它不会提示关闭所有应用程序的列表,但代码将是一个合理的起点。

The WiX toolset has a CloseApps CustomAction that will close windows for you. It unfortuantely does not prompt with a list to close all the applications but the code would be a reasonable place to start.

吹梦到西洲 2024-07-23 18:12:25

您最好的选择是遵循 Rob 的建议并组合自定义操作来检查进程是否正在运行。 我可能会做一些事情,比如查看它是否正在运行,尝试关闭,如果它仍在运行,则安排重新启动并进行 devenv 设置
通过 RunOnce 注册表项。

如果工作量太大,那么使用 Windows 命令 TASKKILL 退出应用程序将是一个丑陋的黑客行为。 虽然不是万无一失,但总比没有好。

TASKKILL /IM devenv.exe 

your best bet is to follow Rob's advide and put together a custom action to check if the process is running. I'd probably do something like see if it's running, try to close, if it's still running then schedule a reboot and do the devenv setup
via the RunOnce registry key.

If that's too much work then a bit of an ugly hack would be to use the windows command TASKKILL to exit the application. Not foolproof but it's better than nothing.

TASKKILL /IM devenv.exe 
人心善变 2024-07-23 18:12:25

您可以在项目中创建一个安装程序类并让它枚举正在运行的进程

You can create an installer class in your project and let it enumerate Running Processes

嗼ふ静 2024-07-23 18:12:25

我必须使用 TASKKILL /IM devenv.exe -F 来终止进程,并且 cmd 必须以管理员身份运行

I had to use TASKKILL /IM devenv.exe -F to kill the process and cmd had to be run as administrator

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文