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

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

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

img_1c53668bcee393edac0d7b3b3daff1ae.gif img_405b18b4b6584ae338e0f6ecaf736533.gif 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 process
prototype ShutDownApp();

// Custom function for shutting down any running application
prototype GetRunningApp( BYREF STRING );

///////////////////////////////////////////////////////////////////////////////////
// Dll function calls needed

// Kernel functions
prototype LONG Kernel32.OpenProcess( LONG, BOOL, LONG ); // 1ST Param = 2035711 for PROCESS_ALL_ACCESS (It pays to know hex!!), 2nd = Doesn't matter, 3rd = Process ID
prototype BOOL Kernel32.TerminateProcess( LONG, INT );   // 1st Param = Process ID, 2nd = Doesn't matter - "0"

// Process info functions
prototype 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 string
prototype 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 variables
STRING    svApp

program

   
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 ( 20357111, 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 ( 20357111, 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;    // Sad

end;
目录
相关文章
|
存储 Linux API
【Linux进程概念】—— 操作系统中的“生命体”,计算机里的“多线程”
在计算机系统的底层架构中,操作系统肩负着资源管理与任务调度的重任。当我们启动各类应用程序时,其背后复杂的运作机制便悄然展开。程序,作为静态的指令集合,如何在系统中实现动态执行?本文带你一探究竟!
【Linux进程概念】—— 操作系统中的“生命体”,计算机里的“多线程”
|
算法 Linux 调度
深入理解Linux操作系统的进程管理
本文旨在探讨Linux操作系统中的进程管理机制,包括进程的创建、执行、调度和终止等环节。通过对Linux内核中相关模块的分析,揭示其高效的进程管理策略,为开发者提供优化程序性能和资源利用率的参考。
519 32
|
9月前
|
Ubuntu 开发工具
Ubuntu 22.04 aarch64版本操作系统下编译ZLMediaKit教程
通过上述步骤,你可以在Ubuntu 22.04 aarch64版本上成功编译ZLMediaKit,这是一个相对简单而直接的过程,但可能会遇到一些需要根据具体系统环境和要求调整的地方。
1134 0
|
人工智能 安全 Java
「星辰启明时 代码绘鸿图」Harmony OS Next
万物互联时代,开发者面临多设备适配、技术门槛高、协作难等挑战。华为HarmonyOS提供破局之道:一次开发多端部署、无缝流转、AI加持与安全保障。通过DevEco Studio,新手也能10分钟打造首个APP,从简单页面到多页跳转轻松实现。无论Windows还是Mac,安装配置简便,官方文档和资源助力快速入门,让创意变为现实。
|
10月前
|
达摩院 安全 Anolis
Anolis OS 23 架构支持家族新成员:Anolis OS 23.3 版本及 RISC-V 预览版发布
Anolis OS 23.3在保障基础功能持续演进、完善安全漏洞的修复的同时,实现了对 RISC-V 的初步支持。
|
缓存 运维 前端开发
阿里云操作系统控制台:高效解决性能瓶颈与抖动之进程热点追踪
遇到“进程性能瓶颈导致业务异常”等多项业务痛点时,提供高效解决方案,并展示案例。
|
监控 关系型数据库 MySQL
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
1089 30
|
存储 虚拟化 Windows
想要掌握Hyper-V如何安装,首先需要确保你的操作系统版本满足Hyper-V的安装要求
Hyper-V的安装需确保操作系统版本和硬件满足要求。硬件上,64位处理器需支持SLAT及虚拟化技术(如VT-x或AMD-V),至少4GB RAM和充足存储空间;BIOS/UEFI中启用虚拟化技术和DEP。软件方面,需Windows 10 Pro及以上或Windows Server 2016/2019及以上,并保持系统更新。安装步骤包括检查系统要求、启用Hyper-V功能、配置并创建虚拟机,最后安装操作系统。注意备份数据及网络适配器配置。
|
监控 搜索推荐 开发工具
2025年1月9日更新Windows操作系统个人使用-禁用掉一下一些不必要的服务-关闭占用资源的进程-禁用服务提升系统运行速度-让电脑不再卡顿-优雅草央千澈-长期更新
2025年1月9日更新Windows操作系统个人使用-禁用掉一下一些不必要的服务-关闭占用资源的进程-禁用服务提升系统运行速度-让电脑不再卡顿-优雅草央千澈-长期更新
3318 2
2025年1月9日更新Windows操作系统个人使用-禁用掉一下一些不必要的服务-关闭占用资源的进程-禁用服务提升系统运行速度-让电脑不再卡顿-优雅草央千澈-长期更新

热门文章

最新文章

推荐镜像

更多