Terminate Process (revisited)

Got a problem you cannot solve? Try here.
jgrubb
Posts: 2
Joined: Tue May 08, 2007 10:16 am

Terminate Process (revisited)

Postby jgrubb » Tue May 08, 2007 10:38 am

I need to shut down a process without a window. Therefore no window title, and the class name is auto-generated (.NET window)

I have looked through the forums a bit, and found this information.

Gizm0 wrote:Well you are not lucky,i'm out of town and i don't have my InstallAWARE here, so i can create a script for you.. It's quite easy actually, you have to call an API to do it.. It's TerminateProcess and before that you have to get the process handle by it's process name. To do that you have to EnumProcesses ( read here -> http://msdn.microsoft.com/library/defau ... cesses.asp ) and get the PIDs and then using the pids to get the process name/handle.


If what I am understanding from this post, it says to make an API call to psapi.dll to enumerate through the running processes.

I have written a c++ program to do this. Thats no problem. How do I link something like this to my InstallAware setup script? The only options I have come up with have been to build a dll that performs the following code, include it in the setup script, and then make a call to the dll. before running the main install. Does this make sense?


DWORD aProcesses [1024], cbNeeded, cProcesses;
if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
{
return 0;
}

cProcesses = cbNeeded / sizeof(DWORD);

for(int i = 0; i < cProcesses; i++)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]);
if(hProcess == NULL)
{
continue;
}

HMODULE hMod;

if(!EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
continue;
}

TCHAR szProcName[1024];

GetModuleBaseName(hProcess, hMod, szProcName, 1024/sizeof(TCHAR));

// if the correct process name, terminate it.
}

I am not getting anywhere with this. I could really use a hand.

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Tue May 08, 2007 10:47 am

You can certainly build a DLL with that code and call it from InstallAware using the Call DLL Function plug-in; or you could author a full blown plug-in for use with InstallAware directly.
Michael Nesmith
InstallAware
Home of The Next Generation MSI Installer
Get your free copy today - http://www.installaware.com/

jgrubb
Posts: 2
Joined: Tue May 08, 2007 10:16 am

Postby jgrubb » Tue May 08, 2007 10:51 am

MichaelNesmith wrote:You can certainly build a DLL with that code and call it from InstallAware using the Call DLL Function plug-in; or you could author a full blown plug-in for use with InstallAware directly.


Could you maybe point me in the right direction for information about writing plug-ins for InstallAware?

EDIT: Nevermind, I was able to find how to do it in the InstallAware help section of the program.
Last edited by jgrubb on Tue May 08, 2007 10:59 am, edited 1 time in total.

MichaelNesmith
Posts: 3452
Joined: Thu Dec 22, 2005 7:17 pm
Contact:

Postby MichaelNesmith » Tue May 08, 2007 10:58 am

The help file contains detailed documentation on the required plug-in exports. The IDE offers two templates for the Visual C++ and Delphi languages.
Michael Nesmith

InstallAware

Home of The Next Generation MSI Installer

Get your free copy today - http://www.installaware.com/

Marco
Posts: 13
Joined: Tue Sep 11, 2007 5:53 pm

Postby Marco » Sun Jan 20, 2008 1:45 am

Can this be done with the MSI Code or only by a plug-in?

Peace in Christ
Marco Napoli
http://www.ourlovingmother.org

swarovski
Posts: 109
Joined: Mon Apr 16, 2007 8:32 pm

Postby swarovski » Sun Jan 20, 2008 10:56 pm

Try AutoIt.

$PEXISTS = ProcessExists("iexplore.exe")
If $PEXISTS <> 0 Then
ProcessClose($PEXISTS)
EndIf

I have used it and put the executable in the Setup.exe
Use plug-in Filebag and run it during the installation process.

Marco
Posts: 13
Joined: Tue Sep 11, 2007 5:53 pm

Postby Marco » Sun Jan 20, 2008 11:40 pm

Hi swarovski,

Thanks for the suggestion. We just recently purchased Installaware and I tried to add the Plugin Filebag but I cannot figure out what to do.

Do you have any steps for me to follow for your suggestion?

Thank you.
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org

swarovski
Posts: 109
Joined: Mon Apr 16, 2007 8:32 pm

Postby swarovski » Mon Jan 21, 2008 3:17 am

In the File Bag dialog, u see 3 textboxes right?

You only need the 1st and the 3rd textbox.
File to include: input or browse the full path of the executable.
e.g. C:\\Deployment\\bin\\terminate.exe

In the 3rd textbox, i.e. Variable to receive runtime location of files.
type an variable name.
e.g. fileBagTerminate


The file bag plugin part is done!

Now, in your setup code,
You can use MessageBox
and type this in the message:
fileBagTerminate = $fileBagTerminate$

$ sign here is like de-reference a variable.
i.e. showing the content of the variable.

So that you can debug if the file bag is correct.

Then add a Run Program: (type run program in the script editor):
in the Run Program field type:
$fileBagTerminate$Terminate.exe

that's it!



Marco wrote:Hi swarovski,

Thanks for the suggestion. We just recently purchased Installaware and I tried to add the Plugin Filebag but I cannot figure out what to do.

Do you have any steps for me to follow for your suggestion?

Thank you.

Marco
Posts: 13
Joined: Tue Sep 11, 2007 5:53 pm

Postby Marco » Mon Jan 21, 2008 1:14 pm

Thanks a lot for the details steps. I have added them to my setup script but I am having a few issues.

1. The terminate.exe program, that would be my program that is running correct? Or is it a program that has code to shut down a running program?

2. For the fileBagTerminate I selected my exe program that I want to install, is this correct? When I trace it, this variable shows the path to the fileBag plugin folder, weird...

Here is my code below:

Set Variable fileBagTerminate to
Define File Bag : D:\\Distribution\\MyRolodex.exe, get runtime location of files into variable fileBagTerminate
MessageBox: $TITLE$ Setup, fileBagTerminate = $fileBagTerminate$
Run Program $fileBagTerminate$MyRolodex.exe


3. Where does the below code belong? I cannot add it to the Installaware script:

$PEXISTS = ProcessExists("iexplore.exe")
If $PEXISTS <> 0 Then
ProcessClose($PEXISTS)
EndIf


Thanks a lot, I really appreciate this help.
Peace in Christ

Marco Napoli

http://www.ourlovingmother.org

swarovski
Posts: 109
Joined: Mon Apr 16, 2007 8:32 pm

Postby swarovski » Mon Jan 21, 2008 9:03 pm

ahhaha
1. the terminate.exe is just an example.
you are right, it's a program that is compiled by AutoIt to shutdown a running program.

2. that's correct. that's the temporarily folder.

3. Those scripts is AutoIt script. Try search AutoIt on google.
Then compile the script into terminate.exe.

Marco wrote:Thanks a lot for the details steps. I have added them to my setup script but I am having a few issues.

1. The terminate.exe program, that would be my program that is running correct? Or is it a program that has code to shut down a running program?

2. For the fileBagTerminate I selected my exe program that I want to install, is this correct? When I trace it, this variable shows the path to the fileBag plugin folder, weird...

Here is my code below:

Set Variable fileBagTerminate to
Define File Bag : D:\\Distribution\\MyRolodex.exe, get runtime location of files into variable fileBagTerminate
MessageBox: $TITLE$ Setup, fileBagTerminate = $fileBagTerminate$
Run Program $fileBagTerminate$MyRolodex.exe


3. Where does the below code belong? I cannot add it to the Installaware script:

$PEXISTS = ProcessExists("iexplore.exe")
If $PEXISTS <> 0 Then
ProcessClose($PEXISTS)
EndIf


Thanks a lot, I really appreciate this help.

Marco
Posts: 13
Joined: Tue Sep 11, 2007 5:53 pm

Postby Marco » Tue Jan 22, 2008 1:13 am

I am almost there. I got it working when I run the original setup.exe to install and to remove the application, it now Terminates the Process correctly with the AutoIt.

But what is very interesting, if I click on the shortcut created that says Uninstall MyRolodex then I receive an pop up windows that asks for the original setup files... weird. I am not sure what I did wrong. My code is below.

I placed my code in the Uninstallation Region. But when I add the code to Terminate the Process using FileBag it gives error when compiling that says that I need to add at least one Web Region, which I did. I wonder if this is what is causing the lookup pop at runtime?


[DEFINE REGION: Perform Uninstallation]
if Variable REMOVE Equals TRUE
Comment: Uninstall product
Comment: TO-DO: Insert any additional uninstall commands here
[OFFLINE CONTENT]
Set Variable TerminateMyRolodex to
Define File Bag : D:\\Distribute\\TerminateMyRolodex.exe, get runtime location of files into variable TerminateMyRolodex
Run Program $TerminateMyRolodex$TerminateMyRolodex.exe


Apply Uninstall (get result into variable SUCCESS)
Set Variable PROGRESS to 100
else



Thank you so much.
Peace in Christ

Marco Napoli

http://www.ourlovingmother.org

swarovski
Posts: 109
Joined: Mon Apr 16, 2007 8:32 pm

Postby swarovski » Wed Jan 23, 2008 4:50 am

Don't worry hehe.
I hit the same problem when I was started to use IA.
Change the build from Single File to Web Deploy will not ask you that location again~~~

Try try XD

Marco wrote:I am almost there. I got it working when I run the original setup.exe to install and to remove the application, it now Terminates the Process correctly with the AutoIt.

But what is very interesting, if I click on the shortcut created that says Uninstall MyRolodex then I receive an pop up windows that asks for the original setup files... weird. I am not sure what I did wrong. My code is below.

I placed my code in the Uninstallation Region. But when I add the code to Terminate the Process using FileBag it gives error when compiling that says that I need to add at least one Web Region, which I did. I wonder if this is what is causing the lookup pop at runtime?


[DEFINE REGION: Perform Uninstallation]
if Variable REMOVE Equals TRUE
Comment: Uninstall product
Comment: TO-DO: Insert any additional uninstall commands here
[OFFLINE CONTENT]
Set Variable TerminateMyRolodex to
Define File Bag : D:\\Distribute\\TerminateMyRolodex.exe, get runtime location of files into variable TerminateMyRolodex
Run Program $TerminateMyRolodex$TerminateMyRolodex.exe


Apply Uninstall (get result into variable SUCCESS)
Set Variable PROGRESS to 100
else



Thank you so much.

Marco
Posts: 13
Joined: Tue Sep 11, 2007 5:53 pm

Postby Marco » Wed Jan 23, 2008 11:54 am

Thanks for the suggestion, go figure... Part of the learning process.
Peace in Christ

Marco Napoli

http://www.ourlovingmother.org


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 105 guests