I am currently trying to do a validation at the uninstall moment. In a Pascal script function, in Inno Setup, I want to search for a specific processes, with a wild card if possible. Then, loop through all find results, get the Image Name and Image Path Name, in order to check if the program that is about to be uninstalled is the same as the one running.

Is there a way to do that?

This is an exemplary task for WMI and its WQL language. Getting list of running processes through WMI is even more reliable than Windows API. The below example shows how to query the Win32_Process class with the LIKE operator:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program [Code]
type
TProcessEntry = record
PID: DWORD;
Name: string;
Description: string;
ExecutablePath: string;
end;
TProcessEntryList = array of TProcessEntry; function GetProcessList(const Filter: string;
out List: TProcessEntryList): Integer;
var
I: Integer;
WQLQuery: string;
WbemLocator: Variant;
WbemServices: Variant;
WbemObject: Variant;
WbemObjectSet: Variant;
begin
Result := 0; WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('localhost', 'root\CIMV2'); WQLQuery :=
'SELECT ' +
'ProcessId, ' +
'Name, ' +
'Description, ' +
'ExecutablePath ' +
'FROM Win32_Process ' +
'WHERE ' +
'Name LIKE "%'+ Filter +'%"'; WbemObjectSet := WbemServices.ExecQuery(WQLQuery);
if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
begin
Result := WbemObjectSet.Count;
SetArrayLength(List, WbemObjectSet.Count);
for I := 0 to WbemObjectSet.Count - 1 do
begin
WbemObject := WbemObjectSet.ItemIndex(I);
if not VarIsNull(WbemObject) then
begin
List[I].PID := WbemObject.ProcessId;
List[I].Name := WbemObject.Name;
List[I].Description := WbemObject.Description;
List[I].ExecutablePath := WbemObject.ExecutablePath;
end;
end;
end;
end; procedure InitializeWizard;
var
S: string;
I: Integer;
Filter: string;
ProcessList: TProcessEntryList;
begin
MsgBox('Now we try to list processes containing "sv" in their names...',
mbInformation, MB_OK); Filter := 'sv';
if GetProcessList(Filter, ProcessList) > 0 then
for I := 0 to High(ProcessList) do
begin
S := Format(
'PID: %d' + #13#10 +
'Name: %s' + #13#10 +
'Description: %s' + #13#10 +
'ExecutablePath: %s', [
ProcessList[I].PID,
ProcessList[I].Name,
ProcessList[I].Description,
ProcessList[I].ExecutablePath]);
MsgBox(S, mbInformation, MB_OK);
end;
end;
answered Jan 28 '14 at 14:39
TLama

55.1k14109177
 
    
That works really well. The only thing is that I get the Executable path in the following format: "PROGRA~1\243~1.106\prog.exe". Can I do something to have the full path, like displayed in the task manager, instead of the compact path with the ~1 ? Strangely, for the second folder, the ~1 is in the middle of the folder name, probably because of the dots in the name... – Amaranth Jan 28 '14 at 20:31
    
That looks like a 8.3 filename. Try to call the ExpandFileName function to expand it to full path. – TLamaJan 28 '14 at 20:39
    
It did not work, but no worries, I found a way that worked for me (it's a bit more complex though). vincenzo.net/isxkb/index.php?title=GetLongPathName_() Thank you for your great help :) – Amaranth Jan 28 '14 at 20:50 
1  
You're welcome! Hm, the ExpandFileName function internally calls GetFullPathName rather than GetLongPathName. It makes me wonder what's the difference between them... – TLama Jan 28 '14 at 21:07
    
I think this only works in Unicode Inno Setup. I use the non-Unicode version and this will compile for me but always errors out. I think Unicode Inno Setup has more support for Variant casting etc... This place I get stuck at on this script is where WbemObjectSet.Count gets used first. – Arvo Bowen Feb 3 at 0:29

Inno Setup Pascal Script to search for running process的更多相关文章

  1. Inno Setup, Pascal 字符串带双引号如何写

    Windows 的路径中如果有空格,就需要用双引号括起来.只能填 ASCII-Code-Number (decimal),不能用一般的 escape 方法. # + path + # 查询这个表的第一 ...

  2. Inno Setup制作安装包的几个问题

    1. 卸载时,如何判断应用程序是否运行    InnoSetup 提供变量AppMutex,用来保存应用程序的Mutex名称.现在很多应用程序都是唯一实例运行.这样避免配置文件被错误修改以及其他很多衍 ...

  3. 20 Inno Setup制作安装包的几个问题

    系统开发好之后,通常需要制作成安装包,才能卖给用户.利用Inno Setup的向导可以制作简单的安装包,但是如果要做个好的安装包的话可能会遇到一些麻烦,今日终于抽空解决了,Inno Setup打包的一 ...

  4. Inno Setup入门(十三)——Pascal脚本(2)

    分类: Install Setup 2013-02-02 11:26 794人阅读 评论(0) 收藏 举报 事件函数(2) function CheckPassword(Password: Strin ...

  5. (转)Inno Setup入门(十三)——Pascal脚本(2)

    本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250933 事件函数(2) function CheckPassw ...

  6. Inno Setup入门(十三)——Pascal脚本(2)

    事件函数(2) function CheckPassword(Password: String): Boolean; 如果安装程序在Pascal 脚本中发现该函数,它自动显示密码页并调用CheckPa ...

  7. 【Inno Setup】Pascal 脚本 ---- 事件函数

    转载 事件函数 Inno Setup支持以下函数和过程. 1. [安装初始化]该函数在安装程序初始化时调用,返回False 将中断安装,True则继续安装,测试代码如下: function Initi ...

  8. Inno Setup入门(十二)——Pascal脚本(1)

    事件函数(1) Inno Setup支持以下函数和过程. function InitializeSetup(): Boolean; 该函数在安装程序初始化时调用,返回False 将中断安装,True则 ...

  9. (转)Inno Setup入门(十二)——Pascal脚本(1)

    本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250917 事件函数(1) Inno Setup支持以下函数和过程 ...

随机推荐

  1. tarjan算法--cojs 1298. 通讯问题

    cojs 1298. 通讯问题 ★   输入文件:jdltt.in   输出文件:jdltt.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员, ...

  2. MySQL数据库单例连接简单实现(MySQL扩展)

    <?php /** * MySQL数据库单例实现 * * @author shizq at 2015-04-22 * */ final class MySQLFactory { private ...

  3. 项目部署后,替换.class文件不生效

    昨天晚上踩了个坑,搞到晚上凌晨.今天感觉有必要总结一下菜的坑... 因为正式环境部署项目,有很多个服务器,有时候发包太慢,或者一些原因不可以轻易发包的.下面谈一下我的经历过程: 因为升级了版本,ip地 ...

  4. MSChart使用小结

        在用到图表展示某项.多项信息的统计情况,很正常联想到MSChart控件.        以VS2008开发为例,在工具箱也中右击,选择”choose items“,打开对话框,选择COM组件T ...

  5. axios 与 Jquery-ajax 的使用区别

    axios 和 ajax 的使用方法基本一样,只有个别参数不同: 附:axios 中文文档 一.axios axios({ url: 'http://jsonplaceholder.typicode. ...

  6. Segger Real Time Terminal RTT JLINK 客户端软件 GUI 版本

  7. Ruby:对象模型(又称八卦模型)笔记

    备注 如果说哪门语言对我影响最大,那就是Ruby了,在.NET阵营多年,试图去用C#的思维去解释很多东西,当然解释Java是足够了,可惜我也用了好几年去解释Javascript,结果是可想而知的:解释 ...

  8. iOS-- UIimageView详解

    原文地址: http://blog.csdn.net/djxiaoyu_haha/article/details/40348377 // (1)创建 UIImageView *imageView = ...

  9. Log4j写入数据库详解

    log4j是一个优秀的开源日志记录项目,我们不仅可以对输出的日志的格式自定义,还可以自己定义日志输出的目的地,比如:屏幕,文本文件,数据库,甚至能通过socket输出.本节主要讲述如何将日志信息输入到 ...

  10. 推荐一份 Google 面试指南

    经常有不少读者在我公众号后台留言,说自己还是应届毕业生,缺乏工作经验与项目经验,不知道如何才能通过面试? 其实,项目经验固然重要,但是企业也知道,对于应届毕业生,是很难有拿得出手的项目经验出来的,毕竟 ...