Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Detecting and Stopping Microsoft Excel on install


Best Answer overlord , 29 June 2015 - 18:06

Ok so I updated the code to look like this:

function SoftFailureProcessRunning(hMSI)
	NUMBER  nvSize, nvType;            
	STRING  svRegKey;  // key to search for
	STRING  svRegValue; // captured value from the registry key
begin
	
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    nvType = REGDB_STRING;
    nvSize = 256;
    svRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\excel.exe";
    
    RegDBGetKeyValueEx(svRegKey, "Path", nvType, svRegValue, nvSize);
    
    
    if (Is(FILE_LOCKED, svRegValue ^ "excel.exe")) then
		MessageBox("This installation proccess cannot continue while Excel.exe is running. Click OK to close Excel", WARNING);
		
    else
		MessageBox( "Process not running", WARNING);
    endif;
	
end;

That seems to properly detect it running without issues.

Go to the full post


8 replies to this topic

overlord

overlord
  • Full Members
  • 38 posts

Posted 25 June 2015 - 14:12

So I have an installer that deploys a plugin for excel. Upon uninstall windows or installshield (not sure which) properly detects we are trying to remove things from excel and prompts you to close it.

On install it cannot detect that excel needs to be closed.

 

I have tried a number of different solutions that did not seem to work properly.

I tried the old examples from the installscript on this sit for detect and kill a process and they did not detect excel.

I also tried using find window but apparently excel names its windows based on the workbook that is currently open at the time and searching for excel.exe or excel7 did not properly detect the application.

 

I have even examined using cmd.exe and tasklist to try and find it but I am not sure how to make that work. I am using Installshield 2012 for this project.

Any suggestions or help is appreciated at this point.

 

Thanks

-Overlordchin


Edited by overlord, 25 June 2015 - 16:44.


overlord

overlord
  • Full Members
  • 38 posts

Posted 25 June 2015 - 16:51

here is the code I used for the find window test:

export prototype MyTestFunction(HWND);


function MyTestFunction(hMSI)
HWND nHwnd;
begin	
	nHwnd = FindWindow("EXCEL", "");
	if (nHwnd != 0) then
	MessageBox("found excel", WARNING);
	SendMessage(nHwnd, WM_CLOSE, 0, 0);
	else
	MessageBox("cant find excel", WARNING);
	endif;

end;

Substitute the "EXCEL" for several variants on the word, capitalization and version numbers. It is set to run after appsearch as a custom action and my else block always pops even with excel open.



deramor

deramor
  • Full Members
  • 187 posts

Posted 25 June 2015 - 23:45

I found this code on Stephan's blog and modified it slightly.  For the unmodified source, go to http://www.installsite.org/. Using the left navigation pane, navigate to InstallScript Samples -> External Programs and Shell.  Review the "List and Shut Down Applications section.

 

My modified versions are attached.

 

Attached Files



overlord

overlord
  • Full Members
  • 38 posts

Posted 26 June 2015 - 16:12

Thanks for the response. However this appears to have the same issue in that it will not detect EXCEL.EXE.

begin
	// The psapi.dll reads the Windows NT performance database. The DLL
	// is part of the Win32 SDK.
	szAppName = "EXCEL.EXE";

I can tell that its running the function. I put a message box in the if block where it confirms that it found it and added an else with a message box saying nope.

The nope message box pops between 18-20 times in a row (Which I assume is as it is checking separate processes). That said there are 141 processes running on my machine currently and it only popped the else 18-20 times. Is it not looking at them all?

if StrCompare(svFileName, szAppName) = 0 then
	// The process module matches the application 
	// name passed to the function.
						
	bvRunning = TRUE;
	MessageBox("Found Excel", WARNING);
					    
	goto ProcessRunningEnd;
else 
	MessageBox("Thats a big nope", WARNING);
					    
endif;

thoughts?



overlord

overlord
  • Full Members
  • 38 posts

Posted 26 June 2015 - 16:48

Ahhh ok so I changed the nope pop up to list the process. It is ONLY looking a the 32bit process table. I guess I will need to enhance the function or duplicate it to have it also look a tthe 64bit process space.



Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 26 June 2015 - 17:37

Just an idea for an alternative approach: If you know the directory where excel.exe is, you could try Is(FILE_LOCKED, ...). But you should call this after the UAC prompt.

If it works this would only detect the situation, not kill the process.



overlord

overlord
  • Full Members
  • 38 posts

Posted 26 June 2015 - 18:05

So that was one of the first things I tried. I attempted to read in the registry to get the path and then call is file locked on it. I probably should have used the System Search and stored the path in a property and then used that for the is FILE_LOCKED instead of trying to do it all in installscript or vbscript



overlord

overlord
  • Full Members
  • 38 posts

Posted 26 June 2015 - 19:04

So looks like I might have to try Stefan's suggestion here is a cross post to the flexera forums where someone encountered the same issue I am seeing: https://community.fl...p?t-188807.html

Even specifying the 64bit psapi.dll still addresses the 32bit space unless you disable the redirection which apprently does not work within the confines of the custom action without throwing some errors. 

 

I will post an update with the results of my attempt with is FILE_LOCKED again

 

 

***UPDATE***

 

So I added a system search for  "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe" - "Path"

to grab the install path for excel.

 

Then I used the following code to check for file_locked:

function Process64Running(hMSI)
	NUMBER  nvSize;          
	STRING  svFilePath; 
begin
	
    nvSize = 256;
    MsiGetProperty	(hMSI, "EXCEL_PATH", svFilePath, nvSize);
    
    if (Is(FILE_LOCKED, svFilePath ^ "excel.exe")) then
		MessageBox("found it finally", WARNING);
    else
		MessageBox( svFilePath ^ "excel.exe", WARNING);
    endif;
	
end;

The problem is that svFilePath is empty even though I can go look in the registry at that path and see the value. I also tried checking and unchecking the "Search the 64bit section of the registry" checkbox.

Did not seem to make a difference. I previously had the custom action executing after app search but moved it to after install welcome hoping to ensure the value had been populated. 

 

I also thought maybe it had something to do with the space in between the "App Paths" in the key that we are searching for. However, I checked a few other system search examples that had spaces in them so I dont think that is the issue. Any ideas what I am doing wrong here? The Message box that pops up only says "excel.exe" 


Edited by overlord, 26 June 2015 - 21:41.


overlord

overlord
  • Full Members
  • 38 posts

Posted 29 June 2015 - 18:06   Best Answer

Ok so I updated the code to look like this:

function SoftFailureProcessRunning(hMSI)
	NUMBER  nvSize, nvType;            
	STRING  svRegKey;  // key to search for
	STRING  svRegValue; // captured value from the registry key
begin
	
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    nvType = REGDB_STRING;
    nvSize = 256;
    svRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\excel.exe";
    
    RegDBGetKeyValueEx(svRegKey, "Path", nvType, svRegValue, nvSize);
    
    
    if (Is(FILE_LOCKED, svRegValue ^ "excel.exe")) then
		MessageBox("This installation proccess cannot continue while Excel.exe is running. Click OK to close Excel", WARNING);
		
    else
		MessageBox( "Process not running", WARNING);
    endif;
	
end;

That seems to properly detect it running without issues.