【问题标题】:Select a file on an open Windows Explorer在打开的 Windows 资源管理器中选择一个文件
【发布时间】:2014-05-28 01:00:18
【问题描述】:

我有以下代码,它将启动 Windows 资源管理器并选择一个文件并最大化资源管理器。然后它将寻找 Windows 资源管理器并将其最小化。我做了最大化最小化,这样我就不必手动执行此操作(懒惰,我知道)。我在我的代码中设置了此设置,仅在文件夹未打开时触发。如果它是打开的,那么只需运行最小化部分。代码如下:

If Not FolderIsOpen Then
    Dim curProcess As Process = New Process()
    With curProcess
        With .StartInfo
            .FileName = "explorer.exe"
            Dim MinimizeName As String = RegScoringWorkbookName.Replace(".xlsm", ".zip")
            .Arguments = String.Format("/select, ""{0}""", MinimizeName)
            .WindowStyle = ProcessWindowStyle.Maximized
        End With
        .Start()
    End With
    Thread.SpinWait(100000000)
    For Each IWindow As InternetExplorer In SHWindows
        If IWindow.Name = "Windows Explorer" Then
            Dim GetURIPath As New Uri(IWindow.LocationURL)
            If GetURIPath.LocalPath.ToLower.Equals(FolderName) Then
                ShowWindow(CType(IWindow.HWND, IntPtr), SW_SHOWMINIMIZED)
                Exit For
            End If
        End If
    Next IWindow
Else
    For Each IWindow As InternetExplorer In SHWindows
        If IWindow.Name = "Windows Explorer" Then
            Dim GetURIPath As New Uri(IWindow.LocationURL)
            If GetURIPath.LocalPath.ToLower.Equals(FolderName) Then

                'Code here to select the targeted file

                ShowWindow(CType(IWindow.HWND, IntPtr), SW_SHOWMINIMIZED)
                Exit For
            End If
        End If
    Next IWindow
End If

所以,我的问题是,可以告诉资源管理器在已打开的 Windows 资源管理器上选择文件吗?

【问题讨论】:

  • 为什么您需要在用户界面(Windows 资源管理器)中选择一个文件,然后将该用户界面最小化以使用户看不到它?问一个与您实际尝试完成的任务相关的问题可能会更好(除非它只是用 Explorer 最大化和最小化来惹恼用户) - 可能有一种更简洁的方法来完成它。
  • Ken,我希望这样做的原因是我的工具会创建很多文件。该工具将在轮班工人使用的办公桌上使用,我希望用户打开 Windows 资源管理器并选择最重要的文件,这样他们就不必在资源管理器\我的电脑中进行挖掘。我最小化它的原因是因为我希望用户看到该工具已经完成。如果我不最小化,那么他们可能看不到它已经完成。一直没能找到很多替代方案,只好虚心请教 StackOverFlow 的大佬们。

标签: vb.net


【解决方案1】:

你可以把它扔掉。

Dim i = Shell("explorer /select, C:\Folder\File.exe", AppWinStyle.NormalFocus)

【讨论】:

  • 经典!非常简单和智能。
  • 选择后的逗号是什么?
猜你喜欢
  • 2012-05-05
  • 2010-09-24
  • 1970-01-01
  • 2011-05-24
  • 2010-11-07
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 1970-01-01
相关资源
最近更新 更多