Old 26th February 2016, 19:13   #1
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
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
pkonduru is offline   Reply With Quote
Old 26th February 2016, 23:51   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,267
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 27th February 2016, 00:55   #3
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
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}
pkonduru is offline   Reply With Quote
Old 27th February 2016, 16:00   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,267
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 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 29th February 2016, 17:31   #5
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
That works like a charm Anders!!
Thanks a ton.
pkonduru is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump