PDA

View Full Version : problem closing a running process..


Lucian Cain
08-09-2006, 01:02 PM
I am attempting to close a running .exe file. (SQLSERVR.EXE) I need to terminate or close down the .exe before i delete the folder where the file lives. (i am removing a previous version of a software package before installing a new version using Autoplay) I can find no way to close a running application. after it closes the application, I will delete the associated files, folders, shortcut, and registry keys. Here is what i have started with... any suggestions?

Code = Dialog.Input("Verification Code", "NOTE: This uninstall procedure works ONLY with WINDOWS XP and WINDOWS 2000. Please enter the code given to you by AccuShade Support.", "", MB_ICONEXCLAMATION);

if Code == "5TGBHU8" then

StatusDlg.Show(MB_ICONNONE, false)

SQLresult = File.IsInUse("c:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlservr.exe");
if SQLresult == true then

File.Rename("C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlservr.exe", "C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlserver.old");
File.Delete("C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlserver.old");

else

File.Delete("C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlservr.exe");

end

Shell.DeleteShortcut(Shell.GetFolder(SHF_DESKTOP), "AccuShade Color Retrieval System", nil);

Folder.DeleteTree("C:\\Program Files\\Matrix", nil);
Folder.DeleteTree("C:\\Program Files\\Microsoft SQL Server", nil);
Folder.DeleteTree("C:\\Program Files\\MSSQL7", nil);
Folder.DeleteTree("C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Matrix System", nil);

Registry.DeleteKey(HKEY_CURRENT_USER, "Software\\Plexus Systems LLC", nil);
Registry.DeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Microsoft SQL Server", nil);
Registry.DeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\InstallShield Uninstall Information", nil);
Registry.DeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\InstallShield_{401BC821-2FFC-4FC3-981A-74D3D88AE3B3}", nil);
Registry.DeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\InstallShield_{821FDAAB-B416-41B9-918A-ECCC2D86636C}", nil);

Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Plexus Systems LLC", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SQL Server", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SQL Server Setup{E09B48B5-E141-427A-AB0C-D3605127224A}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SQL Server Setup.{EFB70B01-B1F3-4960-AB69-4A280084A60C}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MSSQLServer", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\{689404D2-1C94-44B3-9203-BEC5594FDA7A}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\{821FDAAB-B416-41B9-918A-ECCC2D86636C}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\{401BC821-2FFC-4FC3-981A-74D3D88AE3B3}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\{E09B48B5-E141-427A-AB0C-D3605127224A}", nil);
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin stall\\InstallShield Uninstall Information", nil);

StatusDlg.Hide();

Application.Exit(0);

-- If an error occurred, display the error message.
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error] "Please contact AccuShade software support at (877) 422-2823 and report this error code.", MB_OKCANCEL, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
end
end

sside
08-12-2006, 08:03 PM
I might be little late and you might have solved the problem, yet i wrote a library to solve the quoted problem.

...I can find no way to close a running application...

Here (http://ams5.ssideproject.com/downloads/Process.apz) you can download the ams5 project.

Intrigued
08-12-2006, 09:24 PM
Take a look also at a post I had a while ago:

http://www.indigorose.com/forums/showthread.php?t=16889

There is a command-line option and it works via right-click in day-to-day Windows activities.

Lucian Cain
08-15-2006, 02:43 PM
this script is to be used as part of an installer/uninstaller. if things go awry, i want the user to be able to click on a single button, put in a code in a input box and have it shut down the process running in the taskmanager, remove the files and registry keys i listed while showing the current progress ( a bar)

as i mentioned in my first post, i am VERY new at scripting and this was... dropped in my lap, so any help in ... explaining would help as well. i won't list out all the keys this time.. i am still... stuck... :huh (yes, i got if off you guys, it LOOKS like it will do what i want it to, and i KINDA understand it, but there is something i am doing wrong.:huh

Code = Dialog.Input("Verification Code", "NOTE: This uninstall procedure works ONLY with WINDOWS XP and WINDOWS 2000. Please enter the code given to you by AccuShade Support.", "", MB_ICONEXCLAMATION);

if Code == "5TGBHU8" then

StatusDlg.Show(MB_ICONNONE, false)
function KillProcess (sProcess)
-- ****( DECLARE LOCAL VARIABLES )****
local tProcesses = {};
local tSplitPath = {};
local sFilename = "";
local bReturn = false;
-- ****( GET TABLE OF ALL SYSTEM PROCESSES )****
tProcesses = Window.EnumerateProcesses(false);
-- ****( TRAVERSE THE PROCESS TABLE )****
for nHandle, sProcessPath in tProcesses do
-- ****( SPLIT THE CURRENT PATH, GET JUST FILENAME AND EXTENSION ) ****
tSplitPath = String.SplitPath("C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Binn\\sqlservr.exe");
sFilename = tSplitPath.sqlservr .. tSplitPath.exe;
-- ****( IF THE CURRENT FILENAME/EXTENSION MATCHES PASSED )****
if String.CompareNoCase(sFilename, "sqlservr.exe") == 0 then
-- ****( PROCESSES MATCH, TERMINATE IT )****
Window.Close(nHandle, CLOSEWND_TERMINATE);
end
end
error = Application.GetLastError(0);
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error]);
else

Shell.DeleteShortcut(Shell.GetFolder(SHF_DESKTOP), "AccuShade Color Retrieval System", nil);

Folder.DeleteTree("C:\\Program Files\\Matrix", nil); ..........................

delete all folders , files, reg keys...

StatusDlg.Hide(0);
Application.Exit();

-- If an error occurred, display the error message.
error = Application.GetLastError(0);
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error] "Please contact AccuShade software support at (877) 422-2823 and report this error code.", MB_OKCANCEL, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
end
end
end
end

Lucian Cain
08-22-2006, 03:10 PM
Thank you for all the help! got the project in just under the wire!

Intrigued
08-22-2006, 05:17 PM
That's a good feeling for sure, victory and "just in time."

:yes