杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2154|回复: 0

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

[复制链接]
发表于 2017-3-1 15:20:37 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. /**********************************************************************************
  2. /* GetRunningApp();
  3. /* ShutDownApp();
  4. /*
  5. /* These script created functions will look for any running application based on
  6. /* the file name, then display an error message within the Setup. You can optionally
  7. /* halt the install or just continue on.
  8. /*
  9. /* You can use the ShutDownApp() function for shutting down that process or others
  10. /* as well. This is useful for processes that run in the background but have no Windows
  11. /* associated with them. May not work with Services.
  12. /*
  13. /* This script calls functions in PSAPI.DLL that are not supported on Windows 95 or 98.
  14. /*
  15. /* ***Instructions***
  16. /* Place these script peices into the Setup.rul file.
  17. /*
  18. /* Modify the script to include the applications you would like to get or shutdown.
  19. /*
  20. /* Submitted by William F. Snodgrass
  21. /* Contact info: bsnodgrass@geographix.com
  22. /*
  23. /* Created by Theron Welch, 3/3/99
  24. /* Minor modifications by Stefan Krueger, 11/03/99
  25. /*
  26. /* Copyright (c) 1999-2000 GeoGraphix, Inc.
  27. **********************************************************************************/

  28. //////////////////// installation declarations ///////////////////

  29. // ----- DLL function prototypes -----

  30. // your DLL function prototypes
  31.    
  32. // Custom function for shutting down MyApp process
  33. prototype ShutDownApp();

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

  36. ///////////////////////////////////////////////////////////////////////////////////
  37. // Dll function calls needed

  38. // Kernel functions
  39. 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
  40. prototype BOOL Kernel32.TerminateProcess( LONG, INT );   // 1st Param = Process ID, 2nd = Doesn't matter - "0"

  41. // Process info functions
  42. 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"
  43. prototype LONG Psapi.GetModuleFileNameExA( LONG, LONG, POINTER, LONG );// 1st Param = ProcessID, 2nd= Module ID, 3rd = pointer to a string, 4th = length of string
  44. 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")
  45. ///////////////////////////////////////////////////////////////////////////////////

  46. // your global variables
  47. STRING    svApp

  48. program

  49.    if ( 1 == GetRunningApp ( svApp ) ) then
  50.         MessageBox ( "The installation has detected that " + svApp + " is running. " +
  51.                  "Please close " + svApp + " then restart the installation process.", SEVERE );
  52.         abort;
  53.    endif;
  54.    
  55.    if ( 0 == ShutDownProjectManager() ) goto end_install; // This statement is within the Program block and jumps to the
  56.                                    "end_install:" switch if the function fails. -WFS
  57.                                    
  58. endprogram

  59. ///////////////////////////////////////////////////////////////////////////////////
  60. //
  61. // Function: GetRunningApp
  62. //
  63. // Purpose: This function returns "1" if an app is running.  Otherwise "0".
  64. //    If "1" is returned, the "appName" parameter will contain the name of the
  65. //    application running.
  66. //
  67. // Theron Welch 3/3/99
  68. //
  69. ///////////////////////////////////////////////////////////////////////////////////
  70. function GetRunningApp( appName )
  71.     HWND hWnd;
  72.     LONG ProcessIDs[ 512 ];                // An array that's hopefully big enough to hold all process IDs
  73.     LONG cbNeeded;
  74.     LONG cb;
  75.     LONG numItems;
  76.     LONG ProcessHandle;
  77.     LONG ModuleHandle;
  78.     LONG Count;
  79.     LONG Ret;
  80.     LONG Ret2;
  81.     POINTER pArray;                    // This pointer will point at the array of process IDs
  82.     STRING ModuleName[ 128 ];
  83.     STRING FileName[ 64 ];
  84.     POINTER pModuleName;
  85. begin

  86.     UseDLL ( WINSYSDIR ^ "Psapi.dll" );    // Load the helper dll - PsApi.dll
  87.    
  88.     cbNeeded = 96;
  89.     cb = 8;
  90.    
  91.     pArray = &ProcessIDs;                // Point at the array
  92.    
  93.     while ( cb <= cbNeeded )
  94.         cb = cb * 2;
  95.         EnumProcesses ( pArray, cb, cbNeeded ); // Get the currently running process IDs
  96.     endwhile;
  97.     numItems = cbNeeded / 4;            // Calculate number of process IDs - 4 is the size in bytes of a Process ID (DWORD)
  98.         
  99.     for Count = 1 to numItems            // For each process id

  100.         ProcessHandle = OpenProcess ( 2035711, 1, ProcessIDs[ Count ] ); // Get a handle to the process
  101.         if ( 0 != ProcessHandle ) then
  102.             
  103.             Ret = EnumProcessModules ( ProcessHandle, ModuleHandle, 4, cb ); // Get the module handle - first one is EXE, the one I care about!
  104.             if ( 0 != Ret ) then

  105.                 pModuleName = &ModuleName;    // Point at the array
  106.                 Ret = GetModuleFileNameExA ( ProcessHandle, ModuleHandle, pModuleName, 128 ); // Get the exe name
  107.                 if ( 0 != Ret ) then
  108.                
  109.                     ParsePath ( FileName, ModuleName, FILENAME_ONLY ); // Convert the full path to a filename

  110.                     //////////////////////////////Outlook/////////////////////////////////////////
  111.                     // Copy the next 5 lines and customize for each app
  112.                     Ret = StrCompare ( FileName, "Outlook" );
  113.                     if ( 0 == Ret  ) then    // If there's a match
  114.                         FileName = "Microsoft Outlook"; // Change to a name that makes sense
  115.                         appName = FileName;        // Copy the filename to the passed in parameter (by ref)
  116.                         return 1;            // Return "Found"
  117.                     endif;
  118.                     ///////////////////////////////////////////////////////////////////////////////

  119.                     //////////////////////////////Navwnt/////////////////////////////////////////
  120.                     Ret = StrCompare ( FileName, "Navwnt" );
  121.                     if ( 0 == Ret  ) then    // If there's a match
  122.                         FileName = "Norton Anti-Virus"; // Change to a name that makes sense
  123.                         appName = FileName;        // Copy the filename to the passed in parameter (by ref)
  124.                         return 1;            // Return "Found"
  125.                     endif;
  126.                     ///////////////////////////////////////////////////////////////////////////////
  127.                 endif;
  128.             endif;
  129.         endif;
  130.     endfor;   
  131.     return 0;    // "Well, uh, apparently, no application is running"
  132. end;

  133. ///////////////////////////////////////////////////////////////////////////////////
  134. //
  135. // Function: ShutDownApp
  136. //
  137. // Purpose: This function attempts to shut down the app you decide on.  It returns
  138. //        "1" if successful or if app is not running.
  139. //        Otherwise "0" if it could not be shut down.  Install should terminate
  140. //        if "0" is returned.
  141. //
  142. // Theron Welch 3/3/99
  143. //
  144. ///////////////////////////////////////////////////////////////////////////////////

  145. function ShutDownApp()
  146.     HWND hWnd;
  147.     LONG ProcessIDs[ 512 ];                // An array that's hopefully big enough to hold all process IDs
  148.     LONG cbNeeded;
  149.     LONG cb;
  150.     LONG numItems;
  151.     LONG ProcessHandle;
  152.     LONG ModuleHandle;
  153.     LONG Count;
  154.     LONG Ret;
  155.     LONG Ret2;
  156.     POINTER pArray;                    // This pointer will point at the array of process IDs
  157.     STRING ModuleName[ 128 ];
  158.     STRING FileName[ 64 ];
  159.     POINTER pModuleName;
  160. begin

  161.     UseDLL ( WINSYSDIR ^ "Psapi.dll" );        // Load the helper dll - PsApi.dll
  162.    
  163.     cbNeeded = 96;
  164.     cb = 8;
  165.    
  166.     pArray = &ProcessIDs;                // Point at the array
  167.    
  168.     while ( cb <= cbNeeded )
  169.         cb = cb * 2;
  170.         EnumProcesses ( pArray, cb, cbNeeded ); // Get the currently running process IDs
  171.     endwhile;
  172.     numItems = cbNeeded / 4;            // Calculate number of process IDs - 4 is the size in bytes of a Process ID (DWORD)
  173.         
  174.     for Count = 1 to numItems            // For each process id

  175.         ProcessHandle = OpenProcess ( 2035711, 1, ProcessIDs[ Count ] ); // Get a handle to the process
  176.         if ( 0 != ProcessHandle ) then
  177.             
  178.             Ret = EnumProcessModules ( ProcessHandle, ModuleHandle, 4, cb ); // Get the module handle - first one is EXE, the one I care about!
  179.             if ( 0 != Ret ) then

  180.                 pModuleName = &ModuleName;    // Point at the array
  181.                 Ret = GetModuleFileNameExA ( ProcessHandle, ModuleHandle, pModuleName, 128 ); // Get the exe name
  182.                 if ( 0 != Ret ) then
  183.                
  184.                     ParsePath ( FileName, ModuleName, FILENAME );     // Convert the full path to a filename
  185.                     // MessageBox( FileName, INFORMATION );
  186.                     Ret = StrCompare ( FileName, "MYAPP~1.EXE" );    // Compare filenames (used for short file names. -WFS)
  187.                     Ret2 = StrCompare ( FileName, "MYAPP.exe" );    // Compare filenames
  188.                     if ( 0 == Ret || 0 == Ret2 ) then            // If it's the filename I'm looking for
  189.                         Ret = TerminateProcess( ProcessHandle, 0 );    // Terminate the process
  190.                         if ( 0 == Ret ) then
  191.                             goto Error;
  192.                         endif;
  193.                         goto Quit;
  194.                 endif;
  195.                
  196.                 endif;
  197.                
  198.             endif;
  199.                
  200.         endif;

  201.     endfor;   
  202.    
  203.     Quit:
  204.    
  205.     UnUseDLL ( "Psapi.dll" );    // Unload the helper dll - PsApi.dll                    
  206.     return 1;    // Happy
  207.    
  208.     Error:
  209.    
  210.     UnUseDLL ( "Psapi.dll" );    // Unload the helper dll - PsApi.dll                    
  211.     return 0;    // Sad

  212. end;
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-14 07:29 , Processed in 0.115315 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表