【问题标题】:Object Shell.Application Open Folder In Same Explorer Window对象 Shell.Application 在同一资源管理器窗口中打开文件夹
【发布时间】:2020-10-18 19:27:40
【问题描述】:

我想问你一个关于 Shell.Application COM 对象的问题。我使用的编程语言是 AutoIT。我想知道,如何在与之前打开的文件夹完全相同的窗口中打开文件夹。

例如,如果我在窗口中打开 C:\Folder 并且它有一个子文件夹,那么如何让脚本在已打开“父文件夹”的同一窗口中打开该子文件夹,而不创建新的窗口。我可以打开文件夹的唯一方法是这样的:

global $ShellApplication = ObjCreate("Shell.Application")
$ShellApplication.Explore("C:\Folder")
Sleep(100)
$ShellApplication.Explore("C:\Folder\Subfolder")

但是这种方式是错误的方式。我希望有人知道如何实现这一点。

【问题讨论】:

    标签: autoit explorer


    【解决方案1】:

    我不知道这是否是你想要的,但你可以像这样自动化当前窗口:

    #include <Array.au3>
    Opt("SendKeyDelay", 1) ;5 milliseconds
    Opt("SendKeyDownDelay", 1) ;1 millisecond
    
    $pid = ShellExecute("explorer.exe ", @DesktopDir)
    Sleep(300)
    ;~ $aWinList=WinList("[REGEXPCLASS:(Explore|Cabinet)WClass]")
    ;~ _ArrayDisplay($aWinList)
    ConsoleWrite($pid & @CRLF)
    $handle = _WinGetHandleByPID($pid)
    Sleep(2000)
    SendKeepActive($handle)
    Send('{F4}')
    Send('^a')
    Send(@AppDataCommonDir & "{ENTER}")
    
    
    Func _WinGetHandleByPID($vProcess, $nShow = 1)
        ; Get Window Handle by PID
        ; Author Hubertus
        ; derived from Smoke_N's script with the same name,
        ; but to handle more than one process with the same name
        ; and to return handle of newest window ($nShow = 2).
        ;
        ; $vProcess = Processname(e.g. "Notepad.exe") or Processnumber(e.g. 4711 )
        ; $nShow = -1 "All (Visble or not)", $nShow = 0 "Not Visible Only", $nShow = 1 "Visible Only", $nShow = 2 "return handle of newest  window "
        ; @error = 0   Returns array of matches. Array[0][0] and @extended shows number of matches.
        ; @error = 0 and $nShow = 2   return handle of newest window
        ; Array[n][0] shows windows title. Array[n][1] shows windows handle. n = 1 to @extended
        ; @error = 1   Process not found.
        ; @error = 2   Window not found.
        If Not ProcessExists($vProcess) Then Return SetError(1, 0, 0) ; no matching process
        Local $iWinList, $aWinList = WinList()
        Local $iResult, $aResult[UBound($aWinList)][2]
        Local $iProcessList, $aProcessList = ProcessList($vProcess)
        If $aProcessList[0][0] = 0 Then Local $aProcessList[2][2] = [[1, 0], ["", $vProcess]]
        For $iWinList = 1 To $aWinList[0][0]
            For $iProcessList = 1 To $aProcessList[0][0]
                If WinGetProcess($aWinList[$iWinList][1]) = $aProcessList[$iProcessList][1] Then
                    If $nShow > -1 And Not $nShow = (2 = BitAND(WinGetState($aWinList[$iWinList][1]), 2)) Then ContinueLoop
                    $iResult += 1
                    $aResult[$iResult][0] = $aWinList[$iWinList][0]
                    $aResult[$iResult][1] = $aWinList[$iWinList][1]
                EndIf
            Next
        Next
        If $iResult = 0 Then Return SetError(2, 0, 0) ; no window found
        ReDim $aResult[$iResult + 1][2]
        $aResult[0][0] = $iResult
        If $nShow = 2 Then Return SetError(0, $iResult, $aResult[1][1])
        Return SetError(0, $iResult, $aResult)
    EndFunc   ;==>_WinGetHandleByPID
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多