本帖最后由 77七 于 2023-4-14 23:36 编辑
- Set objShell = CreateObject("Shell.Application")
- Set objWindows = objShell.Windows
-
- For Each Window in objWindows
- If InStr(1, Window.FullName, "explorer.exe", vbTextCompare) > 0 Then
- Path = Window.Document.Folder.Self.Path
- If Not Path = Replace(WScript.ScriptFullName, WScript.ScriptName, "") Then
- WScript.Echo Path
- End If
- End If
- Next
-
- WScript.Echo "Press any key to continue..."
- WScript.StdIn.Read(1)
复制代码
我问了下ai,写了个类似的,让ai排除脚本所在目录,一直不成功
23:35编辑
我又问了一下ai
获取最后打开的windows资源管理器窗口目录
- Set objShell = CreateObject("Shell.Application")
- Set objWindows = objShell.Windows
-
- strFolder = ""
-
- For i = objWindows.Count - 1 To 0 Step -1
- ' Check if the window belongs to Windows Explorer
- If InStr(1, objWindows.Item(i).FullName, "explorer.exe", vbTextCompare) > 0 Then
- ' Get the location of the last opened window
- strFolder = objWindows.Item(i).Document.Folder.Self.Path
- Exit For
- End If
- Next
-
- ' Output the directory path of the last opened window
- WScript.Echo strFolder
复制代码
|