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 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 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 ([email protected]).
//
// 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: [email protected]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 _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(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及以上版本适用

时间: 2024-08-02 00:40:30

Installshield停止操作系统进程的代码 --IS6及以上版本适用的相关文章

Installshield停止操作系统进程的代码--IS5版本适用

原文:Installshield停止操作系统进程的代码--IS5版本适用 出处:http://www.installsite.org/pages/en/isp_ext.htm这个地址上有不少好东西,有空要好好研究下里面的“List and Shut Down Running Applications”就是演示了Installshield如何停止操作系统进程 Code/*****************************************************************

(转)几个常用的操作系统进程调度算法

几个常用的操作系统进程调度算法 转自:http://blog.csdn.net/wanghao109/article/details/13004507 一.先来先服务和短作业(进程)优先调度算法 1.先来先服务调度算法 先来先服务(FCFS)调度算法是一种最简单的调度算法,该算法既可用于作业调度,也可用于进程调度.当在作业调度中采用该算法时,每次调度都是从后备作业队列中选择一个或多个最先进入该队列的作业,将它们调入内存,为它们分配资源.创建进程,然后放入就绪队列.在进程调度中采用FCFS算法时,

jquery操作单选钮代码示例

jquery操作单选钮代码示例:radio单选按钮是最重要的表单元素之一,下面介绍一下常用的几个jquery对radio单选按钮操作.一.取消选中: $(".theclass").each(function(){ if($(this).attr('checked')) { $(this).attr('checked',false); } }); 以上代码可以将class属性值为theclass的被选中单选按钮取消选中.二.获取被选中的单选按钮的值: var val=$('.thecla

ios多线程操作(七)—— GCD延迟操作与一次性代码

使用GCD函数可以进行延时操作,该函数为 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ }); 现在我们来分解一下参数 dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)) : NSEC_PER_SEC在头文

30 个 php 操作 redis 常用方法代码例子

这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类型. list 类型和 set 类型的数据 , 需要的朋友可以参考下redis 的操作很多的,以前看到一个比较全的博客,但是现在找不到了.查个东西搜半天,下面整理一下php 处理 redis 的例子,个人觉得常用一些例子.下面的例子都是基于 php-redis 这个扩展的.1 , connect描述:实例连接到一个 Redis.参数: host: string

AD帐户操作C#示例代码(一)——导入用户信息

最近写了一个AD帐户导入的小工具(为啥写作“帐”户呢?),跟大家分享下相关代码,欢迎各位高手指教! 首先,我准备一个这样的Excel文件作为导入模版,并添加了一些测试数据. 然后,我打开Visual Studio 2012,新建一个Windows窗体应用程序.在主窗体界面,我放了一些Label.TextBox.Button控件,还有一个ProgressBar. 开始写代码.首先写从Excel里读取数据的方法. private static async Task<DataTable> GetTa

无法执行添加/移除操作,因为代码元素 是只读的

刚刚学习用MFC编写嵌入式软件,各种问题接踵而来啊,在资源选项卡里面新建一个dialog后拖进去一个button按钮,想要添加这个空间的时间相应却怎么也不成功.会出现 提示框 “无法执行添加/移除操作,因为代码元素**是只读的”.根据提示去查看对应的.cpp和.h文件,发现并没有只读属性,没办法,求助于网络,发现这个问题还是挺普遍的,参考这篇文章后,保存现有工程后,在目录里面删掉.ncb文件后重新打开解决方案,问题解决. 另外还碰到一个情况,就是在属性栏点击“控件事件”后列表为空,不应该啊,比对

AD帐户操作C#示例代码(二)——检查密码将过期的用户

本文接着和大家分享AD帐户操作,这次开发一个简单的检查密码将过期用户的小工具. 首先,新建一个用户实体类,属性是我们要取的用户信息. public class UserInfo { /// <summary> /// sAM帐户名称 /// </summary> public string SamAccountName { get; set; } /// <summary> /// 名称 /// </summary> public string Name {

Linux下互斥量加锁与解锁操作的C代码实现

一.概述 在实际的软件程序中,由于代码量较大,函数之间的调用关系较为复杂,因此对于某些全局变量的操作要格外小心.在程序中,一般采用互斥量加锁的方式来保证对全局变量的操作的唯一性. 本文详细介绍了Linux下互斥量加锁与解锁操作的C代码实现,为相关的软件开发工作的开展提供了有益的参考. 二.加锁与解锁函数及时间结构体介绍 1.加锁函数pthread_mutex_timedlock 函数原型:int pthread_mutex_timedlock(pthread_mutex_t *restrict