Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How can I identify dynamic environment variables - SET does not help  (Read 12271 times)

0 Members and 2 Guests are viewing this topic.

ALAN_BR

    Topic Starter


    Hopeful

    Thanked: 5
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    A commercial Windows backup utility (ACRONIS) requires me to select source and destination folders, and then runs my user defined *.CMD batch file to execute other commands.

    My "other commands" need to know what I selected as source and destination.

    I commence "my commands" with "SET > variable.txt",
    and this shows fixed environmental variables that include some ACRONIS variables,
    but nothing indicates the source and destination choices.
    Just possibly these choices may be held in dynamic environmental variables.

    SET totally fails to show dynamic environmental variables such as %TIME%

    Is there a special argument for SET to expose all dynamic variables ?
    Or is there a SET_DELUXE type of command that can reveal this information.

    Regards
    Alan

    billrich

    • Guest
    Re: How can I identify dynamic environment variables - SET does not help
    « Reply #1 on: June 05, 2009, 12:16:01 PM »

    C:\>set
    ALLUSERSPROFILE=C:\Documents and Settings\All Users
    CLIENTNAME=Console
    CommonProgramFiles=C:\Program Files\Common Files
    COMPUTERNAME=
    ComSpec=C:\WINDOWS\system32\cmd.exe
    DESKTOPICON=0
    FP_NO_HOST_CHECK=NO
    HOMEDRIVE=C:
    HOMEPATH=\Documents and Settings\Bill Richardson
    LOGONSERVER=\\NEWBILL
    NUMBER_OF_PROCESSORS=2
    OS=Windows_NT
    Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Co
    mmon Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10
    .0\DLLShared\
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    PROCESSOR_ARCHITECTURE=x86
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel
    PROCESSOR_LEVEL=6
    PROCESSOR_REVISION=1706
    ProgramFiles=C:\Program Files
    PROMPT=$P$G
    RoxioCentral=C:\Program Files\Common Files\Roxio Shared\10.0\Roxio Central36\
    SESSIONNAME=Console
    SystemDrive=C:
    SystemRoot=C:\WINDOWS
    USERDOMAIN=USERNAME=
    USERPROFILE=
    windir=C:\WINDOWS

    C:\>


    C:\>help
    For more information on a specific command, type HELP command-name
    ASSOC    Displays or modifies file extension associations.
    AT       Schedules commands and programs to run on a computer.
    ATTRIB   Displays or changes file attributes.
    BREAK    Sets or clears extended CTRL+C checking.
    CACLS    Displays or modifies access control lists (ACLs) of files.
    CALL     Calls one batch program from another.
    CD       Displays the name of or changes the current directory.
    CHCP     Displays or sets the active code page number.
    CHDIR    Displays the name of or changes the current directory.
    CHKDSK   Checks a disk and displays a status report.
    CHKNTFS  Displays or modifies the checking of disk at boot time.
    CLS      Clears the screen.
    CMD      Starts a new instance of the Windows command interpreter.
    COLOR    Sets the default console foreground and background colors.
    COMP     Compares the contents of two files or sets of files.
    COMPACT  Displays or alters the compression of files on NTFS partitions.
    CONVERT  Converts FAT volumes to NTFS.  You cannot convert the
             current drive.
    COPY     Copies one or more files to another location.
    DATE     Displays or sets the date.
    DEL      Deletes one or more files.
    DIR      Displays a list of files and subdirectories in a directory.
    DISKCOMP Compares the contents of two floppy disks.
    DISKCOPY Copies the contents of one floppy disk to another.
    DOSKEY   Edits command lines, recalls Windows commands, and creates macros.
    ECHO     Displays messages, or turns command echoing on or off.
    ENDLOCAL Ends localization of environment changes in a batch file.
    ERASE    Deletes one or more files.
    EXIT     Quits the CMD.EXE program (command interpreter).
    FC       Compares two files or sets of files, and displays the differences
             between them.
    FIND     Searches for a text string in a file or files.
    FINDSTR  Searches for strings in files.
    FOR      Runs a specified command for each file in a set of files.
    FORMAT   Formats a disk for use with Windows.
    FTYPE    Displays or modifies file types used in file extension associations.
    GOTO     Directs the Windows command interpreter to a labeled line in a
             batch program.
    GRAFTABL Enables Windows to display an extended character set in graphics
             mode.
    HELP     Provides Help information for Windows commands.
    IF       Performs conditional processing in batch programs.
    LABEL    Creates, changes, or deletes the volume label of a disk.
    MD       Creates a directory.
    MKDIR    Creates a directory.
    MODE     Configures a system device.
    MORE     Displays output one screen at a time.
    MOVE     Moves one or more files from one directory to another directory.
    PATH     Displays or sets a search path for executable files.
    PAUSE    Suspends processing of a batch file and displays a message.
    POPD     Restores the previous value of the current directory saved by PUSHD.
    PRINT    Prints a text file.
    PROMPT   Changes the Windows command prompt.
    PUSHD    Saves the current directory then changes it.
    RD       Removes a directory.
    RECOVER  Recovers readable information from a bad or defective disk.
    REM      Records comments (remarks) in batch files or CONFIG.SYS.
    REN      Renames a file or files.
    RENAME   Renames a file or files.
    REPLACE  Replaces files.
    RMDIR    Removes a directory.
    SET      Displays, sets, or removes Windows environment variables.
    SETLOCAL Begins localization of environment changes in a batch file.
    SHIFT    Shifts the position of replaceable parameters in batch files.
    SORT     Sorts input.
    START    Starts a separate window to run a specified program or command.
    SUBST    Associates a path with a drive letter.
    TIME     Displays or sets the system time.
    TITLE    Sets the window title for a CMD.EXE session.
    TREE     Graphically displays the directory structure of a drive or path.
    TYPE     Displays the contents of a text file.
    VER      Displays the Windows version.
    VERIFY   Tells Windows whether to verify that your files are written
             correctly to a disk.
    VOL      Displays a disk volume label and serial number.
    XCOPY    Copies files and directory trees.

    C:\>Echo %TIME%
    13:15:23.50

    C:\>

    ALAN_BR

      Topic Starter


      Hopeful

      Thanked: 5
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: How can I identify dynamic environment variables - SET does not help
      « Reply #2 on: June 05, 2009, 01:35:28 PM »
      Bill

      My system response to "SET " is similar to yours.
      It fails to show volatile variables such as %TIME% and %DATE%,
      so I can only display their values if I know their names.

      I can use "ECHO %ACRONIS_PATH% and that will show me what I want to know,
      BUT ONLY if I correctly guess that ACRONIS_PATH is the name that I need.
      As it happens ACRONIS_PATH is not defined, so the only response is "Echo is OFF".

      What I am hoping for is some way to discover the names of volatile / hidden / secret variables, after which I can use ECHO %WHATEVER% etc. to find their values.

      Unfortunately the HELP list of commands does not appear to include anything to help in my quest.

      Incidentally, I am amused that halfway through that list is the line
      "HELP     Provides Help information for Windows commands."
      It looks like Microsoft do not know their DOS from their WINDOWS ! !

      I am hoping for a DOS or EXTENDED DOS type command to reveal dynamic variables,
      or failing that a simple VB script.

      If "push comes to shove" I can search the registry for dynamic variables I already know, such as DATE and TIME, and hope that I will find where these dynamic things are held.  But searching the registry takes so much time

      Alternatively, Google search "dynamic environmental variables" took only 0.39 Seconds to find 308,000,000 - but I am too lazy to inspect every result ! !

      Regards
      Alan

      devcom



        Apprentice

        Thanked: 37
        Re: How can I identify dynamic environment variables - SET does not help
        « Reply #3 on: June 05, 2009, 01:40:00 PM »
        you maybe want sth like this:
        Code: [Select]
        set ACRONIS_PATH
        Download: Choice.exe

        ALAN_BR

          Topic Starter


          Hopeful

          Thanked: 5
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: How can I identify dynamic environment variables - SET does not help
          « Reply #4 on: June 05, 2009, 02:46:23 PM »
          No, that would not work.

          I know that TIME is a dynamic variable,
          and "ECHO %TIME%" gives a result such as 21:21:59.16
          But SET TIME merely results in "Environment variable TIME not defined"
          because "SET " only deals with fixed variables and not dynamic.

          SET ACRONIS_PATH will always say "Environment variable ACRONIS_PATH not defined",
          regardless of whether it is totally undefined (and not the NAME I am looking for),
          and it will say the same even if it is defined as a dynamic variable.
          It will only admit to the presence of a FIXED variable.

          ACRONIS_PATH is just wishful thinking of what I would like to locate.
          I just do not know if ACRONIS have created a dynamic variable,
          and I do not know what name they might have used.

          I could capture all fixed and dynamic 8 character variables with
          Code: [Select]
          SET %%A%%B%%C%%D%%E%%F%%G%%H | FIND /V /I "not defined" >> set.txt
          and place that within 8 nested for loops that increment each of %%A, %%B etc. through all printable characters.
          but I also need to deal with possibilities of fewer then 8 characters and more than 8 characters.

          It would probably take as long as Deep Thought took to compute that "42" was the answer to
          "The meaning of Life and all that" ! !

          Regards
          Alan

          Dusty



            Egghead

          • I could if she would, but she won't so I don't.
          • Thanked: 75
          • Experience: Beginner
          • OS: Windows XP
          Re: How can I identify dynamic environment variables - SET does not help
          « Reply #5 on: June 06, 2009, 02:11:45 AM »
          Quote from: Alan_BR
          Incidentally, I am amused that halfway through that list is the line
          "HELP     Provides Help information for Windows commands."
          It looks like Microsoft do not know their DOS from their WINDOWS ! !

          Billrich's operating system is listed as Windows XP therefore the command list he posted is from Windows not DOS.  Windows XP does not include any version of DOS, CMD.exe is a Windows program, runs in a Window and interprets Dos-like commands.  The Help command quoted does Provide Help information for Windows commands.

          Below is a quote from Wiki:

          Quote
          Technically, cmd.exe is a Windows program that acts as a DOS-like command line interpreter. It is generally compatible, but provides extensions which address the limitations of COMMAND.COM:

          One good deed is worth more than a year of good intentions.

          ALAN_BR

            Topic Starter


            Hopeful

            Thanked: 5
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: How can I identify dynamic environment variables - SET does not help
            « Reply #6 on: June 06, 2009, 02:58:23 AM »
            Dusty

            I will concede that point to you !

            I believe command.com is similarly dependant upon Windows, and is generally less powerful than cmd.exe.

            One other amusing detail, Command.com has an identical help file -
            so identical that it has the same line
            "EXIT     Quits the CMD.EXE program (command interpreter)."

            Regards
            Alan

            Dusty



              Egghead

            • I could if she would, but she won't so I don't.
            • Thanked: 75
            • Experience: Beginner
            • OS: Windows XP
            Re: How can I identify dynamic environment variables - SET does not help
            « Reply #7 on: June 06, 2009, 04:27:15 PM »
            Trying to delve into Command.com throws up more quandaries than it solves.  I agree there is a dependency on Windows and also believe that there is a dependency on Cmd.exe.   Just look at the top line in the attachment "Microsoft (R) Windows DOS", if ever there was an oxymoron that must be one.  Also, the first line of Config.nt is "Windows MS-Dos Startup File".   

            The attachment shows what happens in Command.com if an attempt is made to echo a variable which is normally set by Cmd.exe, Cmd.exe is opened!!

            Lots to investigate but not enough time.

            Regards
            Dusty.

            [attachment deleted by admin]
            One good deed is worth more than a year of good intentions.

            ALAN_BR

              Topic Starter


              Hopeful

              Thanked: 5
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #8 on: June 07, 2009, 02:05:22 PM »
              Dusty

              I cannot obtain your result.

              Regardless of whether I use Command.com or Cmd.exe, I get the same result :-
              Code: [Select]
              C:\DOCUME~1\DAD>echo %cmdcmd line%
              %cmdcmd line%

              I launch the "DOS" thing via Windows => Run
              I have administrator privileges.
              I am using XP Home edition with SP3.
              ESET and Comodo keep me free of malware.

              I am puzzled by your qualification "a variable which is normally set by Cmd.exe".
              I know that "SET " has subtle differences between Command.com and Cmd.exe,
              but I tested and found that Command.com is identical to Cmd.exe in the ability to set and also display a variable that includes an embedded space.

              As a final test, I used Cmd.exe to launch Command.com after it created the variable "cmdcmd line", and then Command.com received that in its environment and was able to display without peculiarity thus :-
              Code: [Select]
              C:\Documents and Settings\Dad>set cmdcmd line=junk

              C:\Documents and Settings\Dad>echo %cmdcmd line%
              junk

              C:\Documents and Settings\Dad>command.com
              Microsoft(R) Windows DOS
              (C)Copyright Microsoft Corp 1990-2001.

              C:\DOCUME~1\DAD>echo %cmdcmd line%
              junk

              C:\DOCUME~1\DAD>

              I find it very strange that in your example, your entire command was typed in lower case, but the DOS response when repeating your command it capitalised the "echo" but not the "%cmdcmd line%".

              I so agree with your opening comment -"Trying to delve into Command.com throws up more quandaries than it solves".

              Another good way of filling a slow weekend is to investigate "setlocal enabledelayedexpansion".
              I have found that once it is enabled it has to remain enabled - otherwise "the results are undefined" (as often repeated by a 'C' tutor to our class when anyone tried to do anything outside the rules).
              Specifically, I believe the "setlocal ..." launches a new environment in which all further variables are created, regardless of whether they need to be in this "setlocal ..." state.  If this "setlocal .." is disabled than ALL variables defined BEFORE it was enabled are still known, but everything defined within the enabled state is now lost.

              Regards
              Alan

              Dusty



                Egghead

              • I could if she would, but she won't so I don't.
              • Thanked: 75
              • Experience: Beginner
              • OS: Windows XP
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #9 on: June 07, 2009, 05:09:22 PM »
              Alan_BR _ we're really beating this one to death, not sure if we'll ever reach any conclusion tho'.

              Quote
              Regardless of whether I use Command.com or Cmd.exe, I get the same result :-
              Code: [Select]
              C:\DOCUME~1\DAD>echo %cmdcmd line%
              %cmdcmd line%

              You've inserted a space between %cmdcmd and line% which changes the var name considerably, try it without the space.

              Quote
              I am puzzled by your qualification "a variable which is normally set by Cmd.exe"

              When Cmd.exe is invoked it automatically sets the var %cmdcmdline% without you having to use Set (not quite true but near enough).  Attached are a couple of screenshots of Cmd.exe having been invoked using Start>Run and using a shortcut with parameters (my choices).  You'll note that the /E and /V parameters are selected.

              Quote
              I find it very strange that in your example, your entire command was typed in lower case, but the DOS response when repeating your command it capitalised the "echo" but not the "%cmdcmd line%"

              I guess this was a preference of the writer of Command.com to emphasize the command being used, quite a common practice.

              The uses of Setlocal Enabledelayedexpansion are well documented here..

              Always stick with what your tutor tells you :||

              D.



              [attachment deleted by admin]
              « Last Edit: June 07, 2009, 09:44:12 PM by Dusty »
              One good deed is worth more than a year of good intentions.

              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #10 on: June 07, 2009, 06:29:33 PM »
              I just thought of this, set acro=%acronis_in_variable% should work...
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #11 on: June 07, 2009, 07:30:21 PM »
              I just thought of this, set acro=%acronis_in_variable% should work...


               ::)

              explain...
              I was trying to dereference Null Pointers before it was cool.

              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #12 on: June 07, 2009, 07:45:25 PM »
              Set will make the variable whatever is on the other sidde of the equal sign at the time the command is run. So if it is a dynamic variable, then you can get it...just like %random%.
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: How can I identify dynamic environment variables - SET does not help
              « Reply #13 on: June 07, 2009, 07:46:44 PM »
              and what, pray, is "%acronis_in_variable%"?
              I was trying to dereference Null Pointers before it was cool.

              gh0std0g74



                Apprentice

                Thanked: 37
                Re: How can I identify dynamic environment variables - SET does not help
                « Reply #14 on: June 07, 2009, 08:14:19 PM »
                SET totally fails to show dynamic environmental variables such as %TIME%

                Is there a special argument for SET to expose all dynamic variables ?
                Or is there a SET_DELUXE type of command that can reveal this information.

                Regards
                Alan

                so are you saying that ACRONIS has set a "dynamic variable" the same as variables like %TIME% or %RANDOM% and it doesn't show when you call set? can you show what your "set' command looks like?  cause AFAIK, %DATE% , %TIME% or %RANDOM% are little things that cmd.exe gives you out of convenience, they are not environment variables.