Announcement

Collapse
No announcement yet.

how to keep set (variable) Win7

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to keep set (variable) Win7

    I'd like to set some variables with a batch file witch 'd like to stay "permanent" for at least the last/active session.

    in example:
    Code:
    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    :OS_Check
    IF EXIST "%ProgramFiles(x86)%" (GOTO x64) ELSE IF EXIST "%ProgramFiles%" (GOTO x86) ELSE GOTO ERROR
    GOTO:EOF
    
    :x64
    rem OS = x64
    SET "OS_LKSVDD=x64"
    GOTO:EOF
    
    :x86
    rem OS = x86
    SET "OS_LKSVDD=x86"
    GOTO:EOF
    
    :ERROR
    echo.
    echo.
    ECHO ERROR:
    ECHO No "Program Files (x86)" and/or No "Program Files" path found?
    ECHO check: %systemroot%\LOGS\LKSVDD\Tim\log.Check_OS.txt for more info
    ECHO ERROR @ %DATE% %TIME%: Nothing ToDo? No "Program Files (x86)" and/or No "Program Files" path found? >> %systemroot%\LOGS\LKSVDD\Tim\log.Check_OS.txt 2>&1
    echo.
    rem \/ HALT ON ERROR \/
    PAUSE
    GOTO:EOF
    I'd like to reuse the variable OS_LKSVDD how should I do this?
    If the above batch script stops all SET variables are lost, if I run cmd and type SET "OS_LKSVDD=x64" for example the variable does get "remembered" by the system, how come this doesn't happen when I use this in a script? Is there some trick needed?

    With kind regards, Tim

  • #2
    Re: how to keep set (variable) Win7

    PS. without editing the registery, i'd like the bastch command SET,
    now I'v got to figure out a way so that the variables "stay active" even when the batch is closed/ended...

    Comment


    • #3
      Re: how to keep set (variable) Win7

      Originally posted by APOC View Post
      PS. without editing the registery, i'd like the bastch command SET,
      now I'v got to figure out a way so that the variables "stay active" even when the batch is closed/ended...
      You cannot uses the SET command to set Environmental Variables for the user.

      To set Environmental Variable for the machine or for the currently logged on user you should use eighter the reskit tool SETX.exe OR a 3rd party tool called SetEnv.exe.

      What your batch currently does is setting the new variable for what is called the 'Process Environment'.
      Also if you run cmd and then type SET "OS_LKSVDD=x64" this will be, like with running a batch, gone when ending the opened instance of the dos box.
      A process environment variable is set during a process (or in one of its subprocesses) and only available for the process thats created it and in any subprocesses lower in the tree that were created after setting the variable. It is gone when the process that created it is finished.

      http://forums.petri.com/showthread.p...403#post183403


      /Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: how to keep set (variable) Win7

        I was "afraid" of that thanks for pointing it out and for a possible work around, really appreciated...

        Comment

        Working...
        X