Results 1 to 3 of 3

Thread: set system environment variable

  1. #1
    Wilderd
    Guest

    Question set system environment variable

    Is there a way to set a system variable with a VB application? I need to permanently set a variable on the users computer. I believe most installation programs do this sort of thing so I'm hoping it isn't too difficult (I'm fairly new with VB). Any help you can offer will be greatly appreciated.

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Not very sure but have a look at this:
    Code:
    Environ Function
          
    
    Returns the String associated with an operating system environment variable. 
    
    Syntax
    
    Environ({envstring | number})
    
    The Environ function syntax has thesenamed arguments:
    
    Part Description 
    envstring Optional.String expression containing the name of an environment variable. 
    number Optional.Numeric expression corresponding to the numeric order of the environment string in the environment-string table. The numberargument can be any numeric expression, but is rounded to a whole number before it is evaluated. 
    
    
    Remarks
    
    If envstring can't be found in the environment-string table, a zero-length string ("") is returned. Otherwise, Environ returns the text assigned to the specified envstring; that is, the text following the equal sign (=) in the environment-string table for that environment variable.
    
    If you specify number, the string occupying that numeric position in the environment-string table is returned. In this case, Environ returns all of the text, including envstring. If there is no environment string in the specified position, Environ returns a zero-length string.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    jim mcnamara
    Guest
    They (env variables) cannot be modified permanently from VB code running under Windows, because every time a reboot occurs, they are set again from a boot script - AUTOEXEC

    Your installation code has to modify AUTOEXEC for that to happen.
    ie. ---------------------------
    Code:
    ' the [whatever] depends on the OS you're using
    FileCopy "c:\AUTOEXEC.[whatever]" , "c:\AUTOEXEC.OLD" 
    Open "c:\AUTOEXEC.[whatever]" for append as #1
    Print #1, "SET myvar = something"
    Close #1


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width