Creating and environment variable and using it in the same cmd window 
Author Message
 Creating and environment variable and using it in the same cmd window

I have a script to identify a videoadapter and then putting it in an
environment variable. When I,m running the vbs alone, I'm getting no
problem but if I am running it from a cmd file then sometimes I get the
environment variable and sometimes not.

If I am dbl-clicking on it, openning a cmd window and making a set
command.

Then I can see my env variable.
But as I put it inside a cmd file, the environment variable is not
always appearing. Sometimes it is and at a time it just stop to report
the videocontroller. But by manually dbl-clicking the vbs it is always
reporting the videocontroller.

Let me give more details:

Videoadapter.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_VideoController",,48)

For Each objItem in colItems
VideoAdapter = objItem.Description
Next

Set objShell = WScript.CreateObject("WScript.Shell")
'Set colEnvVars = objShell.Environment("SYSTEM")
Set colEnvVars = objShell.Environment("USER")
colEnvVars("VideoAdapter") = VideoAdapter

Videoadapter.cmd
wscript //B videoadapter.vbs
echo %videoadapter%
wscript //B "remove env.vbs"

Remove env.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_VideoController",,48)

For Each objItem in colItems
VideoAdapter = objItem.Description
Next

Set objShell = WScript.CreateObject("WScript.Shell")
Set colEnvVars = objShell.Environment("USER")
colEnvVars("VideoAdapter") = VideoAdapter
colEnvVars.remove("VideoAdapter")

As I can see, the environment variable is only available if I am opening
another cmd window. I tried to define it as volatile and process but the
only way to see that variable is from another window.
I tried too:
wscript //B videoadapter.vbs
cmd /k echo %videoadapter%
wscript //B "remove env.vbs" and what I get is "echo is activate"

Is it a way to create it and then using it from the same session?

Fran?ois Racine



Mon, 12 Sep 2005 11:20:18 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. kernel32 ERROR! how do I find it.

2. Help: BDE Copyright?

3. Creating and environment variable and using it in the same cmd window

4. create environment variable in windows 95

5. Create a new environment variable?

6. How to create a new Environment Variable

7. Creating a new environment variable?

8. Creating Environment Variables like program WINSET

9. Pascal 2 C Converter

10. Binary Tree Programming

11. changing cmd window icon does work when using compiled EXE

12. Naming The CMD Window Using Shell?

 

 
Powered by phpBB® Forum Software