/build/static/layout/Breadcrumb_cap_w.png

installscript kill exe in Win2008

Hi
I want to kill an exe before I uninstall.
I am using uninstall script code which worked fine on windows server 2003, but is not working consistently on windows server 2008 R2. ( I works sometimes but not always)

I've noticed that when it does not work, that it returning the number of processes running as 128( which seems a suspiciously round computer number)

Anyone got any ideas?

Thank you in advance



// Process information functions.

prototype NUMBER Kernel32.K32EnumProcesses(POINTER, NUMBER, BYREF NUMBER);
prototype NUMBER Kernel32.K32EnumProcessModules(NUMBER, BYREF NUMBER, NUMBER,
BYREF NUMBER);
prototype NUMBER Kernel32.K32GetModuleFileNameEx(NUMBER, NUMBER, BYREF STRING,
NUMBER);

//////////////////////////////////////////////////////////////////////////////
//
// Function: _Process_Running
//
// Description: Determines if the specified process is running in memory.
//
// Parameters: szAppName - Name of the application to check.
//
// Returns: 1 - The process is running.
// 0 - The process is not running.
// -1 - Error querying task list
//
//////////////////////////////////////////////////////////////////////////////

function NUMBER ProcessRunning(hMSI,szAppName)
NUMBER nvRunning; // 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
STRING szMessage; // Message String
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.

WriteToLogFile(hMSI,"ERROR: Could not load [" + WINSYSDIR ^ PSAPI_FILE +
"]. Rolling back uninstall");

return -1;
endif;

// Get the PIDs of all currently running processes.

nvRunning = 0;

pvProcessIDs = ArrayToPointer(nvProcessIDs);

K32EnumProcesses(pvProcessIDs, 512, nvBytesReturned);

// Determine the number of process IDs retrieved. Each process ID
// is PROCESSID_LENGTH bytes.

nvProcesses = nvBytesReturned / PROCESSID_LENGTH;

Sprintf(szMessage, "INFO: ProcessRunning: nvRunning = %d, nvProcesses = %d", nvRunning,nvProcesses);
WriteToLogFile(hMSI, szMessage);

// 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));
Sprintf(szMessage, "INFO: ProcessRunning: nvIndex = %d, nvProcessHandle = %d", nvIndex,nvProcessHandle);
WriteToLogFile(hMSI, szMessage);
if nvProcessHandle != 0 then
// Get a handle to the first module in the process, which
// should be the executable.

if K32EnumProcessModules(nvProcessHandle, nvModuleHandle,
PROCESSID_LENGTH, nvBytesRequired) != 0 then
// Get the path of the module.

if K32GetModuleFileNameEx(nvProcessHandle, nvModuleHandle,
svModuleName, SizeOf(svModuleName)) != 0 then
// Extract the filename (without an extension) from
// the path.

ParsePath(svFileName, svModuleName, FILENAME_ONLY);
Sprintf(szMessage, "INFO: ProcessRunning: nvRunning = %d, nvProcesses = %d, svFileName = %s, svModuleName = %s, szAppName = %s ", nvRunning,nvProcesses,svFileName,svModuleName,szAppName);
WriteToLogFile(hMSI, szMessage);
if StrCompare(svFileName, szAppName) = 0 then
// The process module matches the application
// name passed to the function.

nvRunning = 1;

goto ProcessRunningEnd;
endif;
endif;
endif;
endif;
endfor;

ProcessRunningEnd:

if UnUseDLL(PSAPI_FILE) < 0 then
// Log this failure but ignore it since the task has been completed.
WriteToLogFile(hMSI,"ERROR: Could not unload [" + WINSYSDIR ^ PSAPI_FILE +
"]. Will ignore.");
endif;

return nvRunning;
end;

0 Comments   [ + ] Show comments

Answers (0)

Be the first to answer this question

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ