我知道大多数程序卸载程序(至少从Windows 7开始)都可以删除程序文件夹,即使它在资源管理器中打开也是如此。卸载资源管理器后,只需刷新并自动转到Program Files文件夹。
如何在编程语言中(特别是在VB.net中)将同样的事情(告诉资源管理器该文件夹需要不使用)?
答案 0 :(得分:1)
行。因此,您希望资源管理器转到当前文件夹的父文件夹。如果当前文件夹是" c:\ windows \ fonts",则要将其更改为" c:\ windows"。
以下代码应该这样做。看一下注释以获得一些代码的解释
Private Sub ChangeExplorerToParentFolderOf(currentFolder As String)
Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows
Dim filename As String
Dim operationCompleted As Boolean = False
currentFolder = "file:///" & currentFolder.Replace("\", "/").ToLower
'Searches all open explorer windows that are pointing to
'the currentFolder parameter and if found, navigates to
'its parent folder.
'
'if successful, sets the operationCompleted cariable to true
For Each ie As SHDocVw.InternetExplorer In shellWindows
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower()
If filename.Contains("explorer") And ie.LocationURL.ToString.ToLower = currentFolder Then
Dim parentFolder As String = currentFolder.Remove(currentFolder.LastIndexOf("/"))
ie.Navigate2(parentFolder)
operationCompleted = True
End If
Next
'If no instance of explorer is pointing to the currentFolder (operationCompleted=false),
'show a messagebox to say so
If operationCompleted = False Then
MessageBox.Show("No instance of Windows Explorer exists that" & vbCrLf & "points to " & currentFolder)
End If
End Sub