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,
Which works fine but not if there is Program Files in the path. I have also tried GetInQuotes:
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
Windows service install directory
5 posts
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.
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}
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}
Function PathRemoveArgsAndQuotes
Exch $0
Push $1 ; Pos
Push $2
Push $3 ; Quote or space
StrCpy $3 " "
StrCpy $1 ""
StrCpy $2 $0 1
StrCmp $2 '"' 0 +3
IntOp $1 $1 + 1
StrCpy $3 $2
loop:
StrCpy $2 $0 1 $1
StrCmp $2 "" stop
StrCmp $2 $3 stop
IntOp $1 $1 + 1
Goto loop
stop:
StrCmp $3 '"' 0 +3
StrCpy $2 1
IntOp $1 $1 - 1
StrCpy $0 $0 $1 $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 That works like a charm Anders!!
Thanks a ton.
Thanks a ton.