EnvVar path

English support forum

Moderators: petermad, Stefan2, Hacker

Post Reply
Hurdet
Power Member
Power Member
Posts: 787
Joined: 2003-05-10, 18:02 UTC

EnvVar path

Post by *Hurdet »

Do it possible make a button to copy path as EnvVar?
f.e.
%ProgramFiles%\7-Zip\7z.exe
instead of
c:\Program Files\7-Zip\7z.exe.
or
%WinDir%\system32\SearchIndexer.exe
instead of
c:\WINDOWS\system32\SearchIndexer.exe
User avatar
nsp
Power Member
Power Member
Posts: 2077
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: EnvVar path

Post by *nsp »

You have to create a script/pgm for it it.
See a sample in C#, you can adapt it to other language. Even you can add this as a field in WinScriptAdv. Reuse it for a custom view or direct call.
Fla$her
Power Member
Power Member
Posts: 4033
Joined: 2020-01-18, 04:03 UTC

Re: EnvVar path

Post by *Fla$her »

2Hurdet
My old script:

Code: Select all

'——————————————————————————————— VBS ———————————————————————————————
' Copy the full names of selected objects with environment variables
' Parameters: %Z%WL [/dq]
'       Note: /dq adds double quotes if there are spaces in the path
'———————————————————————————————— Author: Flasher (22.01.2018) © ———
Option Explicit
Dim List, oDic, F, i, Keys, QM, oList, K, All
If WSH.Arguments.Count Then List = WSH.Arguments(0) Else WSH.Quit
If WSH.Arguments.Named.Exists("dq") Then QM = """"
Set oDic = CreateObject("Scripting.Dictionary")
oDic.CompareMode = 1
With CreateObject("WScript.Shell").Environment("Process")
   For Each F in Split("COMMANDER_INI COMMANDER_PATH COMMONPROGRAMW6432 " &_
   "COMMONPROGRAMFILES(x86) COMMONPROGRAMFILES PUBLIC PROGRAMFILES(x86) " &_
   "PROGRAMW6432 PROGRAMFILES WINDIR TMP TEMP LOCALAPPDATA APPDATA " &_
   " USERPROFILE ALLUSERSPROFILE COMMANDER_DRIVE SYSTEMDRIVE HOMEDRIVE")
      i = .Item(F)
      If i <> "" Then If Not oDic.Exists(i) Then oDic.Add i, F
  Next
End With
Keys = oDic.Keys
Set oList = CreateObject("Scripting.FileSystemObject").OpenTextFile(List,,,-1)
Do
   F = oList.ReadLine
   For i = 0 To oDic.Count - 1
      K = Keys(i)
      If InStr(1, F, K, 1) Then
         If InStr(F, " ") + InStr(F, vbTab) Then F = QM & F & QM
         F = Replace(F, K, "%" & oDic(K) & "%", 1, -1, 1)
         Exit For
      End If
   Next
   All = All & vbCrLf & F
Loop Until oList.AtEndOfStream
oList.Close
With CreateObject("SAPI.SpFileStream")
   .Format.Type = 1
   .Open List, 3
   .Write Mid(All, 3)
   .Close
End With
CreateObject("WScript.Shell").Run "%ComSpec% /q/c clip<" & List, 0
oDic.RemoveAll
Set oDic  = Nothing
Set oList = Nothing
Drag .vbs to the button bar from the TC script subfolder and specify the required parameters.
Overquoting is evil! 👎
Post Reply