在安装过程中如何检查某个程序是否正在运行? [英] How to check during setup if a certain program is running?

查看:130
本文介绍了在安装过程中如何检查某个程序是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2008创建安装项目,我想知道是否存在一种标准的方法来检查安装过程中是否正在运行某个程序?在这种情况下,我要检查Microsoft Excel的任何实例.

I'm creating a setup project using Visual Studio 2008 and I was wondering if there is a standard way to check if a certain program is running during the setup? In this case I want to check for any instances of Microsoft Excel.

提前谢谢!

推荐答案

要在安装过程中执行此操作,您可能必须定义一个自定义操作.自定义操作是一个安装步骤,它允许您运行任意代码. SO文章中涉及的主题太大,但是下面的文章将帮助您开始进行自定义操作

To do this during setup you will likely have to define a custom action. A custom action is an install step which allows you to run arbitrary code. It's too big of a topic to cover in a SO post, but the following article will help you get started on custom actions

在此操作中,您可以使用进程类来确定特定进程是否正在运行.

In this action you could use the process class to determine if a particular process is running.

public static bool IsExcelRunning() {
  return Process.GetProcesses().Where(x => x.ProcessName == "excel");
}

如果它是excel或msexcel,记不起我的头了,但是您可以适当地调整;).

Can't remember off the top of my head if it's excel or msexcel but you can adjust appropriately ;).

这篇关于在安装过程中如何检查某个程序是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆