Winamp & Shoutcast Forums Windows service install directory

 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
 26th February 2016, 23:51 #2 Anders Moderator     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  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}  27th February 2016, 16:00 #4 Anders Moderator Join Date: Jun 2002 Location:${NSISDIR} Posts: 5,267 PHP Code:  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  IntOp$PostCount \$PostCount + 1