potitpanda Posted May 6, 2008 Posted May 6, 2008 I have added my application in "Add remove" tab of Windows Before remove IT, I Want to check if an instance is running and close the running instance before removing regkeys and autokill script. I Launch My app while "MyApp /uninstall" Normally my App is launched in HKLM\Software\Microsoft\Windows\CurrentVersion\Run "myapp.exe" Myapp and Myapp /uninstall is the same application with command line in order to uninstall it Thanks for replies.
monoceres Posted May 6, 2008 Posted May 6, 2008 I have added my application in "Add remove" tab of WindowsBefore remove IT, I Want to check if an instance is running and close the running instance before removing regkeys and autokill script.I Launch My app while "MyApp /uninstall"Normally my App is launched in HKLM\Software\Microsoft\Windows\CurrentVersion\Run "myapp.exe"Myapp and Myapp /uninstall is the same application with command line in order to uninstall itThanks for replies.Check out _Singleton() Broken link? PM me and I'll send you the file!
MikeP Posted May 6, 2008 Posted May 6, 2008 Simple functions : ProcessList , ProcessExists, ProcessCloseFor more detailed results, you might wanna check that UDF from PsaltyDS : _ProcessListProperties()
MilesAhead Posted May 6, 2008 Posted May 6, 2008 Many times trying to do things all in one .exe/app causes complications. I use Inno Setup which has an UninstallRun section that makes it convenient to run an app before uninstalling. I include a generic app killer in the install that takes a command line param for the program to kill: #include <RefreshSystemTray.au3> If Not $CmdLine[0] Then Exit EndIf If ProcessExists($CmdLine[1]) Then ProcessClose($CmdLine[1]) _RefreshSystemTray() EndIf if your app has a common name then you might need to get more specific but chances are if it's a Tray Icon type app and the user is uninstalling, then they probably forgot it's running in the tray. So I kill it, then use the RefreshSystemTray() to clear off the icon, before the uninstall runs. It compiles to around 250KB which is pretty economical these days. You might include a note in your Readme file so that people don't think it's something sinister you're sneaking in on them if they notice it in the install folder. My Freeware Page
monoceres Posted May 6, 2008 Posted May 6, 2008 (edited) I made a fully working example how a single script can work as installer / uninstaller and also main app. It also closes other instances: #include <WINApi.au3> If $CmdLine[0] > 0 Then If $CmdLine[1] = "/install" Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp", "DisplayName", "REG_SZ", "MyApp") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp", "UninstallString", "REG_SZ", @ScriptFullPath & " /uninstall") ElseIf $CmdLine[1] = "/uninstall" Then ; Check for running apps $pid = _WinAPI_GetCurrentProcessID() $plist = ProcessList(@ScriptName) For $i = 1 To UBound($plist, 1) - 1 If $plist[$i][1] <> $pid Then ProcessClose($plist[$i][1]) EndIf Next ; Here you can do all uninstalling stuff RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp") EndIf Else ; Main app While 1 ; fooling around... Sleep(100) WEnd EndIf Edit: This will of course work best if it's compiled. Edited May 6, 2008 by monoceres Broken link? PM me and I'll send you the file!
ProgAndy Posted May 6, 2008 Posted May 6, 2008 _WinAPI_GetCurrentProcessID() could alos be replaced with @AutoitPID *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
monoceres Posted May 6, 2008 Posted May 6, 2008 _WinAPI_GetCurrentProcessID() could alos be replaced with @AutoitPID ...you learn something everyday.Wonder why there is a _WinAPI_GetCurrentProcessID() function though... Broken link? PM me and I'll send you the file!
weaponx Posted May 6, 2008 Posted May 6, 2008 (edited) ...you learn something everyday.Wonder why there is a _WinAPI_GetCurrentProcessID() function though...Thats probably where @AutoItPid is generated from internally. Edited May 6, 2008 by weaponx
MilesAhead Posted May 6, 2008 Posted May 6, 2008 I made a fully working example how a single script can work as installer / uninstaller and also main app.It also closes other instances:How do you delete the exe from the HD while it's running? My Freeware Page
weaponx Posted May 6, 2008 Posted May 6, 2008 How do you delete the exe from the HD while it's running?You don't. You call ProcessClose() first.
MilesAhead Posted May 6, 2008 Posted May 6, 2008 You don't. You call ProcessClose() first.I don't get the point of closing a process using the same process if you're still leftwith the self-deleting problem. That's not uninstalling. Just settings cleanup. My Freeware Page
AdmiralAlkex Posted May 6, 2008 Posted May 6, 2008 I don't get the point of closing a process using the same process if you're still leftwith the self-deleting problem. That's not uninstalling. Just settings cleanup.You cant delete a file that is running/opened, check Q14 in the FAQ for one possible way of self-deleting .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
MilesAhead Posted May 6, 2008 Posted May 6, 2008 You cant delete a file that is running/opened, check Q14 in the FAQ for one possible way of self-deletingOk I think I see what the OP is getting at now. His app is it's ownuninstaller because he registers with the install services(Add/Remove)and that deletes the .exe when he's done with the cleanup?Another way to skin the cat. Main disadvantage is carrying uninstall logic into ramevery time your program loads but if it's a small utilityit prolly doesn't matter.I like the KillApp.exe approach for the general case sinceI don't have to reinvent the wheel for every app.. plusthe workhorse app doesn't have to be written in AutoIt.I think that's the first time I heard of somebody registeringthe main application as the uninstaller though. Novel idea. My Freeware Page
monoceres Posted May 7, 2008 Posted May 7, 2008 Ok I think I see what the OP is getting at now. His app is it's ownuninstaller because he registers with the install services(Add/Remove)and that deletes the .exe when he's done with the cleanup?Another way to skin the cat. Main disadvantage is carrying uninstall logic into ramevery time your program loads but if it's a small utilityit prolly doesn't matter.I like the KillApp.exe approach for the general case sinceI don't have to reinvent the wheel for every app.. plusthe workhorse app doesn't have to be written in AutoIt.I think that's the first time I heard of somebody registeringthe main application as the uninstaller though. Novel idea.Actually this isn't new, if you look at the bt client uTorrent you will see that it's just a single excutable, main app, installer and uninstaller everything is in the exe. which is pretty amazing since it's only 214 kB big. Broken link? PM me and I'll send you the file!
MilesAhead Posted May 8, 2008 Posted May 8, 2008 Actually this isn't new, if you look at the bt client uTorrent you will see that it's just a single excutable, main app, installer and uninstaller everything is in the exe. which is pretty amazing since it's only 214 kB big.Yeah, I wrote a program that managed a bunch of shell extensions. It had a button to uninstall that unregistered all the dlls and removed registry settings for itself, and closed itself. But I didn't think of deleting the files and registering with the install service. In that particular case it may not have worked though. The shell can be a pain letting go of extensions. Usually just a log out and log back in will free them up so you can delete, but it's a fly in the ointment for otherwise smooth uninstalls. For some reason Inno Setup seems to do a better job of deleting registered dll servers it installs, as compared to unregistering and deleting manually. Windows has so many "undocumented" gizmos anyway that it's tough to know what some programs are doing. I had a shell extension utility that I first wrote in 2001 that used the Context Menu to do special copy on selected files. I just found out a few months ago how to drag & drop copy with my extension instead of using the Browse For Folder dialog! "Undocumented APIs" must be in the list of PC Oxymorons. My Freeware Page
potitpanda Posted May 13, 2008 Author Posted May 13, 2008 Is not working... How can I get All process Name and All Process PIDS on a single GUI window.... Thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now