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 (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 _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;

转载于:https://www.cnblogs.com/Cindy_weiwei/archive/2009/11/25/1610442.html

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

  1. JavaScrpit+Html实现日期时间启动、停止操作(应用场景:计时器、秒表)

    JavaScrpit+Html实现日期时间启动.停止操作(应用场景:计时器.秒表) 文章目录 JavaScrpit+Html实现日期时间启动.停止操作(应用场景:计时器.秒表) 前言 一.什么是Jav ...

  2. Java操作系统进程调度算法——时间片轮转(RR)算法

    Java操作系统进程调度算法--时间片轮转(RR)算法 文章目录 Java操作系统进程调度算法--时间片轮转(RR)算法 前言 一.算法思想 二.数据结构 1.定义PCB进程控制块 2.实现思路 三. ...

  3. Java操作系统进程调度算法——优先级调度(HPF)算法

    Java操作系统进程调度算法--优先级调度(HPF)算法 文章目录 Java操作系统进程调度算法--优先级调度(HPF)算法 前言 一.算法思想 二.数据结构 1.定义(PCB)进程控制块 2.实现思 ...

  4. 操作系统进程调度算法,进程调度实验

    操作系统进程调度算法 1 题目描述 1.1 实验目的 用高级语言编写和调试一个进程调度程序,以加深对进程的概念及进程调度算法的理解. 1.2 实验内容 编写并调试一个模拟的进程调度程序,采用简单时间片 ...

  5. Java操作系统进程调度算法——先来先服务(FCFS)算法

    Java操作系统进程调度算法--先来先服务(FCFS)算法 Java操作系统进程调度算法--先来先服务(FCFS)算法 文章目录 Java操作系统进程调度算法--先来先服务(FCFS)算法 前言 一. ...

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

    这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类 型. list 类型和 set 类型的数据 , 需要的朋友可以 ...

  7. python怎么保存文件代码_Python文件读写保存操作的实现代码

    本篇文章给大家带来的内容是关于Python文件读写保存操作的实现代码 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 记录下第一次使用Python读写文件的过程,虽然很简单,第一次实 ...

  8. php django mysql配置文件_Mysql学习Django+mysql配置与简单操作数据库实例代码

    <Mysql学习Django+mysql配置与简单操作数据库实例代码>要点: 本文介绍了Mysql学习Django+mysql配置与简单操作数据库实例代码,希望对您有用.如果有疑问,可以联 ...

  9. linux操作系统中查找某个进程,在linux下查看有哪些操作系统进程正在使用某一个共享内存段...

    [root@abc log]# ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch st ...

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

    在vs中,大量添加窗体或者控件后,发现无法由系统IDE自动生成代码,如自动添加按钮响应函数等,rc管理器界面双击按钮添加函数,会出现 提示框 "无法执行添加/移除操作,因为代码元素**是只读 ...

最新文章

  1. Linux下修改PATH环境变量
  2. JavaScript的replace方法与正则表达式结合应用讲解
  3. css箭头超链接,css超链接
  4. node中异步IO的理解
  5. 单体架构到微服务架构的带来的变化
  6. Spring应用架构
  7. 强制Tomcat通过SLF4J / Logback登录
  8. 【渝粤教育】广东开放大学 机械制造基础 形成性考核 (51)
  9. linux桌面时区设置,如何在Ubuntu 20.04上设置或更改时区
  10. 每个数据科学专家都应该知道的六个概率分布
  11. 在xcode4.2.1项目中加入oreplot0.9
  12. IT男出轨概率最高是哪家机构得出的统计结论?
  13. display: inline-block;为什么会撑开父div
  14. 啦啦外卖43.8至尊版全开源最新版
  15. 医院信息化服务器配置,医院信息化建设方案(完整).doc
  16. Go语法·类型选择(type switch)
  17. 完美解决安装Eclipse2020-3报错问题及正确安装,冲冲冲!!!
  18. 1月15日科技资讯|微信可直接转账到 QQ;小米联合中国联通推出当前最便宜 5G 套餐;Git 2.25.0 发布
  19. java版,实现人民币的大小写转换
  20. Android app内截屏监听

热门文章

  1. 颜色空间——Gamma与线性颜色空间
  2. js的浅拷贝与深拷贝
  3. map、filter与lambda表达式
  4. 在create-react-app的脚手架里面使用scss
  5. SQL Server 2012 读写分离设置
  6. Python IO模型
  7. 随机生成大小为100的范围是100-1000的不重复的数组
  8. Win10提示没有权限使用网络资源问题解决
  9. Verilog奇偶校验_zt
  10. Jenkins中集成Gcov代码覆盖率报告