1.在操作时,首先引入类库ShutDownRunningApp.rul,其中ShutDownRunningApp.rul代码如下

//////////////////////////////////////////////////////////////////////////////
//
// Description: WindowsNT process control functions.
//
// The process code is adapted fromcode posted by William F.
// Snodgrass to www.installsite.org.The original code header
// is appended below. The array codeis adapted from code posted
// by Rajesh Ramachandran to theinstallshield.is6.installscript
// newsgroup.
//
// Submitted by RichardIwasa (riwasa@email.com).
//
// Usage example:
//
// ifProcessRunning("notepad") then
// MessageBox("Application isrunning.", INFORMATION);
//
// ProcessEnd("notepad");
//
// Delay(2); // Delay to allow process list to refresh
//
// if ProcessRunning("notepad")then
// MessageBox("Application isrunning.", INFORMATION);
// else
// MessageBox("Application is notrunning.", INFORMATION);
// endif;
// else
// MessageBox("Application is notrunning.", INFORMATION);
// endif;
//
// Original code headerappended below:
//
// GetRunningApp();
// ShutDownApp();
//
// These script createdfunctions will look for any running application
// based on the filename, then display an error message within the Setup.
// You can optionally haltthe install or just continue on.
//
// You can use theShutDownApp() function for shutting down that process
// or others as well.This is useful for processes that run in the
// background but haveno Windows associated with them. May not work with
// Services.
//
// This script callsfunctions in PSAPI.DLL that are not supported on
// Windows 95 or 98.
//
// ***Instructions***
// Place these scriptpeices into the Setup.rul file.
//
// Modify the script toinclude the applications you would like to get or
// shutdown.
//
// Submitted by WilliamF. Snodgrass
// Contact info:bsnodgrass@geographix.com
//
// Created by TheronWelch, 3/3/99
// Minor modificationsby Stefan Krueger, 11/03/99
//
// Copyright (c)1999-2000 GeoGraphix, Inc.
//
////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////
// Function prototypes.
///////////////////////////////////////////////// prototype POINTERArrayToPointer(BYREF VARIANT);
prototype NUMBER ProcessEnd(STRING);
prototype BOOL ProcessRunning(STRING); // Kernel functions. prototype NUMBERKernel32.OpenProcess(NUMBER, BOOL, NUMBER);
prototype NUMBERKernel32.TerminateProcess(NUMBER, NUMBER); // Process informationfunctions. prototype NUMBERPSAPI.EnumProcesses(POINTER, NUMBER, BYREF NUMBER);
prototype NUMBERPSAPI.EnumProcessModules(NUMBER, BYREF NUMBER, NUMBER,
BYREF NUMBER);
prototype NUMBERPSAPI.GetModuleFileNameExA(NUMBER, NUMBER, BYREF STRING,
NUMBER); /////////////////////////////////////////////////
// Structures.
///////////////////////////////////////////////// // Structure to mirrorthe C/C++ SAFEARRAY data structure. typedef _SAFEARRAY
begin
SHORT cDims;
SHORT fFeatures;
LONG cbElements;
LONG cLocks;
POINTER pvData;
// rgsaBound omitted
end; // Structure to mirrorthe 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 informationconstants. #definePROCESS_QUERY_INFORMATION 0x400
#definePROCESS_ALL_ACCESS 0x1f0fff
#definePROCESS_VM_READ 0x10 //////////////////////////////////////////////////////////////////////////////
//
// Function: ArrayToPointer
//
// Description: Convertsan InstallShield array into a C array.
//
// When an array is created inInstallScript, a VARIANT variable
// is created which holds anOLEAutomation SAFEARRAY. To pass
// such an array to a DLL functionexpecting a C-style array,
// this function explicitlytypecasts the pointer to the array
// to a _VARIANT pointer so that the_SAFEARRAY pointer can be
// extracted. The pointer to theactual data is then extracted
// from the _SAFEARRAY pointer.
//
// Parameters: structArray - Array variable.
//
// Returns: POINTER - Pointer to array.
//
////////////////////////////////////////////////////////////////////////////// function POINTERArrayToPointer(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 datafrom the _SAFEARRAY. return pstructArray->pvData;
end; //////////////////////////////////////////////////////////////////////////////
//
// Function: _Process_End
//
// Description:Terminates running processes for the specified application.
//
// Parameters: szAppName - Name of the application toterminate.
//
// Returns: >= 0 - Number of processes terminated.
// -1 - Failure.
//
////////////////////////////////////////////////////////////////////////////// function NUMBERProcessEnd(szAppName)
NUMBER nvReturn; // Number ofprocesses terminated
NUMBER nvProcessIDs(512); // Array ofprocess IDs
NUMBER nvBytesReturned; // Number ofbytes returned in process ID array
NUMBER nvProcesses; // Number ofprocesses running
NUMBER nvIndex; // Loop index
NUMBER nvProcessHandle; // Handle to aprocess
NUMBER nvModuleHandle; // Handle to aprocess module
NUMBER nvBytesRequired; // Number ofbytes required to store values
POINTER pvProcessIDs; // Pointer to process ID array
STRING svModuleName; // Module name
STRING svFileName; // Modulefilename
begin
// The psapi.dll reads the Windows NTperformance database. The DLL
// is part of the Win32 SDK. if UseDLL(WINSYSDIR ^ PSAPI_FILE) < 0then
// Could not load psapi.dll. MessageBox("ERROR: Could not load[" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return -1;
endif; // Get the PIDs of all currently runningprocesses. pvProcessIDs =ArrayToPointer(nvProcessIDs); EnumProcesses(pvProcessIDs, 512,nvBytesReturned); // Determine the number of process IDsretrieved. Each process ID
// is PROCESSID_LENGTH bytes. nvProcesses = nvBytesReturned /PROCESSID_LENGTH; // Get the executable associated with eachprocess, and check if
// its filename matches the one passed tothe function. for nvIndex = 1 to nvProcesses
// Get a handle to the process. TheOpenProcess function
// must have full (all) access to beable to terminate
// processes. nvProcessHandle =OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_ALL_ACCESS, 0,nvProcessIDs(nvIndex)); if nvProcessHandle != 0 then
// Get a handle to the first modulein the process, which
// should be the executable. ifEnumProcessModules(nvProcessHandle, nvModuleHandle,
PROCESSID_LENGTH,nvBytesRequired) != 0 then
// Get the path of the module. ifGetModuleFileNameExA(nvProcessHandle, nvModuleHandle,
svModuleName,SizeOf(svModuleName)) != 0 then
// Extract the filename(without an extension) from
// the path. ParsePath(svFileName,svModuleName, FILENAME_ONLY); if StrCompare(svFileName,szAppName) = 0 then
// The process modulematches the application
// name passed to thefunction. ifTerminateProcess(nvProcessHandle, 0) > 0 then
nvReturn++;
endif;
endif;
endif;
endif;
endif;
endfor; if UnUseDLL(PSAPI_FILE) < 0 then
MessageBox("ERROR: Could notunload [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return -1;
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 notrunning.
//
////////////////////////////////////////////////////////////////////////////// function BOOLProcessRunning(szAppName)
BOOL bvRunning; // Process isrunning
NUMBER nvProcessIDs(512); // Array ofprocess IDs
NUMBER nvBytesReturned; // Number ofbytes returned in process ID array
NUMBER nvProcesses; // Number ofprocesses running
NUMBER nvIndex; // Loop index
NUMBER nvProcessHandle; // Handle to aprocess
NUMBER nvModuleHandle; // Handle to aprocess module
NUMBER nvBytesRequired; // Number ofbytes required to store values
POINTER pvProcessIDs; // Pointer to process ID array
STRING svModuleName; // Module name
STRING svFileName; // Modulefilename
begin
// The psapi.dll reads the Windows NTperformance database. The DLL
// is part of the Win32 SDK. if UseDLL(WINSYSDIR ^ PSAPI_FILE) < 0then
// Could not load psapi.dll. MessageBox("ERROR: Could not load[" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return FALSE;
endif; // Get the PIDs of all currently runningprocesses. pvProcessIDs =ArrayToPointer(nvProcessIDs); EnumProcesses(pvProcessIDs, 512,nvBytesReturned); // Determine the number of process IDsretrieved. Each process ID
// is PROCESSID_LENGTH bytes. nvProcesses = nvBytesReturned /PROCESSID_LENGTH; // Get the executable associated with eachprocess, and check if
// its filename matches the one passed tothe function. for nvIndex = 1 to nvProcesses
// Get a handle to the process. nvProcessHandle =OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, 0,nvProcessIDs(nvIndex)); if nvProcessHandle != 0 then
// Get a handle to the first modulein the process, which
// should be the executable. ifEnumProcessModules(nvProcessHandle, nvModuleHandle,
PROCESSID_LENGTH,nvBytesRequired) != 0 then
// Get the path of the module. ifGetModuleFileNameExA(nvProcessHandle, nvModuleHandle,
svModuleName,SizeOf(svModuleName)) != 0 then
// Extract the filename(without an extension) from
// the path. ParsePath(svFileName,svModuleName, FILENAME_ONLY); if StrCompare(svFileName,szAppName) = 0 then
// The process modulematches the application
// name passed to thefunction. bvRunning = TRUE; goto ProcessRunningEnd;
endif;
endif;
endif;
endif;
endfor; ProcessRunningEnd: if UnUseDLL(PSAPI_FILE) < 0 then
MessageBox("ERROR: Could notunload [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE); return FALSE;
endif; return bvRunning;
end;

2.然后Setup.rul 代码如下:

//===========================================================================
//
// File Name: Setup.rul
//
// Description: Blank setup main script file
//
// Comments: Blank setup is an empty setup project. If you want to
// create a new project via. step-by step instructions use the
// Project Assistant.
//
//=========================================================================== // Included header files----------------------------------------------------
#include"ifx.h"
#include"ShutDownRunningApp.rul"
// Note: In order tohave your InstallScript function executed as a custom
// action by the WindowsInstaller, it must be prototyped as an
// entry-point function. // The keyword exportidentifies MyFunction() as an entry-point function.
// The argument itaccepts must be a handle to the Installer database. /* export prototypeMyFunction(HWND); */ function OnFirstUIBefore()
NUMBER nResult,nSetupType;
STRING szTitle, szMsg;
begin if ProcessRunning("SOMME") then
MessageBox("Application isrunning.", INFORMATION); ProcessEnd("SOMME"); Delay(2); // Delay to allow process list to refresh if ProcessRunning("SOMME")then
MessageBox("Application isrunning.", INFORMATION);
else
MessageBox("Application is notrunning.", INFORMATION);
endif;
else
MessageBox("Application is notrunning.", INFORMATION);
endif; abort; // TO DO: if you want to enable background,window title, and caption bar title
// SetTitle( @TITLE_MAIN, 24, WHITE );
// SetTitle( @TITLE_CAPTIONBAR, 0,BACKGROUNDCAPTION );
// Enable( FULLWINDOWMODE );
// Enable( BACKGROUND );
// SetColor(BACKGROUND,RGB (0, 128,128)); TARGETDIR = PROGRAMFILES ^@COMPANY_NAME^@PRODUCT_NAME; Dlg_Start:
// beginning of dialogs label Dlg_ObjDialogs:
nResult = ShowObjWizardPages(nResult);
if (nResult = BACK) goto Dlg_Start; // setup default status
SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100); return 0;
end; //////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: OnFirstUIAfter
//
// EVENT: FirstUIAfter event is sent after file transfer, when installation
// is run for the first time ongiven machine. In this event handler
// installation usually displays UIthat will inform end user that
// installation has been completedsuccessfully.
//
///////////////////////////////////////////////////////////////////////////////
functionOnFirstUIAfter()
begin
Disable(STATUSEX); ShowObjWizardPages(NEXT);
end; ///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: OnMaintUIAfter
//
// EVENT: MaintUIAfter event is sent after file transfer, when end user runs
// installation that has alreadybeen installed on the machine. Usually
// this happens through Add/RemovePrograms applet.
// In the handler installationusually displays UI that will inform
// end user thatmaintenance/uninstallation has been completed successfully.
//
///////////////////////////////////////////////////////////////////////////////
functionOnMaintUIAfter()
begin
Disable(STATUSEX); ShowObjWizardPages(NEXT);
end; ///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: OnMoving
//
// EVENT: Moving event is sent when file transfer is started as a result of
// ComponentTransferData call,before any file transfer operations
// are performed.
//
///////////////////////////////////////////////////////////////////////////////
function OnMoving()
STRING szAppPath;
begin
// Set LOGO Compliance Application Path
// TO DO : if your application .exe is in asubfolder of TARGETDIR then add subfolder
szAppPath = TARGETDIR;
RegDBSetItem(REGDB_APPPATH, szAppPath);
RegDBSetItem(REGDB_APPPATH_DEFAULT,szAppPath ^ @PRODUCT_KEY);
end; //---------------------------------------------------------------------------
// OnBegin
//
// The OnBegin event iscalled directly by the framework after the setup
// initializes.
//---------------------------------------------------------------------------
function OnBegin()
begin Disable (BACKBUTTON);
if(!MAINTENANCE)then
SdLicense2 ("License ", "Yes","False",SUPPORTDIR^"2.txt", FALSE);
endif; end;

Installshield 在安装或者卸载过程中,判断某一程序是否正在运行的更多相关文章

  1. Office2007在安装、卸载过程中出错的解决办法

    Micorsoft office professional plus 2007在安装过程中出错,错误1706 如果在安装OFFICE 2007的 时候,遇到“Microsoft Office 2007 ...

  2. oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序

    15511477451 原文 oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序? 环境:win7 64位系统.oracle11g数据库 问题描述:在win7 64位系统 ...

  3. (转)CloudStack 安装及使用过程中常见问题汇总

    CloudStack 安装及使用过程中常见问题汇总             在做工程项目中对CloudStack 安装及使用过程中常见的几个问题及如何解决做一个总结.   1.Windows XP虚拟 ...

  4. centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题。

    centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题. 原因:yum调用Python,启动程/usr/bin/yum就是一个python ...

  5. (最新)VS2015安装以及卸载过程——踩坑实录

    前言 Visual Studio (简称VS)是微软公司旗下最重要的软件集成开发工具产品.是目前最流行的 Windows 平台应用程序开发环境,也是无数人学习编程的入门软件之一.Visual Stud ...

  6. 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation

    安装过程中提示报错   点击确定后 安装程序会接着回滚,又提示报错如下       Error 1935的解决方法是下载一个微软的补丁. http://support.microsoft.com/de ...

  7. Oracle 安装安全补丁过程中出现的问题

    为Oracle安装安全补丁,首先在官网上下载相应版本的补丁. 根据官方文档的说明安装,但是在安装的过程中会出项各种各样的错误,这里仅仅把我遇到的记录下来,给大家提供参考. 首先按照官方文档安装. 在这 ...

  8. 安装python caffe过程中遇到的一些问题以及对应的解决方案

    关于系统环境: Ubuntu 16.04 LTS cuda 8.0 cudnn 6.5 Anaconda3 编译pycaffe之前需要配置文件Makefile.config ## Refer to h ...

  9. 我在MySQL免安装版使用过程中遇到的问题记录

    我的MySQL版本为:mysql-5.7.16-winx64 安装时间为:2016年5月10号 由于是免安装版,下载好压缩文件之后解压到特定目录下,再打开命令行运行几行命令即可. 在一次操作中,发现无 ...

随机推荐

  1. Android MagicIndicator系列之一 —— 使用MagicIndicator打造千变万化的ViewPager指示器

    说到 ViewPager 指示器,想必大家都不陌生,绝大部分应用中都有这个.使用频率非常之高.但系统对它的支持并不好,自带的 PagerTabStrip 和 PagerTitleStrip 太弱,很难 ...

  2. 微信开发学习日记(五):weiphp开源框架的bug,公众号权限编辑问题

    最近在研究weiphp,总体感觉还行,bug据说还挺多. 这不,我就遇到一个比较严重影响使用的.感觉不太应该出现这么严重的bug啊. weiphp的微信公众号等级,权限增加和编辑bug,看不到权限列表 ...

  3. 《iOS Human Interface Guidelines》——Segmented Control

    分段控件 分段控件是一组线性段.每一个button相应的功能能够显示一个不同的视图. API NOTE 查看UISegmentedControl来学习很多其它关于在你的代码中定义一个分段控件的内容. ...

  4. Android与IOS的UUID的区别

    UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, OS ...

  5. js时间和时间戳之间如何转换(汇总)

    js时间和时间戳之间如何转换(汇总) 一.总结 一句话总结: 1.js中通过new Date()来获取时间对象, 2.这个时间对象可以通过getTime()方法获取时间戳, 3.也可以通过getYea ...

  6. CSU1323: ZZY and his little friends

    Description zzy养了一只小怪兽和N只凹凸曼,单挑的话每只凹凸曼都不是小怪兽的对手,所以必须由两只凹凸曼合作来和小怪兽战斗.凹凸曼A和凹凸曼B合作的战斗力为他们战斗力的异或值.现在由zzy ...

  7. amazeui中的js插件有哪些(详解功能)

    amazeui中的js插件有哪些(详解功能) 一.总结 一句话总结: 二.amazeui中的js插件有哪些 1.UI 增强 警告框Alert 按钮交互Button 折叠面板Collapse 下拉组件D ...

  8. 中国象棋V2:Java源代码、毕业设计等所有文档,已经全部提交到CSDN-Code平台

    下载地址:https://code.csdn.net/FansUnion/chinesechess-v2 主要内容:Java源代码.毕业设计.API文档.声音图片等资源.Demo截图等一切的一切. 2 ...

  9. 带你轻松看源代码---AsyncTask(异步任务)

    本文出自博客Vander丶CSDN博客,如需转载请标明出处,尊重原创谢谢 博客地址:http://blog.csdn.net/l540675759/article/details/62893318 写 ...

  10. [ExtJS5学习笔记]第三十五条 sencha extjs 5 组件查询方法

    一UI前部组件势必更加,我们通常习惯性使用ID获取部件操作的需要.但是,这种方法是extjs推荐么?你有吗extjs利用它来获取组件的推荐方法? 夹 文件夹 extjs的查询组件的API 查询实例 主 ...