Visual Studio环境变量脚本

时间:2017-06-30 15:49:31

标签: visual-studio autohotkey explorer

我想测试和反馈(我希望这是这个mod的正确位置,请视情况移动/删除)

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

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

不幸的是,这意味着你失去了所有打开的窗户。

我写了一个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

我们非常感谢您提出的任何建议或改进。 希望它对其他人有用。

1 个答案:

答案 0 :(得分:1)

另一种方法:

; 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% 
}