Jump to content

Environment variable by Process


Recommended Posts

I am trying to get an environment variable from a process and am struggling with how to get the variable specific to a Windows handle.

I know the handle from WinList, but I need to change to each handle and get the value of a environment variable labeled %SAInstance% that is set internal to the process as it starts up. 

EnvGet seems to only get System and User variables that are common to the entire system, not process specific ones. I'm sure there is a way, but I'm just not figuring it out.

Thanks

 

Link to comment
Share on other sites

those are created by some batch file. so probably not. have to test. Visual Studio has batch files for loading their build environment. I will test and see if I can pick up those (while the app is running)

i am willing to test if you provide me some test code. i don't want to write it for you and I am sure you don't want that either.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Retrieve the value of the environment variable %APPDATA%.
    ; When you assign or retrieve an envorinment variable you do so minus the percentage signs (%).
;~  ShellExecute("C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat")
    Local $sEnvVar = EnvGet("VS120COMNTOOLS")

    ; Display the value of the environment variable %APPDATA%.
    MsgBox($MB_SYSTEMMODAL, "", "The environment variable %VS120COMNTOOLS% has the value of: " & @CRLF & @CRLF & $sEnvVar) ; This returns the same value as the macro @AppDataDir does.
EndFunc   ;==>Example

results in: so it does read the ones set up by other apps. if those are set at runtime, then you would need to find a way to read those. run the script after those have been loaded I guess. but AutoIt is having trouble reading all of them, so maybe you are onto something.

Capture.PNG

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

so this is how you want to do it because apps or bat files may be involved at runtime. read the stdout

https://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm

search through your array after for the information you need. Once for each app. run it, and take that handle and hook the stdout and see it there in other words.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Yes, that works for Environment variables that are set at system level. I have a application that sets Environment variables for each instance that it runs. I can run Process Explorer and see the variables for each instance that it runs. (see jpg attached) The variable SAInstance is not available at a "Set" command at a cmd window.  I have code that is the same idea as what you provided, but it cannot read "SAInstance" 

I need something like https://msdn.microsoft.com/en-us/library/windows/desktop/ms683187(v=vs.85).aspx which is getting over me head...

 

2018-02-06_16h20_27.jpg

Link to comment
Share on other sites

Also, the app that runs sets the variables during startup, but there is no output to console. I can internal to the app run a VBScript that will open as a child of the app and I can read the variable and then write it out to a text file. So I just need to figure out how to get to specific process environment space and read the variable from there...

 

Link to comment
Share on other sites

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

14 minutes ago, toofewacres said:

Also, the app that runs sets the variables during startup, but there is no output to console. I can internal to the app run a VBScript that will open as a child of the app and I can read the variable and then write it out to a text file. So I just need to figure out how to get to specific process environment space and read the variable from there...

 

I’ll post back tomorrow with code

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

No, the variable info is not in the command line.

Here's what the command line says...

"C:\Program Files\Autodesk\Moldflow Synergy 2018.2\bin\synergy.exe" "T:\PROJECTS\GM\T1XX\Door\Moldflow\CAE 10835\Analysis\Cadillac Coreback\Rear_LWB_Coreback\Rear LWB Coreback.mpi"

The.mpi file is basically a CAD file that is opened with the synergy.exe

 

Link to comment
Share on other sites

I still haven't figured this one out..I can get the Windows handle, ProgID, and the CLSID for the running process (which is started outside of Autoit), but I can't seem to figure out how to read the Environment variables for that particular process instead of the system wide variables.

Any help from anybody? 

Link to comment
Share on other sites

Subz, thanks for the input. I looked at that example and it only looks at system Enviroment variable, not process specific. But, the code might be a help if I can figure out how to point to the process specific PEB and understand what format it is in..(ANSI,OEM, etc is confusing me)

I found this info: https://sites.google.com/site/ascend4ntscode/processfunctions and I am trying to figure out the PEB address stuff. I think I am able to grab the block from the process I want but I'm not sure what to do with the output from the  _ProcessUDGetPEB() yet. still digging..I just don't grasp the pointers, extracting variables from the block, etc. yet.

I think I am getting closer, but it's a stretch for me from an experience standpoint...it's a far reach from simple macros, etc. !!

 

Edited by toofewacres
added more info
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...