toofewacres Posted February 6, 2018 Posted February 6, 2018 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
Earthshine Posted February 6, 2018 Posted February 6, 2018 (edited) 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 February 6, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted February 6, 2018 Posted February 6, 2018 (edited) #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. Edited February 6, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted February 6, 2018 Posted February 6, 2018 (edited) 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 February 6, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted February 6, 2018 Posted February 6, 2018 one more way is to get the process and look at it's command line. you can tell what everything resolves to there. My resources are limited. You must ask the right questions
toofewacres Posted February 6, 2018 Author Posted February 6, 2018 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...
Earthshine Posted February 6, 2018 Posted February 6, 2018 Get a handle to each process that you’re interested in and look at it’s command line and all your data will be there My resources are limited. You must ask the right questions
toofewacres Posted February 6, 2018 Author Posted February 6, 2018 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...
toofewacres Posted February 6, 2018 Author Posted February 6, 2018 Ok, I can get the handle by using WinList("App.name"). Once I have the handle, now what do I do?
BrewManNH Posted February 6, 2018 Posted February 6, 2018 Try here, not AutoIt but if you're savvy you can figure it out. https://stackoverflow.com/questions/5470698/read-environment-variables-from-a-process-in-c-sharp https://stackoverflow.com/questions/5454667/how-to-get-the-process-environment-block-peb-from-extern-process 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 GudeHow 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
Earthshine Posted February 6, 2018 Posted February 6, 2018 (edited) 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 February 6, 2018 by Earthshine My resources are limited. You must ask the right questions
toofewacres Posted February 6, 2018 Author Posted February 6, 2018 Thanks for Info. I found these too. But, I'm not that deep into programming, so this went over my head in a hurry.
toofewacres Posted February 7, 2018 Author Posted February 7, 2018 I found this info but don't know how to take advantage of it. It's beyond my knowledge base... https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.environmentvariables(v=vs.110).aspx
Earthshine Posted February 7, 2018 Posted February 7, 2018 so, in task manager, can you enable the command line column and post back what it finds for, say, 3 processes you care about. post the command line of each and let's see if your info is there before coding. My resources are limited. You must ask the right questions
Earthshine Posted February 7, 2018 Posted February 7, 2018 the code in that link will display all running processes in an array. column 9 is the command line for each. run that and see if you can see your variables in the command line column My resources are limited. You must ask the right questions
toofewacres Posted February 7, 2018 Author Posted February 7, 2018 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
toofewacres Posted February 13, 2018 Author Posted February 13, 2018 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?
toofewacres Posted February 15, 2018 Author Posted February 15, 2018 Has anyone implemented anything like what is found in this link? https://www.codeproject.com/Articles/25647/Read-Environment-Strings-of-Remote-Process This is basically what I am looking for so that I can read a specific variable in a specific process.
toofewacres Posted February 18, 2018 Author Posted February 18, 2018 (edited) 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 February 18, 2018 by toofewacres added more info
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now