我知道我可以通过编辑注册表项并重新启动explorer.exe来完成此 *** 作,但这会关闭所有打开的资源管理器windows,我不希望这样.
有没有人知道windows是如何通过简单点击一个复选框以及我如何能够在VB.net中编码它来做到这一点的?
对此的任何意见都提前非常感谢.
编辑:那么它看起来像我发现作品刷新windows资源管理器/文件浏览器,可应用于以下Drarig的答案,但我无法将其转换为VB.net作为原始的例子是在C#中的刷新方法.
'Original at https://stackoverflow.com/questions/2488727/refresh-windows-explorer-in-win7Private Sub refreshExplorer(ByVal explorerType As String) Dim CLSID_ShellApplication As GuID = GuID.Parse("13709620-C279-11CE-A49E-444553540000") Dim shellApplicationType As Type = Type.GetTypeFromCLSID(CLSID_ShellApplication,True) Dim shellApplication As Object = Activator.CreateInstance(shellApplicationType) Dim windows As Object = shellApplicationType.InvokeMember("windows",Reflection.BindingFlags.InvokeMethod,nothing,shellApplication,New Object() {}) Dim windowsType As Type = windows.GetType() Dim count As Object = windowsType.InvokeMember("Count",Reflection.BindingFlags.GetProperty,windows,nothing) For i As Integer = 0 To CType(count,Integer) Dim item As Object = windowsType.InvokeMember("Item",New Object() {i}) Dim itemType As Type = item.GetType() 'Only fresh windows explorer windows Dim itemname As String = CType(itemType.InvokeMember("name",item,nothing),String) If itemname = explorerType Then itemType.InvokeMember("Refresh",nothing) End If NextEnd Sub
当我将itemType设置为上面的Type = item.GetType()时,我得到一个异常对象引用未设置为对象的实例.我无法弄清楚哪个对象没有被创建.当我单步执行代码时,它看起来像windowsType包含一个对象.有没有人对此有任何想法?一旦解决了这个问题,我就可以将它应用到下面的Drarig解决方案中.
解决方法 好吧,我希望我能早点得到你,但最近忙于工作.今天我花了一点时间来弄清楚这一点,因为我喜欢挖掘我之前没有做过的事情.这是一个新项目的全班;没有时间把它包装在一个单独的课堂上.我相信这会得到你所需要的.它比我想象的更难获得正确的句柄然后发送命令,但我得到了它.希望对你有帮助.附:你可以省略一些东西,特别是用于加载的布尔值,这样我就可以在加载时拉回当前值并检查/取消选中CheckBox.
注意:这是在windows 7,8和10上试用和测试的
imports Microsoft.Win32imports System.Reflectionimports System.Runtime.InteropServicesPublic Class Form1 <Flags()> _ Public Enum KeyboardFlag As UInteger KEYBOARDF_5 = &H74 End Enum <Dllimport("user32.dll",SetLastError:=True,CharSet:=CharSet.auto)> _ Private Shared Function Getwindow(ByVal hl As Long,ByVal vm As Long) As IntPtr End Function <Dllimport("user32.dll",CharSet:=CharSet.auto)> _ Private Shared Function PostMessage(ByVal hWnd As IntPtr,ByVal Msg As UInteger,ByVal wParam As IntPtr,ByVal lParam As IntPtr) As Boolean End Function <Dllimport("user32.dll",CharSet:=CharSet.auto)> _ Private Shared Function FinDWindow(ByVal lpClassname As String,ByVal lpWindowname As String) As IntPtr End Function Private blnLoading As Boolean = False Private Sub CheckBox1_CheckedChanged(sender As Object,e As EventArgs) Handles CheckBox1.CheckedChanged Form1.HIDefilesExtension(Me.CheckBox1.Checked) If Not blnLoading Then NotifyfileAssociationChanged() RefreshExplorer() End Sub Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load Dim name As String = "Software\Microsoft\windows\CurrentVersion\Explorer\Advanced" Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey(name,False) blnLoading = True Me.CheckBox1.Checked = CBool(key.GetValue("HIDden")) key.Close() blnLoading = False End Sub Private Shared Sub HIDefilesExtension(ByVal HIDe As Boolean) Dim name As String = "Software\Microsoft\windows\CurrentVersion\Explorer\Advanced" Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey(name,True) key.SetValue("HIDden",If(HIDe,1,0)) key.Close() End Sub Public Shared Sub RefreshExplorer() Dim clsID As New GuID("13709620-C279-11CE-A49E-444553540000") Dim typeFromCLSID As Type = Type.GetTypeFromCLSID(clsID,True) Dim objectValue As Object = Activator.CreateInstance(typeFromCLSID) Dim obj4 As Object = typeFromCLSID.InvokeMember("windows",BindingFlags.InvokeMethod,objectValue,New Object(0 - 1) {}) Dim type1 As Type = obj4.GetType Dim obj2 As Object = type1.InvokeMember("Count",BindingFlags.GetProperty,obj4,nothing) If (CInt(obj2) <> 0) Then Dim num2 As Integer = (CInt(obj2) - 1) Dim i As Integer = 0 do while (i <= num2) Dim obj5 As Object = type1.InvokeMember("Item",New Object() {i}) Dim type3 As Type = obj5.GetType Dim str As String = CStr(type3.InvokeMember("name",obj5,nothing)) If (str = "file Explorer") Then type3.InvokeMember("Refresh",nothing) End If i += 1 Loop End If End Sub Public Shared Sub NotifyfileAssociationChanged() 'Find the actual window... Dim hwnd As IntPtr = FinDWindow("Progman","Program Manager") 'Get the window handle and refresh option... Dim j = Getwindow(hwnd,3) 'Finally post the message... PostMessage(j,256,KeyboardFlag.KEYBOARDF_5,3) End SubEnd Class总结
以上是内存溢出为你收集整理的vb.net – 复制Windows取消隐藏文件夹和文件功能全部内容,希望文章能够帮你解决vb.net – 复制Windows取消隐藏文件夹和文件功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)