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

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

Code/**********************************************************************************/* 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. **********************************************************************************///////////////////// installation declarations ///////////////////// ----- DLL function prototypes -----// your DLL function prototypes    // Custom function for shutting down MyApp processprototype ShutDownApp();// Custom function for shutting down any running applicationprototype GetRunningApp( BYREF STRING );///////////////////////////////////////////////////////////////////////////////////// Dll function calls needed// Kernel functionsprototype LONG Kernel32.OpenProcess( LONG, BOOL, LONG ); // 1ST Param = 2035711 for PROCESS_ALL_ACCESS (It pays to know hex!!), 2nd = Doesn't matter, 3rd = Process IDprototype BOOL Kernel32.TerminateProcess( LONG, INT );   // 1st Param = Process ID, 2nd = Doesn't matter - "0"// Process info functionsprototype LONG Psapi.EnumProcesses( POINTER, LONG, BYREF LONG );  // 1st Param = By ref, Process ID, 2nd = number of bytes in param 1 = "4", 3rd = cb needed - might as well be "4"prototype LONG Psapi.GetModuleFileNameExA( LONG, LONG, POINTER, LONG );// 1st Param = ProcessID, 2nd= Module ID, 3rd = pointer to a string, 4th = length of stringprototype LONG Psapi.EnumProcessModules( LONG, BYREF LONG, LONG, BYREF LONG ); // 1st Param = Process Handle, 2nd = Module Handle, 3rd = bytes passed ("4"), 4th = bytes needed ("4")///////////////////////////////////////////////////////////////////////////////////// your global variablesSTRING    svAppprogram   if ( 1 == GetRunningApp ( svApp ) ) then        MessageBox ( "The installation has detected that " + svApp + " is running. " +                 "Please close " + svApp + " then restart the installation process.", SEVERE );        abort;   endif;      if ( 0 == ShutDownProjectManager() ) goto end_install; // This statement is within the Program block and jumps to the                                   "end_install:" switch if the function fails. -WFS                                   endprogram/////////////////////////////////////////////////////////////////////////////////////// Function: GetRunningApp//// Purpose: This function returns "1" if an app is running.  Otherwise "0".//    If "1" is returned, the "appName" parameter will contain the name of the //    application running.//// Theron Welch 3/3/99/////////////////////////////////////////////////////////////////////////////////////function GetRunningApp( appName )    HWND hWnd;    LONG ProcessIDs[ 512 ];                // An array that's hopefully big enough to hold all process IDs    LONG cbNeeded;    LONG cb;    LONG numItems;    LONG ProcessHandle;    LONG ModuleHandle;    LONG Count;    LONG Ret;    LONG Ret2;    POINTER pArray;                    // This pointer will point at the array of process IDs    STRING ModuleName[ 128 ];    STRING FileName[ 64 ];    POINTER pModuleName;begin    UseDLL ( WINSYSDIR ^ "Psapi.dll" );    // Load the helper dll - PsApi.dll        cbNeeded = 96;    cb = 8;        pArray = &ProcessIDs;                // Point at the array        while ( cb <= cbNeeded )        cb = cb * 2;        EnumProcesses ( pArray, cb, cbNeeded ); // Get the currently running process IDs    endwhile;    numItems = cbNeeded / 4;            // Calculate number of process IDs - 4 is the size in bytes of a Process ID (DWORD)            for Count = 1 to numItems            // For each process id        ProcessHandle = OpenProcess ( 2035711, 1, ProcessIDs[ Count ] ); // Get a handle to the process        if ( 0 != ProcessHandle ) then                        Ret = EnumProcessModules ( ProcessHandle, ModuleHandle, 4, cb ); // Get the module handle - first one is EXE, the one I care about!            if ( 0 != Ret ) then                pModuleName = &ModuleName;    // Point at the array                Ret = GetModuleFileNameExA ( ProcessHandle, ModuleHandle, pModuleName, 128 ); // Get the exe name                if ( 0 != Ret ) then                                    ParsePath ( FileName, ModuleName, FILENAME_ONLY ); // Convert the full path to a filename                    //////////////////////////////Outlook/////////////////////////////////////////                    // Copy the next 5 lines and customize for each app                    Ret = StrCompare ( FileName, "Outlook" );                    if ( 0 == Ret  ) then    // If there's a match                        FileName = "Microsoft Outlook"; // Change to a name that makes sense                        appName = FileName;        // Copy the filename to the passed in parameter (by ref)                        return 1;            // Return "Found"                    endif;                    ///////////////////////////////////////////////////////////////////////////////                    //////////////////////////////Navwnt/////////////////////////////////////////                    Ret = StrCompare ( FileName, "Navwnt" );                    if ( 0 == Ret  ) then    // If there's a match                        FileName = "Norton Anti-Virus"; // Change to a name that makes sense                        appName = FileName;        // Copy the filename to the passed in parameter (by ref)                        return 1;            // Return "Found"                    endif;                    ///////////////////////////////////////////////////////////////////////////////                endif;            endif;        endif;    endfor;        return 0;    // "Well, uh, apparently, no application is running"end;/////////////////////////////////////////////////////////////////////////////////////// Function: ShutDownApp//// Purpose: This function attempts to shut down the app you decide on.  It returns//        "1" if successful or if app is not running.//        Otherwise "0" if it could not be shut down.  Install should terminate//        if "0" is returned.//// Theron Welch 3/3/99/////////////////////////////////////////////////////////////////////////////////////function ShutDownApp()    HWND hWnd;    LONG ProcessIDs[ 512 ];                // An array that's hopefully big enough to hold all process IDs    LONG cbNeeded;    LONG cb;    LONG numItems;    LONG ProcessHandle;    LONG ModuleHandle;    LONG Count;    LONG Ret;    LONG Ret2;    POINTER pArray;                    // This pointer will point at the array of process IDs    STRING ModuleName[ 128 ];    STRING FileName[ 64 ];    POINTER pModuleName;begin    UseDLL ( WINSYSDIR ^ "Psapi.dll" );        // Load the helper dll - PsApi.dll        cbNeeded = 96;    cb = 8;        pArray = &ProcessIDs;                // Point at the array        while ( cb <= cbNeeded )        cb = cb * 2;        EnumProcesses ( pArray, cb, cbNeeded ); // Get the currently running process IDs    endwhile;    numItems = cbNeeded / 4;            // Calculate number of process IDs - 4 is the size in bytes of a Process ID (DWORD)            for Count = 1 to numItems            // For each process id        ProcessHandle = OpenProcess ( 2035711, 1, ProcessIDs[ Count ] ); // Get a handle to the process        if ( 0 != ProcessHandle ) then                        Ret = EnumProcessModules ( ProcessHandle, ModuleHandle, 4, cb ); // Get the module handle - first one is EXE, the one I care about!            if ( 0 != Ret ) then                pModuleName = &ModuleName;    // Point at the array                Ret = GetModuleFileNameExA ( ProcessHandle, ModuleHandle, pModuleName, 128 ); // Get the exe name                if ( 0 != Ret ) then                                    ParsePath ( FileName, ModuleName, FILENAME );     // Convert the full path to a filename                    // MessageBox( FileName, INFORMATION );                    Ret = StrCompare ( FileName, "MYAPP~1.EXE" );    // Compare filenames (used for short file names. -WFS)                    Ret2 = StrCompare ( FileName, "MYAPP.exe" );    // Compare filenames                    if ( 0 == Ret || 0 == Ret2 ) then            // If it's the filename I'm looking for                        Ret = TerminateProcess( ProcessHandle, 0 );    // Terminate the process                        if ( 0 == Ret ) then                            goto Error;                        endif;                        goto Quit;                endif;                                endif;                            endif;                        endif;    endfor;            Quit:        UnUseDLL ( "Psapi.dll" );    // Unload the helper dll - PsApi.dll                        return 1;    // Happy        Error:        UnUseDLL ( "Psapi.dll" );    // Unload the helper dll - PsApi.dll                        return 0;    // Sadend;

Installshield停止操作系统进程的代码--IS5版本适用的更多相关文章

  1. Installshield停止操作系统进程的代码 --IS6及以上版本适用

    原文:Installshield停止操作系统进程的代码 --IS6及以上版本适用 setup.rul的代码 Code;end;///////////////////////////////////// ...

  2. Redis:安装、配置、操作和简单代码实例(C语言Client端)

    Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...

  3. C#开发中使用Npoi操作excel实例代码

    C#开发中使用Npoi操作excel实例代码 出处:西西整理 作者:西西 日期:2012/11/16 9:35:50 [大 中 小] 评论: 0 | 我要发表看法 Npoi 是什么? 1.整个Exce ...

  4. 全面吃透JAVA Stream流操作,让代码更加的优雅

    全面吃透JAVA Stream流操作,让代码更加的优雅 在JAVA中,涉及到对数组.Collection等集合类中的元素进行操作的时候,通常会通过循环的方式进行逐个处理,或者使用Stream的方式进行 ...

  5. SELECT控件操作的JS代码示例

    SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...

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

    From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...

  7. php foreach 操作数组的代码

    php foreach 操作数组的代码.   foreach()有两种用法:  foreach(array_name as $value)  {  statement;  }  这里的array_na ...

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

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

  9. Linux操作系统进程模型分析进程

    Linux操作系统简介 Linux拥有现代操作系统的功能,如真正的抢先式多任务处理,支持多用户内存,保护虚拟内存,支持SMP.UP,符合POSIX 标准联网.图形用户接口和桌面环境具有快速性.稳定性等 ...

随机推荐

  1. Spring Framework 下载链接_现在有空

    下载链接:http://repo.spring.io/libs-release-local/org/springframework/spring/ 点击打开链接 包括Spring的各个版本号: 3.2 ...

  2. 使用RESTClient插件数据模拟(GET,POST)提交

    1:在Firefox下载RESTClient插件安装 2:安装界面后, 3:点击设置头文件:(设请求地址有头部文件) 4:设置界面,当然有非常多选择.依据你的须要.一般在输入的时候有智能提示,我这里以 ...

  3. iOS一个开发系列中 - UIButton 使用摘要

    // 初始化button并设置类型 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 可以定义的UIButto ...

  4. vim cheat sheet

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzE1Mjg5NQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  5. Linux内核进程管理

    介绍: 在Linux的内核的五大组成模块中,进程管理模块时很重要的一部分.它尽管不像内存管理.虚拟文件系统等模块那样复杂.也不像进程间通信模块那样条理化,但作为五大内核模块之中的一个,进程管理对我们理 ...

  6. Struts2_1_struts2建立一个执行环境

    1)最低需要进口jar包: commons-fileupload-1.2.1.jar.commons-logging-1.0.4.jar. freemarker-2.3.15.jar.ognl-2.7 ...

  7. Redis源代码分析(二十)--- ae事件驱动

    事件驱动的术语出现更频繁.听起来非常大的,今天我把Redis内部驱动器模型来研究它,奖励的感觉啊.一个ae.c主程序,加4文件的事件类型,让你彻底弄清楚,Redis是怎样处理这些事件的. 在Redis ...

  8. Oracle 数据恢复指导具体解释

    1.数据恢复指导 : 高速检測.分析和修复故障 最大程度地降低停机故障和执行时故障 将对用户的干扰降到最低 用户界面:    --EM GUI 界面 (多个路径)    --RMAN 命令行 支持的数 ...

  9. zoj 3659 并检查集合

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4882 现在在牡丹江,明天regional直播比赛,我会在一个月内退休.求祝福 ...

  10. 运营商网络採用SDN所面临的挑战(一)

    运营商网络採用SDN所面临的挑战(一) Babak Samimi 将数据平面.控制平面与管理平面分隔开来所实现的软件定义网络(SDN)改善了OPEX及CAPEX,而且使得网络资源的集中调配和管理成为可 ...