|
-
Jun 20th, 2001, 02:51 PM
#1
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.
-
Jun 20th, 2001, 03:57 PM
#2
Frenzied Member
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.
-
Jun 20th, 2001, 05:34 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|