Installshield停止操作系统进程的代码 --IS6及以上版本适用
原文:Installshield停止操作系统进程的代码 --IS6及以上版本适用
setup.rul的代码
Code////////////////////////////////////////////////////////////////////////////////// // IIIIIII SSSSSS // II SS InstallShield (R) // II SSSSSS (c) 1996-2000, InstallShield Software Corporation // II SS (c) 1990-1996, InstallShield Corporation // IIIIIII SSSSSS All Rights Reserved. // // // This code is generated as a starting setup template. You should // modify it to provide all necessary steps for your setup.// // // File Name: Setup.rul // // Description: InstallShield script // // Comments: This template script performs a basic setup. With minor // modifications, this template can be adapted to create // new, customized setups.//////////////////////////////////////////////////////////////////////////////////// Include header files #include "ifx.h" //DO NOT REMOVE////////////////////// string defines //////////////////////////////////////////////// installation declarations ///////////////////// ----- DLL function prototypes ----- // your DLL function prototypes#include "ShutDownRunningApp.rul" // ---- script function prototypes ----- // your script function prototypes // your global variables//////////////////////////////////////////////////////////////////////////////// // FUNCTION: OnFirstUIBefore // // EVENT: FirstUIBefore event is sent when installation is run for the first// time on given machine. In the handler installation usually displays// UI allowing end user to specify installation parameters. After this// function returns, ComponentTransferData is called to perform file// transfer.// ///////////////////////////////////////////////////////////////////////////////function OnFirstUIBefore() NUMBER nResult,nSetupType; STRING szTitle, szMsg;begin if ProcessRunning("notepad") then MessageBox("Application is running.", INFORMATION); ProcessEnd("notepad"); Delay(2); // Delay to allow process list to refresh if ProcessRunning("notepad") then MessageBox("Application is running.", INFORMATION); else MessageBox("Application is not running.", INFORMATION); endif; else MessageBox("Application is not running.", 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 labelDlg_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 on given machine. In this event handler // installation usually displays UI that will inform end user that// installation has been completed successfully./////////////////////////////////////////////////////////////////////////////////function OnFirstUIAfter()begin Disable(STATUSEX); ShowObjWizardPages(NEXT); end;/////////////////////////////////////////////////////////////////////////////////// FUNCTION: OnMaintUIAfter//// EVENT: MaintUIAfter event is sent after file transfer, when end user runs // installation that has already been installed on the machine. Usually // this happens through Add/Remove Programs applet. // In the handler installation usually displays UI that will inform // end user that maintenance/uninstallation has been completed successfully./////////////////////////////////////////////////////////////////////////////////function OnMaintUIAfter()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 a subfolder of TARGETDIR then add subfolder szAppPath = TARGETDIR; RegDBSetItem(REGDB_APPPATH, szAppPath); RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);end;// --- include script file section ---
ShutDownRunningApp.rul的代码
Code////////////////////////////////////////////////////////////////////////////////// Description: Windows NT process control functions.//// The process code is adapted from code posted by William F.// Snodgrass to www.installsite.org. The original code header// is appended below. The array code is adapted from code posted// by Rajesh Ramachandran to the installshield.is6.installscript// newsgroup.// // Submitted by Richard Iwasa (riwasa@email.com).//// Usage example://// if ProcessRunning("notepad") then// MessageBox("Application is running.", INFORMATION);//// ProcessEnd("notepad");// // Delay(2); // Delay to allow process list to refresh// // if ProcessRunning("notepad") then// MessageBox("Application is running.", INFORMATION);// else// MessageBox("Application is not running.", INFORMATION);// endif;// else// MessageBox("Application is not running.", INFORMATION);// endif;//// Original code header appended below://// GetRunningApp();// ShutDownApp();// // These script created functions will look for any running application// based on the file name, then display an error message within the Setup.// You can optionally halt the install or just continue on.// // You can use the ShutDownApp() function for shutting down that process// or others as well. This is useful for processes that run in the // background but have no Windows associated with them. May not work with// Services.// // This script calls functions in PSAPI.DLL that are not supported on // Windows 95 or 98.// // ***Instructions***// Place these script peices into the Setup.rul file.// // Modify the script to include the applications you would like to get or// shutdown.// // Submitted by William F. Snodgrass// Contact info: bsnodgrass@geographix.com// // Created by Theron Welch, 3/3/99// Minor modifications by Stefan Krueger, 11/03/99// // Copyright (c) 1999-2000 GeoGraphix, Inc. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Function prototypes./////////////////////////////////////////////////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 _SAFEARRAYbegin SHORT cDims; SHORT fFeatures; LONG cbElements; LONG cLocks; POINTER pvData; // rgsaBound omittedend;// Structure to mirror the C/C++ VARIANT data structure.typedef _VARIANTbegin 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 pointerbegin // 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(512); // 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) < 0 then // Could not load psapi.dll. MessageBox("ERROR: Could not load [" + WINSYSDIR ^ PSAPI_FILE + "].", SEVERE); return -1; endif; // Get the PIDs of all currently running processes. pvProcessIDs = ArrayToPointer(nvProcessIDs); EnumProcesses(pvProcessIDs, 512, 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 = 1 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, 0, nvProcessIDs(nvIndex)); if nvProcessHandle != 0 then // Get a handle to the first module in the process, which // should be the executable. if EnumProcessModules(nvProcessHandle, nvModuleHandle, PROCESSID_LENGTH, nvBytesRequired) != 0 then // Get the path of the module. if GetModuleFileNameExA(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 module matches the application // name passed to the function. if TerminateProcess(nvProcessHandle, 0) > 0 then nvReturn++; endif; endif; endif; endif; endif; endfor; if UnUseDLL(PSAPI_FILE) < 0 then MessageBox("ERROR: Could not unload [" + 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 not running.////////////////////////////////////////////////////////////////////////////////function BOOL ProcessRunning(szAppName) BOOL bvRunning; // Process is running NUMBER nvProcessIDs(512); // 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) < 0 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, 512, 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 = 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 module in the process, which // should be the executable. if EnumProcessModules(nvProcessHandle, nvModuleHandle, PROCESSID_LENGTH, nvBytesRequired) != 0 then // Get the path of the module. if GetModuleFileNameExA(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 module matches the application // name passed to the function. bvRunning = TRUE; goto ProcessRunningEnd; endif; endif; endif; endif; endfor; ProcessRunningEnd: if UnUseDLL(PSAPI_FILE) < 0 then MessageBox("ERROR: Could not unload [" + WINSYSDIR ^ PSAPI_FILE + "].", SEVERE); return FALSE; endif; return bvRunning;end;
Installshield停止操作系统进程的代码 --IS6及以上版本适用的更多相关文章
- Installshield停止操作系统进程的代码--IS5版本适用
原文:Installshield停止操作系统进程的代码--IS5版本适用 出处:http://www.installsite.org/pages/en/isp_ext.htm这个地址上有不少好东西,有 ...
- Redis:安装、配置、操作和简单代码实例(C语言Client端)
Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...
- SELECT控件操作的JS代码示例
SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...
- C#开发中使用Npoi操作excel实例代码
C#开发中使用Npoi操作excel实例代码 出处:西西整理 作者:西西 日期:2012/11/16 9:35:50 [大 中 小] 评论: 0 | 我要发表看法 Npoi 是什么? 1.整个Exce ...
- 30个php操作redis常用方法代码例子
From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...
- php foreach 操作数组的代码
php foreach 操作数组的代码. foreach()有两种用法: foreach(array_name as $value) { statement; } 这里的array_na ...
- 30 个 php 操作 redis 常用方法代码例子
这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类型. list 类型和 set 类型的数据 , 需要的朋友可以参 ...
- Linux操作系统进程模型分析进程
Linux操作系统简介 Linux拥有现代操作系统的功能,如真正的抢先式多任务处理,支持多用户内存,保护虚拟内存,支持SMP.UP,符合POSIX 标准联网.图形用户接口和桌面环境具有快速性.稳定性等 ...
- C# FTP操作类的代码
如下代码是关于C# FTP操作类的代码.using System;using System.Collections.Generic;using System.Text;using System.Net ...
随机推荐
- Nginx + IIS
Nginx + IIS 配置,实现负载均衡 当你的Web应用程序访问量大的时候,一台服务器可能会因为压力过大而无法处理所有的请求.此时,可以增加服务器,采用负载均衡来分担所有的请求.关于Nginx ...
- UVa 10491 - Cows and Cars
題目:有m+n個們,每個門後面有牛或者車:有n仅仅牛,m輛車,你選擇当中1個: 然後打開当中的k你沒有選中的門後是牛的,問你改變選時得到車的概率. 說明:數學題,概率.全概率公式就可以: 說明:第10 ...
- RH253读书笔记(5)-Lab 5 Network File Sharing Services
Lab 5 Network File Sharing Services Goal: Share file or printer resources with FTP, NFS and Samba Se ...
- IOS-Plist文件存储(1)
1.什么是一个文件系统? IOS每个应用程序都有自己的文件系统.并且有一个相应的接入,一般分 ~/Documents/ ~/tmp/ ~/Library/Caches/ ~/Library/Prefe ...
- PE文件结构(四) 输出表
PE文件结构(四) 參考 书:<加密与解密> 视频:小甲鱼 解密系列 视频 输出表 一般来说输出表存在于dll中.输出表提供了 文件里函数的名字跟这些函数的地址, PE装载器通过输出表来改 ...
- MEF初体验之二:定义组合部件和契约
组合部件 在MEF中,一个组合部件就是一个组合单元,组合部件"出口"其它组合部件需要的服务并且从其它部件"进口"需要的服务.在MEF编程模型中,为了声明组合部件 ...
- hibernate 双向n-n
领域模型: 关系数据模型 双向 n-n 关联须要两端都使用集合属性 双向n-n关联必须使用连接表 集合属性应添加 key 子元素用以映射外键列, 集合元素里还应添加many-to-many子元素关联实 ...
- 在win7在结构cocos2d-x v3.2rc0开发环境(For Android)
cocos2d-x 这是现在比较流行的游戏引擎., 因此.本文的目的在于教导新手怎样在win7下建立cocos2dx开发环境, 截止本文,cocos2dx的最新版本号为 v3.2rc0版,我将如果您的 ...
- [ExtJS5学习笔记]第22 Extjs5正在使用beforeLabelTpl添加所需的配置选项标注星号标记
本文地址:http://blog.csdn.net/sushengmiyan/article/details/39395753 官方样例:http://docs.sencha.com/extjs/5. ...
- 用Unicode迎接未来
项目中使用了emoji,然后,问题产生了,后端MySQL数据库无法存储emoji字符,悲了个剧. emoji是Unicode字符集的子集,Unicode的使用应该非常普遍了,怎么会 ...