windows – Inno设置Pascal脚本来搜索运行进程
发布时间:2020-12-14 02:05:28 所属栏目:Windows 来源:网络整理
导读:我目前正在尝试在卸载时进行验证.在Pascal脚本函数中,在Inno Setup中,我想搜索特定的进程,如果可能的话使用通配符.然后,遍历所有查找结果,获取图像名称和图像路径名称,以检查即将卸载的程序是否与正在运行的程序相同. 有没有办法做到这一点? 解决方法 这是W
|
我目前正在尝试在卸载时进行验证.在Pascal脚本函数中,在Inno Setup中,我想搜索特定的进程,如果可能的话使用通配符.然后,遍历所有查找结果,获取图像名称和图像路径名称,以检查即将卸载的程序是否与正在运行的程序相同.
有没有办法做到这一点? 解决方法
这是WMI及其WQL语言的示例性任务.通过WMI获取正在运行的进程列表比
Windows API更可靠.以下示例显示如何使用
LIKE运算符查询
Win32_Process类:
[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','rootCIMV2');
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,MB_OK);
end;
end;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-server-2008 – 将组策略应用于远程桌面服务用户,但
- windows-xp – 如何从.exe自动安装驱动程序
- Windows Server 2012 R2 VM备份失败,可用存储空间不足,无法
- 在Windows 8上使用gem安装SASS
- windows-server-2008 – Subversion Edge LDAP(需要CAC证书
- 在Windows上,控制台窗口所有权如何工作?
- Windows上的Makefile错误
- microsoft-office – OpenOffice可以取代MS Office吗?
- 如何减少Windows Azure网站上托管的Orchard CMS站点的内存消
- Windows Phone 7从应用程序导航到互联网
