You are here

ProcFunc - NSIS Process Function Header

102 posts / 0 new
Last post
quala
Offline
Last seen: 6 years 6 months ago
Joined: 2011-02-03 09:07
All work! Steeply! Loosed in

All work! Steeply!
Loosed in GoTo))

Thank you for good code!

It is Correct I use your code gentlemen? The Paircouple beside I work only for 1 file!
If I try right behind close one more file that beside me is not got.
Prompt please.

!macro StopExe NAME
StrCpy $tmpRetVal 0
StrCpy $tmpCount 0
DetailPrint "Çàâåðøåíèå ðàáîòû '${NAME}'"

StrCpy $tmpCount 2 ;// ×èñëî ïîïûòîê
${CloseProcess} "${NAME}" $tmpRetVal

${Do}
${If} $tmpRetVal != 0
${ProcessWaitClose} "${NAME}" "1000" $tmpRetVal

${EndIf}
;// -1 - operation timed out
IntOp $tmpCount $tmpCount - 1 ;// Ñ÷åò÷èê ïîïûòîê
${If} $tmpRetVal == 0
StrCpy $tmpCount $tmpRetVal ;Íå íàéäåí ïðîöåññ èëè çàêðûò
${EndIf}

${LoopUntil} $tmpCount == 0 ;// Ïîêà åñòü ïîïûòêè è ïðîöåññ åùå íå óáèò

${If} $tmpRetVal

OpenPlatform
OpenPlatform's picture
Offline
Last seen: 10 years 8 months ago
Joined: 2011-02-20 18:26
${TerminateProcess} & ${CloseProcess}

These functions did not function as I had expected I was hoping to create a semi-automated script for parsing through a list and ending the functions in a list, but when I use ${TerminateProcess} the process is ended and then the .exe file is deleted? and when I use the ${CloseProcess} nothing happens, except for the launcher parsing through the ini file, searching for the process, obtaining the PID, obtaining the path, and attempting to end the process, but it never is ended, did I do something wrong in these two parts of a section?

${CloseProcess} "blah.exe" $1
${If} $1 == 1
  Goto Error
${EndIf}

or

${TerminateProcess} "blah.exe" $1
${If} $1 == 1
  Goto Error
${EndIf}

(edit) turns out the loop was faulty and directed it to the delete option

poofeg
Offline
Last seen: 12 years 11 months ago
Joined: 2011-04-11 15:52
Multiple CloseProcess

Can anybody help me, why this code wrong? Why CloseProcess works only once?

Name "NSIS ProcFunc Test"
OutFile "ProcFunc.exe"
ShowInstDetails show
RequestExecutionLevel user

!include "ProcFunc.nsh"

Page components
Page instfiles

Section "Run tests" TESTS

    Exec "notepad.exe"
    Exec "calc.exe"
    Exec "mspaint.exe"

    MessageBox MB_OK "Ready?"

    DetailPrint "Close notepad"
    ${CloseProcess} "notepad.exe" $0
    ${ProcessWaitClose} "notepad.exe" -1 $0

    DetailPrint "Close calc"
    ${CloseProcess} "calc.exe" $0
    ${ProcessWaitClose} "calc.exe" -1 $0

    DetailPrint "Close mspaint"
    ${CloseProcess} "mspaint.exe" $0
    ${ProcessWaitClose} "mspaint.exe" -1 $0

SectionEnd
poofeg
Offline
Last seen: 12 years 11 months ago
Joined: 2011-04-11 15:52
I found solution. Problem was

I found solution. Problem was in "callback1". There is

!macro CloseProcess_
	System::Store "s" ; store registers in System's private stack
	Pop $0 ; process / PID
	
	; passed process name or pid
	StrCpy $1 $0 4 -4
	${If} $1 == ".exe"
		${GetProcessPID} $0 $0
	${EndIf}
	
	; else passed pid directly
	
	${Unless} $0 = 0 ; $0 = target pid
		Push $0 ; return pid of process
		; use EnumWindows and a callback
		System::Get '(i .r1, i)i sr4' ; $1 = hwnd, $4 = callback#, s (stack) = source for return value
		Pop $3 ; $3 = callback address
		System::Call 'user32::EnumWindows(k r3, i)i' ; enumerate top-level windows
        StrCpy $4 $4 8
		${DoWhile} $4 == "callback"
			System::Call 'user32::GetWindowThreadProcessId(i r1, *i .r2)i' ; $2 = pid that created the window
			${If} $2 = $0 ; match to target pid
				SendMessage $1 16 0 0 /TIMEOUT=1  ; send WM_CLOSE to all top-level windows owned by process, timeout immediately
			${EndIf}
			Push 1 ; callback return value; keep enumerating windows (returning 0 stops)
			StrCpy $4 "" ; clear callback#
			System::Call '$3' ; return from callback
            StrCpy $4 $4 8
		${Loop}
		System::Free $3 ; free callback
	${Else}
		Push 0 ; failure return value
	${EndUnless}
	
	System::Store "l" ; restore registers
!macroend
david_pi
Offline
Last seen: 1 year 2 months ago
Joined: 2011-03-19 09:44
${EnumProcessPaths} on 64-bit Windows

The ${EnumProcessPaths} only report the installer itself on 64-bit windows. The same code works well on 32-bit windows. Is this a bug?

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 5 months ago
Developer
Joined: 2010-02-13 17:10
Before I get shot

I l know that this topic is well over 4 years old and I know that much of this has been added into the th ePA Launcher, so do NOT get angry at me for adding to an old thread since I did what everyone tells use to do and search the forums first, heck I even searched Google for my answer and this was one of the first 5 hits.

I amdeveloping amarok, one of the issues I am trying to deal with is that after the main program exits there any where from 4-8 processes still running that prevent you from removing the drive as it is "still in use" I can manually kill them and all is good. SO I was looking into writing some custom launcher code in the post phase to kill the processes which brought me back here. If this code is now part of the PA Launcher can I kill them from within the launcher or use parts of this code to create a post section? Since I know the processes that need killing I think I could just usse the KillProc feature? Any help or ideas appreciated

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Pyromaniac
Pyromaniac's picture
Offline
Last seen: 8 years 11 months ago
Developer
Joined: 2008-09-30 19:18
Try it

Try writing ${TerminateProcess} into ${SegmentPost} with all the exe's and see if it compiles fine, and if it doesn't then !including ProcFunc.nsh will get you your expected results.

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 5 months ago
Developer
Joined: 2010-02-13 17:10
tyvm

will give it a try

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 5 months ago
Developer
Joined: 2010-02-13 17:10
can you take a look

at http://pastebin.com/VcSG5HDk which is my attempt and I also included in comments the error, been trying to figure it out for 2 hours and just not sure if I not understanding or what I am missing

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Aluísio A. S. G.
Offline
Last seen: 7 years 8 months ago
DeveloperTranslator
Joined: 2010-11-09 17:43
Maybe

$Var is not defined?

Previously known as kAlug.

Simone73
Offline
Last seen: 9 years 8 months ago
Joined: 2014-07-08 12:25
hidden process

how can i modify this script to allow me to execute a process hiding his window ?

Pages

Log in or register to post comments