Accessing Microsoft's Set Variables
Moderators: Dorian (MJT support), JRL
Accessing Microsoft's Set Variables
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.
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.
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.
System Variables
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Hello Mundekis...
Try this, I think you will have what you want.
Bob
Try this, I think you will have what you want.
Hope this helps......good luck,
//===============================
//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
//=================
Bob
DOS Set Variables Command
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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:
The sysvar "Path" is on the same path. Feel free to check for others ...
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%
DOS SET Variables
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.
SET Variables in Win95
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.
Accessing MS SET VARIABLes
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%
Create the Executable then pass the environment variable.
//MsgScript
messagemodal>%msg%
run MsgScript.exe /msg=%dosvariable%
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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:
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.
http://home.att.net/~wshvbs/theScriptBoutiquePage.htm
The vbs code is here:
When you run the script, you will get a message box listing the variables with output similar to the SET command.' 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
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!
Bob
A humble man and PROUD of it!