rudi Posted May 31, 2010 Share Posted May 31, 2010 Hi. At Google I'm obviously searching with the wrong search terms for a pretty messed up environment I need to write a custom "which.exe", that presents in a list, where all the different versions of outdated tools (EXE, CMD, BAT) are spread throughout all the folders in the path folders. At very first I want to read, what extensions are executable at *THIS* workstation. I know, that this is defined in either *ONE* registry value, or in several registry values beyond *ONE* regstry key. I miss to find, which registry value (key) is holding the extensions, that are currently executable. Who can point out the right value/key, please? In return I'll post my which.exe Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
rudi Posted May 31, 2010 Author Share Posted May 31, 2010 Hi. It's in the environment: %pathext% Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
UEZ Posted May 31, 2010 Share Posted May 31, 2010 Or in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT BR, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
rudi Posted May 31, 2010 Author Share Posted May 31, 2010 Hi. Maybe somebody else can make use of this script as well: expandcollapse popup; Which.exe -> where is a program found in path (and current directory) ; Autoit Version 3.3.4.0 (not the latest one, currently, I know) ; Author: Rudolf Thilo ; Syntax: which.exe <program/scriptname> (without extension) ; Example: which.exe robocopy ; Action: searches the current directory and all folders specified in the %path% environment variable ; for a *FILE* with one of the extensions specified in the environment variable %pathext% ; Output: 1.) displays the path variable, one folder per line ; 2.) displays the search results (if any), including the file version (if found in the file) #Region Check parameter(s) If Not $cmdline[0] = 1 Then info() $exit = True Else $SearchMe = $cmdline[1] $exit = False EndIf #EndRegion Check parameter(s) #Region get Env variables, prepare script variables $PathExtArr = StringSplit(EnvGet("pathext"), ";") $ExtString = "" For $i = 1 To $PathExtArr[0] $ExtString &= $PathExtArr[$i] & @CRLF Next $Path = EnvGet("path") If StringRight($Path, 1) = ";" Then $Path = StringTrimRight($Path, 1) $PathArr = StringSplit($Path, ";") $PathString = "(aktuelles Verzeichnis) " & @WorkingDir & @CRLF For $i = 1 To $PathArr[0] If Not (StringRight($PathArr[$i], 1) = "\") Then $PathArr[$i] &= "\" $PathString &= $PathArr[$i] & @CRLF Next MsgBox(0, "Suchreihenfolge im Pfad:", $PathString) If $exit Then Exit $Found = $SearchMe & " wurde hier im Pfad gefunden:" & @CRLF & @CRLF $Count = 1 $WD = @WorkingDir If not (StringRight($WD, 1) = "\") Then $WD &= "\" ; trailing backslash required, except for root folders... #Region get Env variables, prepare script variables #Region Search for executables in current dir For $i = 1 To $PathExtArr[0] $NXT = $WD & $SearchMe & $PathExtArr[$i] ; ConsoleWrite($NXT & @CRLF) $Attrib = FileGetAttrib($NXT) If $Attrib And Not StringInStr($Attrib, "D") Then ; it's a file ;) $Found &= $Count & ". (Aktuelles Verzeichnis) " & $NXT & getver() & @CRLF $Count += 1 EndIf Next #EndRegion Search for executables in current dir #Region Search for executables throughout folders given in %PATH% For $k = 1 To $PathArr[0] For $i = 1 To $PathExtArr[0] $NXT = $PathArr[$k] & $SearchMe & $PathExtArr[$i] ; ConsoleWrite($NXT & @CRLF) $Attrib = FileGetAttrib($NXT) If $Attrib And Not StringInStr($Attrib, "D") Then ; it's a file ;) $Found &= $Count & ". " & $NXT & getver() & @CRLF $Count += 1 EndIf Next Next #Region Search for executables throughout folders given in %PATH% #Region display results If $Count > 1 Then MsgBox(0, $SearchMe & " wurde " & $Count - 1 & " mal im Pfad gefunden:", $Found) Else MsgBox(0, $SearchMe & " wurde *NICHT* im Pfad gefunden", _ "Gesucht wurde nach: """ & $SearchMe & """ mit diesen Erweiterungen:" & @CRLF & $ExtString) EndIf #EndRegion display results #Region Functions Func info() MsgBox(0, @ScriptName, "Erwartet als 1. und einzigen Parameter einen ausführbaren Dateinamen *OHNE* Extension, der dann in allen Positionen des Pfades gesucht und angezeigt wird.", 10) EndFunc ;==>info Func getver() $ver = FileGetVersion($NXT) If @error Then Return "" Else Return " (v" & $ver & ")" EndIf EndFunc ;==>getver #EndRegion Functions Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
rudi Posted May 31, 2010 Author Share Posted May 31, 2010 (edited) Hi. Or in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT Of course. But this registry value is presenting environment variables in it, e.g. %systemroot%. Therefore I made use of the environment variables %PATH% and %PATHEXT%, basically because I was too lazy to workout how to correctly substitute %VARIABLE% occurences within the reg value. This does *NOT* work, EnvGet("$1") is trying to resolve "%$1%" as environment variable: $key="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val="PATHEXT" $PathExt=RegRead($key,$val) $PathExt=StringRegExpReplace($PathExt,"(%[^%]*%)",EnvGet("$1")) ; $1 is *NOT* populated with the regex backreference, and this wouldn't be the final syntax anyways, I think... Regards, Rudi. Edited May 31, 2010 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
ResNullius Posted June 4, 2010 Share Posted June 4, 2010 @Rudi, I have no environment variables in my PATHEXT registry value. But anyway, the following code should do what you want if any do exist: $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATHEXT" $PathExt = RegRead($key, $val) MsgBox(4096, "", "PathExt Before: " & $PathExt) $aEnvVars = StringRegExp($PathExt, "%([^%]*?)%", 3) For $i = 0 To UBound($aEnvVars) - 1 $PathExt = StringRegExpReplace($PathExt, "(%\Q" & $aEnvVars[$i] & "\E%)", EnvGet($aEnvVars[$i])) Next MsgBox(4096, "", "PathExt After: " & $PathExt) Link to comment Share on other sites More sharing options...
rudi Posted June 8, 2010 Author Share Posted June 8, 2010 Hi. I meant PATH, not PATHEXT. #include <array.au3> $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATH" $PATH = RegRead($key, $val) MsgBox(4096, "", "Path Before: " & @LF & PathSplit()) $aEnvVars = StringRegExp($PATH, "%([^%]*?)%", 3) For $i = 0 To UBound($aEnvVars) - 1 $PATH = StringRegExpReplace($PATH, "(%\Q" & $aEnvVars[$i] & "\E%)", EnvGet($aEnvVars[$i])) Next MsgBox(4096, "", "PATH After: " & @LF & PathSplit()) Func PathSplit() Local $PathArr = StringSplit($PATH, ";"), $String = "", $i For $i = 1 To $PathArr[0] $String &= @lf & $i & ": " & $PathArr[$i] Next Return $String EndFunc ;==>PathSplit Thanks for your nice code. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
ResNullius Posted June 9, 2010 Share Posted June 9, 2010 Hi. I meant PATH, not PATHEXT. #include <array.au3> $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATH" $PATH = RegRead($key, $val) MsgBox(4096, "", "Path Before: " & @LF & PathSplit()) $aEnvVars = StringRegExp($PATH, "%([^%]*?)%", 3) For $i = 0 To UBound($aEnvVars) - 1 $PATH = StringRegExpReplace($PATH, "(%\Q" & $aEnvVars[$i] & "\E%)", EnvGet($aEnvVars[$i])) Next MsgBox(4096, "", "PATH After: " & @LF & PathSplit()) Func PathSplit() Local $PathArr = StringSplit($PATH, ";"), $String = "", $i For $i = 1 To $PathArr[0] $String &= @lf & $i & ": " & $PathArr[$i] Next Return $String EndFunc ;==>PathSplit Thanks for your nice code. Regards, Rudi. Actually, I think we may have just uncovered a bug in StringRegExpReplace. I'll pursue it further before reporting it, but on my system, Win 7 Pro with AutoIt 3.3.6.1 when the replacement string contains a single backslash (\) it's being stripped out. So even though the script returns EnvVar("SystemRoot") as C:\Windows, the StringRegExpReplace removes the backslash turning it into C:Windows. Can you confirm the same behaviour? As a work around use this for the processing loop: For $i = 0 To UBound($aEnvVars) - 1 $sEnVar = StringReplace(EnvGet($aEnvVars[$i]), "\", "\\") $PATH = StringRegExpReplace($PATH, "(%\Q" & $aEnvVars[$i] & "\E%)", $sEnVar) Next Link to comment Share on other sites More sharing options...
rudi Posted August 9, 2010 Author Share Posted August 9, 2010 Hi. Sorry for the extreme delay. I lost this thread. [can you confirm, that "C:\Windows" goes "C:Windows" ?] Yes. %windir% goes "C:windows". WinXP-SP3. But isn't that WAD, I mean, isn't it normal to use "\\" for a single "\" in RegEx? This works fine: ... $PATH = StringRegExpReplace($PATH, "(%\Q" & $aEnvVars[$i] & "\E%)", StringReplace(EnvGet($aEnvVars[$i]),"\","\\")) ... Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
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