Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Windows service install directory (http://forums.winamp.com/showthread.php?t=389946)

pkonduru 26th February 2016 19:13

Windows service install directory
 
Hi All,

In my installer, I have to search for an existing windows service and get the parent directory of the executable that is running this service. Since I don't know the exact name of the service but know what string it begins with, I loop around the
HKLM System\CurrentControlSet\services and get the exact service name. Then I use the SimpleService plugin:

SimpleSC::GetServiceBinaryPath "$servFound"
Pop $0
Pop $1

Which returns($1) something like this:
"C:\Program Files\XXX\YYY\zzz\exec.exe" //RS//XX_YY

I need to get this out from this string : C:\Program Files\XXX\YYY\zzz

The problem is if the service is running in any other directory than the ProgramFiles, there is no quotes around it, something like this:

C:\Blah\XXX\YYY\zzz\exec.exe //RS//XX_YY

I tried using the GetFirstStrPart function,

http://nsis.sourceforge.net/Get_first_part_of_a_string

Which works fine but not if there is Program Files in the path. I have also tried GetInQuotes:

http://nsis.sourceforge.net/GetInQuo...between_quotes

But problem is it wouldn't work if there are no quotes.

Any suggestions on how to get the directory path no matter there are quotes or not will be very helpful.

--Pavan

Anders 26th February 2016 23:51

This is a basic path parsing issue, I'm sure there is a function out there that fits your needs. If not you can write your own, the requirements are pretty basic. If it starts with " then you look for the terminating ", otherwise it ends at the first space.

pkonduru 27th February 2016 00:55

Thanks Anders, I ended doing this:

SimpleSC::GetServiceBinaryPath "$servFound"
Pop $0
Pop $1

${StrContains} $0 '"' "$1"

${If} $0 == ""
Push "$1" ; contains the service executable string
Call GetFirstStrPart
Pop "$R0"
${Else}
Push "$1"
Call GetInQuotes
Pop $R0
${EndIf}

Anders 27th February 2016 16:00

PHP Code:

Function PathRemoveArgsAndQuotes
Exch 
$0
Push 
$Pos
Push 
$2
Push 
$Quote or space
StrCpy 
$" "
StrCpy $""
StrCpy $$0 1
StrCmp 
$'"' +3
IntOp 
$$1
StrCpy 
$$2
loop
:
    
StrCpy $$0 1 $1
    StrCmp 
$"" stop
    StrCmp 
$$3 stop
    IntOp 
$$1
    
Goto loop
stop
:
    
StrCmp $'"' +3
    StrCpy 
$2 1
    IntOp 
$$1
    StrCpy 
$$$$2
Pop 
$3
Pop 
$2
Pop 
$1
Exch 
$0
FunctionEnd

Section
Push 
'c:\foo\bar.ext'
Call PathRemoveArgsAndQuotes
Pop 
$9
DetailPrint 
<$9>
Push 'c:\foo\bar.ext baz'
Call PathRemoveArgsAndQuotes
Pop 
$9
DetailPrint 
<$9>

Push '"c:\foo\bar.ext"'
Call PathRemoveArgsAndQuotes
Pop 
$9
DetailPrint 
<$9>
Push '"c:\foo\bar.ext" baz'
Call PathRemoveArgsAndQuotes
Pop 
$9
DetailPrint 
<$9>
Push '"c:\f o o\b a r.ext" baz'
Call PathRemoveArgsAndQuotes
Pop 
$9
DetailPrint 
<$9>
SectionEnd 


pkonduru 29th February 2016 17:31

That works like a charm Anders!!
Thanks a ton.


All times are GMT. The time now is 18:02.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.