Visual Studio 环境变量脚本

Visual Studio environment variables script

我想要测试和反馈(我希望这是这个模组的正确位置,请 move/delete 视情况而定)

任何经常更改环境变量的人都知道 Visual studio 不会自动选择它们。

我发现退出并重新启动 explorer.exe 的所有实例会 Visual Studio 在不重新启动的情况下获取最新的环境变量集。

不幸的是,这意味着您将失去所有打开的 windows。

我已经编写了一个 AutoHotKey (www.AutoHotKey.com) 脚本来解决这个问题。

; Array must be initialised
Full_Path := Object()

; First Array dimension must be setup
Full_Path[j] := A_LoopField

; Generate a list of HWND's for explorer windows
WinGet, id, list, ahk_class CabinetWClass

; iterate over all HWND's filling in our Full_Path array
Loop, %id%
{
    ; store hwnd in this_id for current loop
    this_id := id%A_Index%

    ; Get the window information for this_id
    WinGetText, pathToStore, ahk_id %this_id%

    ; strips the address out of the text storing in ActiveAddress
    StringSplit, ActiveAddress, pathToStore, `n

    ; Turn's Path Into Variable
    pathToStore = %ActiveAddress1%

    ; Remove's The Beginning "Address:" Phrase
    pathToStore := RegExReplace(pathToStore, "^Address: ", "")

    ; Remove's Carriage Returns Incase it Exist in pathToStore
    StringReplace, pathToStore, pathToStore, `r, , all

    ; Store the result in the Full_Path array
    ifExist, %pathToStore%
        Full_Path%A_Index% := pathToStore
}

; We can now kill all instances of explorer.exe at command prompt
Loop, %id%
{
    ; Store hwnd in id array
    this_id := id%A_Index%

    ; get process id to kill from stored hwnd
    WinGet, pidVal, PID, ahk_id %this_id%

    ; kill the explorer process
    Run, taskkill /f /pid %pidVal%
}
; kill explorer shell
RunWait, taskkill /f /im explorer.exe

; restart explorer shell
Run, explorer

; open all windows we had open previously
Loop, %id%
{
    ; store actual path to open in local variable path To Open
    pathToOpen := Full_Path%A_Index%

    ; Run explorer providing the correct path to open
    Run, explorer %pathToOpen%
}
Return

如果您能提出任何建议或改进,我们将不胜感激。 希望它对其他人有用。

另一种方法:

; Get fullpath of all opened explorer windows:
If WinExist("ahk_class CabinetWClass") ; explorer
{
    list := ""
    ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
    for window in ComObjCreate("Shell.Application").Windows
    {
       explorer_path := ""
       try explorer_path := window.Document.Folder.Self.Path 
       list .= explorer_path ? explorer_path "`n" : "" 
    }
    list := trim(list, "`n")
    ; MsgBox, "%list%"
}

; We can now restart the Explorer.exe Process:
RunWait, %comspec% /c taskkill /f /im explorer.exe ,,hide
Process, WaitClose, explorer.exe
Run, explorer.exe

; open all explorer windows we had open previously:
If (list != "")
{
    Process, wait, explorer.exe
    Loop, parse, list, `n
        Run %A_LoopField% 
}