3 Replies Latest reply on Feb 6, 2006 6:49 AM by map

    Parse a variable

    ssweb Rookie
      I would like to Parse a string or variable

      I have a string from the registry


      I want to get the path where the exe is located

      Does anyone have a solution.


        • 1. Re: Parse a variable
          klaus.messmer Apprentice

          most times i'm searching the file on the filesystem, create an INI-Based-File and work with the section of the INI-File.
          To search the File and get the Path to it, i use a normal Batch-File like this:

          set _server_name=%1
          set _file2check=%2
          set _check_folder_log=%3

          FOR /F "Tokens=1" %%i in ('dir /b /s %_file2check%') do (
          echo [checkfolder]
          echo checkfolder=%%~pi%_file2check%

          The Parameters are given by the NetInstll Script wich is calling the Batch-File.

          RunAs('.\extern$\check_folder.cmd %_server_name% %_file2check% %_check_folder_log%')

          To read and parse an string from the registy i would also be interessted in.
          Finally i got to excuse my bad english, hope you understand what i mean.

          greetz from germany
          • 2. Re: Parse a variable
            map Specialist

            i know its kinda late to answer to this thread, but better late than never

            1) do retrieve the path only from a string, one can use the advanced features of the shell's "SET" command.
            in a batchfile a construction like:

            set PSTPATH=%%~dpj

            will result in %PSTPATH% containing the Path to the file %j, so if

            %j is "c:\program Files\data\text.doc" ->%PSTPATH% will be "c:\program Files\data"

            2) to retrieve a path from the registy i use a rather sophisticated piece of batch coding. The trick is to parse the output of "reg.exe" on the fly and process the results.

            i'll post an example.

            Lets say we want to find out where Adobe Photoshop has installed its Gamma Loader.

            That information is contained in the registry at
            "HKLM\Software\Adobe\Adobe Gamma" in a Key called "Location"

            It looks like this:
            Windows Registry Editor Version 5.00

            [HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe Gamma]
            "Location"="C:\\Programme\\Gemeinsame Dateien\\Adobe\\Calibration\\Adobe Gamma.cpl"

            The Batch Script for getting that Value and dividing it in "Path" and "Filename" would be:

            @echo off
            :: Example for retrieveing a files name and path from a registryvalue for further use within NetInstall
            :: Result will look like this:
            ::PNAME1=Adobe Gamma.cpl
            ::PPATH1=C:\Programme\Common Files\Adobe\Calibration
            :: These Values can be read from a NetInstall script using ReadINI and processed easily.
            :: Parameter:
            ::    %1 Name of Ini-Files
            ::    %2 Name of Temp-Directory that contains "reg.exe".
            :: Requirements:
            ::    - reg.exe from Resource-Kit must be in %TEMPDIR%.
            ::      (Will be copied there by calling NI-script)
            ::    - Commandline Extensions for  NT must be active (usually are)
            :: (c) 2006 Martin Appel enteo Software GmbH

            set INIFILE=%1
            set TEMPDIR=%2

            :: Create INI-File
            echo [SECTION]>%INIFILE%

            :: Get Path and File that is contained in the value of keyword "Location", and call subroutine :PRINTIT with these values in Variables PNAME and PPATH

            for /f "tokens=3" %%j in ('%TEMPDIR%\reg query "HKEY_CURRENT_USER\Software\Adobe\Adobe Gamma\Location"') do (
            set PPATH=%%~dpj
            set PNAME=%%~nxj
            call :PRINTIT
            goto :END

            :: Add result to INI-File

              echo PNAME=%PNAME% >>%INIFILE%
              echo PPATH=%PPATH% >>%INIFILE%
            goto :EOF

            • 3. Re: Parse a variable
              jparekh Apprentice
              This simple vbScript will get you the result you need.

              The path is hardcoded, but you can use RegRead to grab it from the registry as well.

              Dim fso
              Set fso = CreateObject("Scripting.FileSystemObject")
              GetTheParent = fso.GetParentFolderName("C:\PROGRA~1\folder1\folder2\UNINST~1.EXE")
              Wscript.Echo GetTheParent