如何使用installscript检测Excel.exe运行? [英] How can I use installscript to detect Excel.exe running?
问题描述
我有一个自定义的操作,在appsearch之后运行,如果找到该进程并向用户显示警告,则会弹出窗口。
我尝试使用一些我在installsite.org上找到的旧例,并使用findWindow()调用。在进程列表中似乎都没有找到excel.exe。
以下是尝试查找窗口时使用的代码片段
出口原型MyTestFunction(HWND);
函数MyTestFunction(hMSI)
HWND nHwnd;
begin
nHwnd = FindWindow(EXCEL,);
if(nHwnd!= 0)then
MessageBox(found excel,WARNING);
SendMessage(nHwnd,WM_CLOSE,0,0);
else
MessageBox(could find excel,WARNING);
endif;
end;
请注意,只有其他块似乎触发,无论应用程序是打开还是关闭。 p>
我尝试了几种不同的变体,其中大部分只是用不同的大小写,扩展和版本替换excel。没有什么似乎检测到窗口。我使用了Spy ++,它报告说,窗口以当前打开的笔记本的名称命名,使得事情变得复杂,因为我无法知道用户可以打开什么。
我可以在这里提出建议。该解决方案的唯一要求是必须能够从Installshield中作为自定义操作或安装条件的一部分运行。
您可以使用vbscript自定义操作。
您可以在UISequence或ExecuteSequence(或两者)的开始运行此CA如果您希望它作为安装条件的一部分。
将代码添加到vbscript函数中,如果要停止安装过程,请将自定义操作的返回处理选项配置为同步(检查退出代码)。
这是我的脚本:
公共功能StopProcess
Dim objWMIService,objProcess, colProcess
Dim strComputer,executableFileName
Const IDABORT = 3
strComputer =。
executableFileName =excel.exe
设置objWMIService = GetObject(winmgmts:{impersonationLevel = impersonate}!\\& strComputer&\root\cimv2 )
Set colProcess = objWMIService.ExecQuery(Select * from Win32_Process Where Name ='& executableFileName&')
对于colProcess中的每个objProcess
objProcess .Terminate()
'OR
StopProcess = IDABORT
退出
下一个
结束函数
Ive been trying to detect the excel process in my installshield installer. I have a custom action that runs after appsearch and pops a window if it finds the process and displays a warning to the user.
I have tried using some old examples I found on installsite.org and using the findWindow() call. Neither seems to find excel.exe in the process list.
Here is a snippet of code I was using when trying the findwindow
export prototype MyTestFunction(HWND);
function MyTestFunction(hMSI)
HWND nHwnd;
begin
nHwnd = FindWindow("EXCEL", "");
if (nHwnd != 0) then
MessageBox("found excel", WARNING);
SendMessage(nHwnd, WM_CLOSE, 0, 0);
else
MessageBox("cant find excel", WARNING);
endif;
end;
Note that only the else block ever seems to fire regardless of the application being open or closed.
I have tried several different variants of this mostly just replacing the "excel" with different capitalization, extensions and versions. Nothing seems to detect the window. I used Spy++ and it reported that the window is named after the name of the currently opened notebook which complicates things since I have no way of knowing what a user could have opened.
I am open to suggestions here. The only requirement for this solution is that it has to be able to run as either a custom action or part of an install condition from within Installshield.
You could use a vbscript Custom Action. You can run this CA at the begining of UISequence or ExecuteSequence (or both) If you want it as a part of the Install condition. Add the code in a vbscript function and configure "Return Processing" Option for the Custom Action to "Synchonous (Check exit code)" if you want to stop the installation process.
Here is my script:
Public Function StopProcess
Dim objWMIService, objProcess, colProcess
Dim strComputer, executableFileName
Const IDABORT = 3
strComputer = "."
executableFileName = "excel.exe"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & executableFileName & "'")
For Each objProcess in colProcess
objProcess.Terminate()
' OR
StopProcess = IDABORT
Exit for
Next
End function
这篇关于如何使用installscript检测Excel.exe运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!