InstallShield2015制作安装包----------卸载前结束执行中的进程
方法一:InstallShiel直接调用cmd命令来杀掉进程。
//更新或卸载时先关闭应用程序
sCmdLine=" /c taskkill /f /im \"Frs.exe\"";
nResult=LaunchAppAndWait("cmd",sCmdLine ,LAAW_OPTION_HIDDEN|LAAW_OPTION_NOWAIT);
备注:
1、命令行前 ,记得加上 /c
2、LaunchAppAndWait()函数第一个参数“cmd”,还有另外一种方式。并不是很好用。
STRING scCmd;
STRING sCmdLine; scCmd=WINDIR ^ "system32" ^ "cmd.exe";
nResult=LaunchAppAndWait(scCmd,sCmdLine ,LAAW_OPTION_HIDDEN|LAAW_OPTION_NOWAIT);
方法二:来自网友写的一些代码。
prototype POINTER ArrayToPointer(BYREF VARIANT);
prototype NUMBER ProcessEnd(STRING);
prototype BOOL ProcessRunning(STRING); // Kernel functions. prototype NUMBER Kernel32.OpenProcess(NUMBER, BOOL, NUMBER);
prototype NUMBER Kernel32.TerminateProcess(NUMBER, NUMBER); // Process information functions. prototype NUMBER PSAPI.EnumProcesses(POINTER, NUMBER, BYREF NUMBER);
prototype NUMBER PSAPI.EnumProcessModules(NUMBER, BYREF NUMBER, NUMBER,
BYREF NUMBER);
prototype NUMBER PSAPI.GetModuleFileNameExA(NUMBER, NUMBER, BYREF STRING,
NUMBER); /////////////////////////////////////////////////
// Structures.
///////////////////////////////////////////////// // Structure to mirror the C/C++ SAFEARRAY data structure. typedef _SAFEARRAY
begin
SHORT cDims;
SHORT fFeatures;
LONG cbElements;
LONG cLocks;
POINTER pvData;
// rgsaBound omitted
end; // Structure to mirror the C/C++ VARIANT data structure. typedef _VARIANT
begin
SHORT vt;
SHORT wReserver1;
SHORT wReserved2;
SHORT wReserved3;
NUMBER nData;
end; /////////////////////////////////////////////////
// Constants.
///////////////////////////////////////////////// #define PSAPI_FILE "psapi.dll" // Windows NT process DLL
#define PROCESSID_LENGTH 4 // 4 bytes (DWORD) for a process ID // Process information constants. #define PROCESS_QUERY_INFORMATION 0x400
#define PROCESS_ALL_ACCESS 0x1f0fff
#define PROCESS_VM_READ 0x10 //////////////////////////////////////////////////////////////////////////////
//
// Function: ArrayToPointer
//
// Description: Converts an InstallShield array into a C array.
//
// When an array is created in InstallScript, a VARIANT variable
// is created which holds an OLEAutomation SAFEARRAY. To pass
// such an array to a DLL function expecting a C-style array,
// this function explicitly typecasts the pointer to the array
// to a _VARIANT pointer so that the _SAFEARRAY pointer can be
// extracted. The pointer to the actual data is then extracted
// from the _SAFEARRAY pointer.
//
// Parameters: structArray - Array variable.
//
// Returns: POINTER - Pointer to array.
//
////////////////////////////////////////////////////////////////////////////// function POINTER ArrayToPointer(structArray)
_SAFEARRAY POINTER pstructArray; // _SAFEARRAY array pointer
_VARIANT POINTER pstructVariant; // _VARIANT array pointer
begin
// Typecast the pointer to the array to a _VARIANT pointer. pstructVariant = &structArray; // Extract the _SAFEARRAY pointer from the _VARIANT. pstructArray = pstructVariant->nData; // Return the pointer to the actual data from the _SAFEARRAY. return pstructArray->pvData;
end; //////////////////////////////////////////////////////////////////////////////
//
// Function: _Process_End
//
// Description: Terminates running processes for the specified application.
//
// Parameters: szAppName - Name of the application to terminate.
//
// Returns: >= 0 - Number of processes terminated.
// -1 - Failure.
//
////////////////////////////////////////////////////////////////////////////// function NUMBER ProcessEnd(szAppName)
NUMBER nvReturn; // Number of processes terminated
NUMBER nvProcessIDs(); // Array of process IDs
NUMBER nvBytesReturned; // Number of bytes returned in process ID array
NUMBER nvProcesses; // Number of processes running
NUMBER nvIndex; // Loop index
NUMBER nvProcessHandle; // Handle to a process
NUMBER nvModuleHandle; // Handle to a process module
NUMBER nvBytesRequired; // Number of bytes required to store values
POINTER pvProcessIDs; // Pointer to process ID array
STRING svModuleName; // Module name
STRING svFileName; // Module filename
begin
// The psapi.dll reads the Windows NT performance database. The DLL
// is part of the Win32 SDK. if UseDLL(WINSYSDIR ^ PSAPI_FILE) < then
// Could not load psapi.dll. MessageBox("ERROR: Could not load [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return -;
endif; // Get the PIDs of all currently running processes. pvProcessIDs = ArrayToPointer(nvProcessIDs); EnumProcesses(pvProcessIDs, , nvBytesReturned); // Determine the number of process IDs retrieved. Each process ID
// is PROCESSID_LENGTH bytes. nvProcesses = nvBytesReturned / PROCESSID_LENGTH; // Get the executable associated with each process, and check if
// its filename matches the one passed to the function. for nvIndex = to nvProcesses
// Get a handle to the process. The OpenProcess function
// must have full (all) access to be able to terminate
// processes. nvProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_ALL_ACCESS, , nvProcessIDs(nvIndex)); if nvProcessHandle != then
// Get a handle to the first module in the process, which
// should be the executable. if EnumProcessModules(nvProcessHandle, nvModuleHandle,
PROCESSID_LENGTH, nvBytesRequired) != then
// Get the path of the module. if GetModuleFileNameExA(nvProcessHandle, nvModuleHandle,
svModuleName, SizeOf(svModuleName)) != then
// Extract the filename (without an extension) from
// the path. ParsePath(svFileName, svModuleName, FILENAME_ONLY); if StrCompare(svFileName, szAppName) = then
// The process module matches the application
// name passed to the function. if TerminateProcess(nvProcessHandle, ) > then
nvReturn++;
endif;
endif;
endif;
endif;
endif;
endfor; if UnUseDLL(PSAPI_FILE) < then
MessageBox("ERROR: Could not unload [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return -;
endif; return nvReturn;
end; //////////////////////////////////////////////////////////////////////////////
//
// Function: _Process_Running
//
// Description: Determines if the specified process is running in memory.
//
// Parameters: szAppName - Name of the application to check.
//
// Returns: TRUE - The process is running.
// FALSE - The process is not running.
//
////////////////////////////////////////////////////////////////////////////// function BOOL ProcessRunning(szAppName)
BOOL bvRunning; // Process is running
NUMBER nvProcessIDs(); // Array of process IDs
NUMBER nvBytesReturned; // Number of bytes returned in process ID array
NUMBER nvProcesses; // Number of processes running
NUMBER nvIndex; // Loop index
NUMBER nvProcessHandle; // Handle to a process
NUMBER nvModuleHandle; // Handle to a process module
NUMBER nvBytesRequired; // Number of bytes required to store values
POINTER pvProcessIDs; // Pointer to process ID array
STRING svModuleName; // Module name
STRING svFileName; // Module filename
begin
// The psapi.dll reads the Windows NT performance database. The DLL
// is part of the Win32 SDK. if UseDLL(WINSYSDIR ^ PSAPI_FILE) < then
// Could not load psapi.dll. MessageBox("ERROR: Could not load [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return FALSE;
endif; // Get the PIDs of all currently running processes. pvProcessIDs = ArrayToPointer(nvProcessIDs); EnumProcesses(pvProcessIDs, , nvBytesReturned); // Determine the number of process IDs retrieved. Each process ID
// is PROCESSID_LENGTH bytes. nvProcesses = nvBytesReturned / PROCESSID_LENGTH; // Get the executable associated with each process, and check if
// its filename matches the one passed to the function. for nvIndex = to nvProcesses
// Get a handle to the process. nvProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, , nvProcessIDs(nvIndex)); if nvProcessHandle != then
// Get a handle to the first module in the process, which
// should be the executable. if EnumProcessModules(nvProcessHandle, nvModuleHandle,
PROCESSID_LENGTH, nvBytesRequired) != then
// Get the path of the module. if GetModuleFileNameExA(nvProcessHandle, nvModuleHandle,
svModuleName, SizeOf(svModuleName)) != then
// Extract the filename (without an extension) from
// the path. ParsePath(svFileName, svModuleName, FILENAME_ONLY); if StrCompare(svFileName, szAppName) = then
// The process module matches the application
// name passed to the function. bvRunning = TRUE; goto ProcessRunningEnd;
endif;
endif;
endif;
endif;
endfor; ProcessRunningEnd: if UnUseDLL(PSAPI_FILE) < then
MessageBox("ERROR: Could not unload [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return FALSE;
endif; return bvRunning;
end;
调用方式如下:
if ProcessRunning("Frs") then
MessageBox("Application \"Frs\" is running,will been killed ", INFORMATION);
ProcessEnd("Frs");
endif;
InstallShield2015制作安装包----------卸载前结束执行中的进程的更多相关文章
- InstallShield2015制作安装包----------卸载后删除安装目录和文件
卸载程序后,一般是需要将安装目录清除干净.但是,如果程序运行中有文件生成,这时InstallShield自带的卸载程序,不会卸载这些运行时生成的文件. 卸载不干净,可能会对下次程序的安装,和安装后的运 ...
- InstallShield2015制作安装包----------安装后实现电脑开机自启动
开机自启动有两个方法: 一 .把程序的快捷方式放在”开始---启动“目录下. 二.把程序的安装目录放在注册表”“. 实现方法一: 1.编写bat脚本.执行bat启动exe. a)核心:cmd命令 : ...
- [Winform]setupfactory制作安装包卸载输入密码进行验证
摘要 项目有这样一个需求,在体验机上安装了一个软件,如果有用户卸载的时候,给与输入密码验证的提示,当然强制删除软件所在目录除外.那么这个有办法实现吗? 解决办法 在卸载的时候,用户单击下一步的时候进行 ...
- InstallShield2015制作安装包----------安装过程中修改文件内容
//修改安装目录下autostart.vbs里的路径 //打开文件 OpenFileMode(FILE_MODE_NORMAL); strPath=INSTALLDIR+"centerAut ...
- InstallShield2015制作安装包----------安装后实现自动运行
安装向导完成后,自动运行. 实现的手段是:InstallScript脚本OnEnd()函数里面,调用可执行程序. 备注:INSTALLDIR预定义变量存放着程序的安装目录. //安装后运行dispat ...
- installshield制作的安装包卸载时提示重启动的原因以及解决办法
原文:installshield制作的安装包卸载时提示重启动的原因以及解决办法 有时候卸载installshield制作的安装包程序,卸载完会提示是否重启电脑以完成所有卸载,产生这个提示的常见原因有如 ...
- 使用VS2015制作安装包( 含相关的下载链接)
补充: 在看下面的教程过程中,如果在下面的步聚1中没有 " Visual Studio Installer", 则需要通过下面的链接进行安装 Visual Studio Insta ...
- 20 Inno Setup制作安装包的几个问题
系统开发好之后,通常需要制作成安装包,才能卖给用户.利用Inno Setup的向导可以制作简单的安装包,但是如果要做个好的安装包的话可能会遇到一些麻烦,今日终于抽空解决了,Inno Setup打包的一 ...
- 为自己编写的windows应用程序制作安装包
1 写好了一个windows程序之后如何制作安装包 这个在vs中就可以直接发布了,可以制作msi的安装包和exe的安装包. 2 window应用程序安装包做了哪些事情 rpm安装包的话,只是把相应的文 ...
随机推荐
- Vue 数据响应式原理
Vue 数据响应式原理 Vue.js 的核心包括一套“响应式系统”.“响应式”,是指当数据改变后,Vue 会通知到使用该数据的代码.例如,视图渲染中使用了数据,数据改变后,视图也会自动更新. 举个简单 ...
- python-爬虫:取qq号中各分组成员信息存入数据库,并将qq头像下载保存到文件夹,图片命名为qq号(实例3)
import requestsimport pymongoimport requestsimport os class QqGroup:#三个接口url 获取 qq组号 获取每组成员信息 获取qq头像 ...
- 1 byte 8 bit 1 sh 1 bit 2. 字符与编码在程序中的实现
https://en.wikipedia.org/wiki/Shannon_(unit) 1字节(英语:Byte)=8比特(英语:bit) The shannon (symbol Sh), also ...
- python导入方法,软件目录
软件目录 import os #print(__file__)#打印当前文件相对路径(文件,发要) import sys BASE_DIR=os.path.dirname(os.path.dirnam ...
- python之类中如何判断是函数还是方法
通常我们认为在类中的函数为方法,类外面声明def为函数,这种说法有点片面 方法1: class Work(object): def show(self): print("执行show方法&q ...
- SQL Server的一些小问题
一.SQL Server远程调用失败 解决办法:在控制面板-程序和功能中卸载“Microsoft SQL Server 2012 Express LocalDB”,具体版本根据你安装的VS版本决定,我 ...
- 萌新接触前端的第二课——CSS
前端知识——CSS CSS(英文全称:Cascading Style Sheets) 中文名层叠样式表,是一种用来表现HTML或XML等文件样式的计算机语言.CSS不仅可以静态地修饰网页,还可以配合各 ...
- CA证书和TLS介绍
数字签名 用自己的私钥给数据加密就叫数字签名 公钥传输威胁 在A和B的通信中,C可以把自己的公钥发给A,让A把C的公钥当成B的公钥,这样的话.B拿到加密数据反而无法解密,而C却可以解密出数据.从而实现 ...
- 帝国cms判断某一字段是否为空
<?php if(empty($navinfor[buy])) { ?> <? } else { ?> <h2 class="buy">< ...
- javascript常见操作数组的方法
在 JavaScript 中,判断一个变量的类型尝尝会用 typeof 运算符,在使用 typeof 运算符时采用引用类型存储值会出现一个问题,无论引用的是什么类型的对象,它都返回 "obj ...