Accessing Microsoft's Set Variables

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

Accessing Microsoft's Set Variables

Post by Mundekis » Mon Jun 30, 2003 3:20 pm

Does anyone know how to directly access Microsofts environment-variable that are Set using the Microsoft SET Command. I know I can send those variables to a file then read them but I'm looking to directly access them. I'm using Macro Scheduler PRO 7.2.036.

Lumumba

Post by Lumumba » Mon Jun 30, 2003 3:35 pm

These system variables are part of MSched (check online help).



OS_VER Operating System
WIN_DIR Windows Directory Path

SYS_DIR Windows System Directory Path

The above variables store their values in upper case.

USER_NAME Current Username
COMPUTER_NAME Computer Name



Maybe there are some additional ones in the current/your release of MSched, which I don't have.

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

System Variables

Post by Mundekis » Mon Jun 30, 2003 3:55 pm

You are correct, the System Set Variables are contained their, but I need to access other variables that are set by other programs that can be displayed by using the DOS window SET Command.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Jun 30, 2003 5:36 pm

Hello Mundekis...

Try this, I think you will have what you want.

//===============================

//Redirect system variables to a file
Let>RP_WINDOWMODE=0
Run Program>c:\windows\command.com /c SET >c:\temp\ms_vars.txt
Let>Line=0

Label>GetValues
//Read each line in the file
Add>Line,1
ReadLn>c:\temp\ms_vars.txt,%Line%,LineValue
If>%LineValue%=##EOF##,Done
//Locate postion of "=" character and create values for MidStr command
Position>=,%LineValue%,1,BreakHere
Let>StartHere=BreakHere+1
LEt>EndHere=BreakHere-1
MidStr>%LineValue%,1,%EndHere%,Key
MidStr>%LineValue%,%StartHere%,128,Value
//Display system variables and their values.
MessageModal>The value for %Key% is %CRLF%%Value%
Goto>GetValues

Label>Done

//=================
Hope this helps......good luck,
Bob

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

DOS Set Variables Command

Post by Mundekis » Mon Jun 30, 2003 8:32 pm

Bob, I've done that in the past, I was just woundering if I could get some direct access to those variables, for they're out their.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jul 01, 2003 4:04 am

Just had a thought, no time to get details, but I will bet you can access those variables with a VB function.........stay tuned, I bet someone will confirm that with an exact example.......

Lumumba

Post by Lumumba » Tue Jul 01, 2003 5:46 am

Here's one sysvar from my NTBox (used: cmd /k set).

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

I found it in the registry as well (searched for "PATHEXT" with regedit.exe). Therefore you should be able to read the registry with:

Code: Select all

RegistryReadKey>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment,PATHEXT,PathExtension
Message>%PathExtension%
The sysvar "Path" is on the same path. Feel free to check for others ...

Lumumba

Post by Lumumba » Tue Jul 01, 2003 10:11 am

Maybe usefull if you've to deal with environment variables more often: XSET!

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

DOS SET Variables

Post by Mundekis » Tue Jul 01, 2003 12:51 pm

Thanks the Registry method is a lot closer to what I'm looking for but that method will not work with Windows 95 and I entend to use this across 95 and NT platforms.

Lumumba

Post by Lumumba » Tue Jul 01, 2003 1:06 pm

Isn't there anymore a registry in W9x?

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

SET Variables in Win95

Post by Mundekis » Tue Jul 01, 2003 7:28 pm

Yes Windows 95 does of course have a registry however at the time Microsoft's employees at the NT side of the house did not talk to the DOS based Windows side, and a lot of things were left out. Thats why it took so long to pull the two OS's together. Needless to say those SET values are left out in the Windows 95 registries.

Lumumba

Post by Lumumba » Wed Jul 02, 2003 5:43 am

So check XSET (see the link in my previous thread). Maybe you could sync both systems/OS with setting the missing ones in W9x.

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

Accessing MS SET VARIABLes

Post by Mundekis » Thu Jul 10, 2003 12:56 pm

Thanks for all the input, my answer is simple and comes inpart from Chaoticz old post.

Create the Executable then pass the environment variable.

//MsgScript
messagemodal>%msg%


run MsgScript.exe /msg=%dosvariable%

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Oct 31, 2003 11:37 pm

I stumbled across the following script today that should provide a solution. The full page of information can be located here:
http://home.att.net/~wshvbs/theScriptBoutiquePage.htm

The vbs code is here:
' enumerate "process" environment variables, jw 20Mar01
' (inspired by vbs ng example, posted by mikHar 20Mar01)...
Option Explicit

Dim oSH ' as object
Dim colProcEnv ' as collection
Dim sGetMyVar ' as string

Set oSH = WScript.CreateObject("WScript.Shell")
Set colProcEnv = oSH.Environment("PROCESS") ' applies to win9x

' show enviromnent variables (as found)...
Call DisplayEnvVar("Current Listing of Process Environment Variables... ")

' add a new environment variable to the list...
colProcEnv("myProcVar") = "d:\Apps\myApp"

' show env vars again...
Call DisplayEnvVar("Environment Variables (hopefully with your addition showing)... ")

' retrieve the env var that you just added...
sGetMyVar = colProcEnv("myProcVar")
MsgBox "this is the env var you added: " & sGetMyVar


' delete the env var you just added...
colProcEnv.Remove("myProcVar")

' show env vars one last time..
Call DisplayEnvVar("Environment Variables (with your addition removed)... ")

Set colProcEnv = nothing ' clean up
Set oSH = nothing
WScript.Quit

Sub DisplayEnvVar(sTitle)
Dim sResult, sEnvVar ' as string

sResult = sTitle & vbCrLf & vbCrLf

for each sEnvVar in colProcEnv
' add this one to the listing...
sResult = sResult & " " & sEnvVar & vbCrLf
Next

MsgBox(sResult) ' show the results
End Sub
When you run the script, you will get a message box listing the variables with output similar to the SET command.

But the few lines in bold red are the lines that could be used to extract the variable value that you want. You could Execute>ThisScript.vbs and use "sGetMyVar" value.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts