Can windows does the below easily?

  • Thread starter Thread starter Sarah Tanembaum
  • Start date Start date
S

Sarah Tanembaum

What would be the best way to set a bunch of system-wide environment
variables(I have about 1000 lines) from a script instead of GUI?

I tried using 'setx /m' but it becomes to cumbersome.

e.g:

setx /M PFI="c:\Program Files"
setx /M SRO="%SystemRoot%"
setx /M S32="%SRO%\system32"

setx /M P0=%PFI%;%SR%;%S32%
....
etc,etc,etc...

Thanks
 
Sarah said:
What would be the best way to set a bunch of system-wide environment
variables(I have about 1000 lines) from a script instead of GUI?

I tried using 'setx /m' but it becomes to cumbersome.

e.g:

setx /M PFI="c:\Program Files"
setx /M SRO="%SystemRoot%"
setx /M S32="%SRO%\system32"

setx /M P0=%PFI%;%SR%;%S32%
...
etc,etc,etc...

Thanks

Well, you should be able to parse a text file by using the 'for' command
and set these variables fairly easily. You may want to check in your
script, though, that the variable doesn't already exist, before changing
it.

hth
 
Thanks Ricardo.

But setting variable is also changing some registry setting, isn't it? Also,
there is limitation on path length.

Does windows has variable called, e.g. DLLPaths for all DLL files and PATH
for executable files?

Thanks
 
What do you need all these new variables for? Are you trying to create a custom PATH to determine the search path when launching a
binary? Is this a one-time need for the PATH(s)? Or are you trying to set it globally for all eternity? Or just for the current
user?

I imagine it is usually best to try to stick with standard system environment variables instead of trying to create your own custom
variables that will only work in your environment.

If you are using batch files you can write a subroutine which "temporarily" sets the %PATH% environment variable (or any variable
name of your choosing) to include (i.e. append or prepend) some additonal path you care about (using setlocal and endlocal to
establish the lifetime of when the custom path is valid). Using this technique your script will be more portable across all Windows
machines, instead of requiring that it be run on a machine where a custom %PFI%, %SRO%, or %S32% variable is set.

Your original question is "What would be the best way to set a bunch of system-wide environment variables from a script instead of
GUI". Ricardo is right that one way is to use a for loop to enumerate all pairs of variable names and values in a text file. You
can do the same thing in JScript or VBScript, or even perl if you have access to perl. But in Windows you do require a program like
SETX.EXE to set an environment variable globally across all users or just for the current user. This is because changing the system
environment variables globally requires a WM_SETTINGCHANGE message be broadcast to all windows in order for the change to take
effect immediately. You can edit the appropriate registry keys, but the change won't really take effect until you logoff and logon
or reboot the machine.

BTW, I have never heard of a "DLLPaths" variable for searching for DLLs, at least not in the context of Windows environment
variables. It sounds familiar, though, as if I've heard about it somewhere, perhaps related to some specific Windows API parameters
or something.

Sarah Tanembaum said:
Thanks Ricardo.

But setting variable is also changing some registry setting, isn't it? Also,
there is limitation on path length.

Does windows has variable called, e.g. DLLPaths for all DLL files and PATH
for executable files?

Thanks
 
There is no environmental variable. There is the new dll folder which is where XP looks for dlls (with SP1 I think) but is a registry key.

Perhaps you should explain your problem and not ask questions about what you think the solution is.

--
----------------------------------------------------------
'Not happy John! Defending our democracy',
http://www.smh.com.au/articles/2004/06/29/1088392635123.html

David Holcomb said:
What do you need all these new variables for? Are you trying to create a custom PATH to determine the search path when launching a
binary? Is this a one-time need for the PATH(s)? Or are you trying to set it globally for all eternity? Or just for the current
user?

I imagine it is usually best to try to stick with standard system environment variables instead of trying to create your own custom
variables that will only work in your environment.

If you are using batch files you can write a subroutine which "temporarily" sets the %PATH% environment variable (or any variable
name of your choosing) to include (i.e. append or prepend) some additonal path you care about (using setlocal and endlocal to
establish the lifetime of when the custom path is valid). Using this technique your script will be more portable across all Windows
machines, instead of requiring that it be run on a machine where a custom %PFI%, %SRO%, or %S32% variable is set.

Your original question is "What would be the best way to set a bunch of system-wide environment variables from a script instead of
GUI". Ricardo is right that one way is to use a for loop to enumerate all pairs of variable names and values in a text file. You
can do the same thing in JScript or VBScript, or even perl if you have access to perl. But in Windows you do require a program like
SETX.EXE to set an environment variable globally across all users or just for the current user. This is because changing the system
environment variables globally requires a WM_SETTINGCHANGE message be broadcast to all windows in order for the change to take
effect immediately. You can edit the appropriate registry keys, but the change won't really take effect until you logoff and logon
or reboot the machine.

BTW, I have never heard of a "DLLPaths" variable for searching for DLLs, at least not in the context of Windows environment
variables. It sounds familiar, though, as if I've heard about it somewhere, perhaps related to some specific Windows API parameters
or something.
 
Dear David, I need to change ghe environment variable globabally. I reallize
that when I change the env variable using setx, it does not change right
away. I have to log off and log back on for the change to take effect.
Thanks

David Holcomb said:
What do you need all these new variables for? Are you trying to create a
custom PATH to determine the search path when launching a
binary? Is this a one-time need for the PATH(s)? Or are you trying to
set it globally for all eternity? Or just for the current
user?

I imagine it is usually best to try to stick with standard system
environment variables instead of trying to create your own custom
variables that will only work in your environment.

If you are using batch files you can write a subroutine which
"temporarily" sets the %PATH% environment variable (or any variable
name of your choosing) to include (i.e. append or prepend) some additonal
path you care about (using setlocal and endlocal to
establish the lifetime of when the custom path is valid). Using this
technique your script will be more portable across all Windows
machines, instead of requiring that it be run on a machine where a custom
%PFI%, %SRO%, or %S32% variable is set.
Your original question is "What would be the best way to set a bunch of
system-wide environment variables from a script instead of
GUI". Ricardo is right that one way is to use a for loop to enumerate all
pairs of variable names and values in a text file. You
can do the same thing in JScript or VBScript, or even perl if you have
access to perl. But in Windows you do require a program like
SETX.EXE to set an environment variable globally across all users or just
for the current user. This is because changing the system
environment variables globally requires a WM_SETTINGCHANGE message be
broadcast to all windows in order for the change to take
effect immediately. You can edit the appropriate registry keys, but the
change won't really take effect until you logoff and logon
or reboot the machine.

BTW, I have never heard of a "DLLPaths" variable for searching for DLLs,
at least not in the context of Windows environment
variables. It sounds familiar, though, as if I've heard about it
somewhere, perhaps related to some specific Windows API parameters
or something.
 
I've not heard of anyone creating 1000 variables before. It sounds whatever you are doing is probably better done another way.
 
Thanks David.

Perhaps you can tell me what is the directory name for Windows XP SP1 and
also for Windows Server 2003.

What I'm trying to do is to separate the system OS exec & dlls(from
Microsoft OS installation) and application exec&dlls(third party apps or MS
Apps). I'm yet to find the better way on how to separate those. Anyone has
any idea?

Perhaps I do not want to change the directory structure much but how do I
prevent any application installation that put its DLL and/or EXECUTABLE in
the<SystemDrive> \Windows or <SystemDrive>\Windows\System32 directory but
put them in their corresponding apps directory in the <SystemDrive>\Program
Files\<XYZ Application>\

Thanks.


There is no environmental variable. There is the new dll folder which is
where XP looks for dlls (with SP1 I think) but is a registry key.

Perhaps you should explain your problem and not ask questions about what you
think the solution is.

--
----------------------------------------------------------
'Not happy John! Defending our democracy',
http://www.smh.com.au/articles/2004/06/29/1088392635123.html

David Holcomb said:
What do you need all these new variables for? Are you trying to create a
custom PATH to determine the search path when launching a
binary? Is this a one-time need for the PATH(s)? Or are you trying to
set it globally for all eternity? Or just for the current
user?

I imagine it is usually best to try to stick with standard system
environment variables instead of trying to create your own custom
variables that will only work in your environment.

If you are using batch files you can write a subroutine which
"temporarily" sets the %PATH% environment variable (or any variable
name of your choosing) to include (i.e. append or prepend) some additonal
path you care about (using setlocal and endlocal to
establish the lifetime of when the custom path is valid). Using this
technique your script will be more portable across all Windows
machines, instead of requiring that it be run on a machine where a custom
%PFI%, %SRO%, or %S32% variable is set.
Your original question is "What would be the best way to set a bunch of
system-wide environment variables from a script instead of
GUI". Ricardo is right that one way is to use a for loop to enumerate all
pairs of variable names and values in a text file. You
can do the same thing in JScript or VBScript, or even perl if you have
access to perl. But in Windows you do require a program like
SETX.EXE to set an environment variable globally across all users or just
for the current user. This is because changing the system
environment variables globally requires a WM_SETTINGCHANGE message be
broadcast to all windows in order for the change to take
effect immediately. You can edit the appropriate registry keys, but the
change won't really take effect until you logoff and logon
or reboot the machine.

BTW, I have never heard of a "DLLPaths" variable for searching for DLLs,
at least not in the context of Windows environment
variables. It sounds familiar, though, as if I've heard about it
somewhere, perhaps related to some specific Windows API parameters
or something.
 
Perhaps I exaggerated the number, but you get the idea for lots and lots of
them depending on how many apps installed in the system.

e.g: if each apps has 5-10 environment variable/registry setting, and you
have 70 apps(big/small/medium) in the system.

Thanks

I've not heard of anyone creating 1000 variables before. It sounds whatever
you are doing is probably better done another way.
 
Sarah Tanembaum said:
Perhaps I exaggerated the number, but you get the idea for lots and lots
of
them depending on how many apps installed in the system.

e.g: if each apps has 5-10 environment variable/registry setting, and you
have 70 apps(big/small/medium) in the system.

In this day and age, it's rather unusual for the majority of applications to
create an environment variable, let alone 5-10. That's just something
developers should back away from.
 
Back
Top