You are here

nsis help again

11 posts / 0 new
Last post
powerjuce
powerjuce's picture
Offline
Last seen: 13 years 9 months ago
Developer
Joined: 2007-09-20 21:34
nsis help again

hey all i need some nsis help.
I found this code on the nsis site and could u guys please explain it to me
thanks

!define APP_NAME find_close_terminate
!define WND_CLASS "Notepad"
!define WND_TITLE "Untitled - Notepad"
!define TO_MS 2000
!define SYNC_TERM 0x00100001
 
!include WinMessages.nsh
 
Name "${APP_NAME}"
OutFile "${APP_NAME}.exe"
 
 
LangString termMsg ${LANG_ENGLISH} "Installer cannot stop running ${WND_TITLE}.$\nDo you want to terminate process?"
LangString stopMsg ${LANG_ENGLISH} "Stopping ${WND_TITLE} Application"
 
!macro TerminateApp
 
    Push $0 ; window handle
    Push $1
    Push $2 ; process handle
    DetailPrint "$(stopMsg)"
    FindWindow $0 '${WND_CLASS}' ''
    IntCmp $0 0 done
    System::Call 'user32.dll::GetWindowThreadProcessId(i r0, *i .r1) i .r2'
    System::Call 'kernel32.dll::OpenProcess(i ${SYNC_TERM}, i 0, i r1) i .r2'
    SendMessage $0 ${WM_CLOSE} 0 0 /TIMEOUT=${TO_MS}
    System::Call 'kernel32.dll::WaitForSingleObject(i r2, i ${TO_MS}) i .r1'
    IntCmp $1 0 close
    MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "$(termMsg)" /SD IDYES IDYES terminate IDNO close
    System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
    Quit
  terminate:
    System::Call 'kernel32.dll::TerminateProcess(i r2, i 0) i .r1'
  close:
    System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
  done:
    Pop $2
    Pop $1
    Pop $0
 
!macroend
 
 
Section "Dummy Section" SecDummy
  
!insertmacro TerminateApp
 
SectionEnd

any help would be great

Simeon
Simeon's picture
Offline
Last seen: 10 years 1 month ago
DeveloperTranslator
Joined: 2006-09-25 15:15
I dont understand

half of it but it seems to be a cool App. Maybe wraithdu "The NSIS Explanaitor" can clarify Smile

"What about Love?" - "Overrated. Biochemically no different than eating large quantities of chocolate." - Al Pacino in The Devils Advocate

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 9 months ago
Developer
Joined: 2007-09-20 21:34
yea it soon will be, i am

yea it soon will be,
i am working on an app but i dont understand this code, i mean i know what it does but cant piece it apart. so i need some help

Please search before posting. ~Thanks

digitxp
digitxp's picture
Offline
Last seen: 13 years 2 months ago
Joined: 2007-11-03 18:33
Apparently

it is a script that checks if notepad is running, then closes it if it is...

Insert original signature here with Greasemonkey Script.

rab040ma
Offline
Last seen: 5 months 1 week ago
Joined: 2007-08-27 13:35
Techniques that would be

Techniques that would be handy in an eject script...

MC

digitxp
digitxp's picture
Offline
Last seen: 13 years 2 months ago
Joined: 2007-11-03 18:33
Kinda hard

can't wait for the autoejectscript thingy

Insert original signature here with Greasemonkey Script.

wraithdu
Offline
Last seen: 11 years 6 months ago
Developer
Joined: 2007-06-27 20:22
This is a macro that tries

This is a macro that tries to close a process in a couple different ways.

First it searches the specified window CLASS, not title in this case, although a specific window title can be specified in the FindWindow command in addition to the class if you want/need to.

That search returns the window HWND (handle) if it exists, if not it exits (window wasn't found). Then it uses the window handle to get the process handle.

First it tries to close the process by sending the window the ${WM_CLOSE} window message (like clicking the X button in the corner of a window). It waits the specified timeout period, and if it fails asks if you want to terminate the app. If so, it tries to terminate the process directly (like using Task Manager to kill an app).

Check the bottom of this page for the other FindWindow options -

http://nsis.sourceforge.net/Find_and_Close_or_Terminate

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 9 months ago
Developer
Joined: 2007-09-20 21:34
thanks i get it now

see here is what i want to do:

create a app like eject script that uses gets all of the apps on the drive, then closes them, if it cannot then it will ask if you want to terminate them. After all of that is done i found an open source program that will eject the drive for you. And i want the whole app to be in the portableapps format.

last question, can i use autoit and still hav the app be considered in the portableapps format?

Please search before posting. ~Thanks

wraithdu
Offline
Last seen: 11 years 6 months ago
Developer
Joined: 2007-06-27 20:22
I should think so. There's

I should think so. There's nothing that demands launchers are written in NSIS.

By the way, there are process plugins for NSIS, and builtin commands in AutoIt3 for controling processes. You don't *have* to use that script above.

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 9 months ago
Developer
Joined: 2007-09-20 21:34
yes i saw those but...

they mostly dealt with terminating the process not closing them. If i make a "ejectscript" like app i don't want people to lose any changes/stuff that the app does on close.

Edit: found one!!!
http://nsis.sourceforge.net/FCT_plug-in

question though:

also is there a way you could find a class name using nsis code?

Please search before posting. ~Thanks

wraithdu
Offline
Last seen: 11 years 6 months ago
Developer
Joined: 2007-06-27 20:22
I'm sure you can find the

I'm sure you can find the class from, say a window title or process name, but you'd need to use the System plugin and WinAPI calls I think. But I don't know how to do that Sad

Log in or register to post comments