VB.NET – Copying Windows Cancel Hide Folders and File Features

I visited a tool again, I wrote my service support team in VB.Net and back, I want to add some checkboxes to copy Windows to show hidden files and folders/ Then hide the same functions, as well as the protected operating system files.

I know I can do this by editing the registry key and restarting explorer.exe, but this will close all open Explorer Windows, I don’t want this.

Does anyone know how Windows can do this by simply clicking a checkbox and how I can code it in VB.net?

Any comments on this are greatly appreciated in advance.

Edit: Then it looks like I found that works refreshed in Windows Explorer/File Explorer, which can be applied to the following Drarig The answer, but I cannot convert it to VB.net as the original example is the refresh method in C#.

'Original at https://stackoverflow.com/questions /2488727/refresh-windows-explorer-in-win7

Private 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, Nothing, windows, Nothing)

For i As Integer = 0 To CType(count, Integer)
Dim i tem As Object = windowsType.InvokeMember("Item", Reflection.BindingFlags.InvokeMethod, Nothing, windows, New Object() {i})
Dim itemType As Type = item.GetType()

'Only fresh Windows explorer Windows
Dim itemName As String = CType(itemType.InvokeMember("Name", Reflection.BindingFlags.GetProperty, Nothing, item, Nothing), String)
If itemName = explorerType Then
itemType.InvokeMember("Refresh", Reflection.BindingFlags.InvokeMethod, Nothing, item, Nothing)
End If
Next
End Sub

When When I set itemType to Type = item.GetType() above, I get an exception that the object reference is not set to an instance of the object. I can’t figure out which object is not created. When I step through the code, it looks Like windowsType contains an object. Does anyone have any ideas on this? Once the problem is solved, I can apply it to the Drarig solution below.

Well, I wish I could get you sooner, but I have been busy with work lately. Today I took a little time to figure this out because I like to dig out things I haven’t done before. This is a whole class for a new project; no Time to wrap it in a separate class. I believe this will get what you need. It is more difficult than I thought to get the right handle and then send the command, but I got it. Hope it helps.

Attachment: You can omit some things, especially the boolean value used for loading, so that I can pull back the current value and check/uncheck the CheckBox when loading.

Note: This is tried and tested on Windows 7, 8 and 10

Imports Microsoft.Win32
Imports System.Reflection
Imports System.Runtime .InteropServices

Public Class Form1

_
Public Enum KeyboardFlag As UInteger
KEYBOARDF_5 = &H74
End Enum< br />
_
Private Shared Function GetWindow(ByVal hl As Long, ByVal vm As Long) As IntPtr
End Function

_
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wPara m As IntPtr, ByVal lParam As IntPtr) As Boolean
End Function

_
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, Nothing, objectValue, New Object(0-1) {})
Dim type1 As Type = obj4.GetType
Dim obj2 As Object = type1.InvokeMember("Count", BindingFlags.GetProperty, Nothing, 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", BindingFlags.InvokeMethod, Nothing, obj4, New Object() {i})
Dim type3 As Type = obj5.GetType
Dim str As String = CStr(type3.InvokeMember("Name", BindingFlags.GetProperty, Nothing, obj5, Nothing))
If (str = "File Explorer") Then< br /> type3.InvokeMember("Refresh", BindingFlags.InvokeMethod, Nothing, obj5, 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 hand le and refresh option...
Dim j = GetWindow(hwnd, 3)

'Finally post the message...
PostMessage(j, 256, KeyboardFlag.KEYBOARDF_5, 3)
End Sub


End Class

I visited a tool again, I wrote it in VB.Net My service support team came back and wanted to add some checkboxes to copy Windows to show hidden files and folders/hide the same functions, as well as protected operating system files.

I know I can do this by editing the registry key and restarting explorer.exe, but this will close all open Explorer Windows, I don’t want this.

Does anyone know what Windows is? How can I do this by simply clicking on a checkbox and how can I code it in VB.net?

Any comments on this are greatly appreciated in advance.

Edit: Then it looks like I found that works refreshed in Windows Explorer/File Explorer, which can be applied to the following Drarig The answer, but I cannot convert it to VB.net as the original example is the refresh method in C#.

'Original at https://stackoverflow.com/questions /2488727/refresh-windows-explorer-in-win7

Private 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, Nothing, windows, Nothing)

For i As Integer = 0 To CType(count, Integer)
Dim item As Object = windowsType.InvokeMember("Item", Reflection.BindingFlags.InvokeMethod, Nothing, windows, New Object() {i})
Dim itemType As Type = item.GetType()

'Only fresh Windows explorer Windows
Dim itemName As String = CType(itemType.InvokeMember("Name", Reflection.BindingFlags.GetProperty, Nothing, item, Nothing), String)
If itemName = explorerType Then
itemType.InvokeMember("Refresh", Reflection.BindingFlags.InvokeMethod, Nothing, item, Nothing)
End If
Next
End Sub

When I When setting itemType to Type = item.GetType() above, I get an exception that the object reference is not set to an instance of the object. I can’t figure out which object is not being created. When I step through the code, it looks like windowsType contains an object. Does anyone have any ideas on this? Once the problem is solved, I can apply it to the Drarig solution below.

Well, I hope I can get you sooner, but Busy with work lately. I took a little time to figure this out today because I like to dig out things I haven’t done before. This is a whole class of a new project; there is no time to wrap it in a separate class. I I believe this will get what you need. It is more difficult than I thought to get the correct handle and send the command, but I got it. Hope it helps you.

Attachment: You can Omit some things, especially the boolean value used for loading, so that I can pull back the current value and check/uncheck the CheckBox when loading.

Note: This is on Windows 7, 8 and 10 Trial and tested

Imports Microsoft.Win32
Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class Form1

_
Public Enum KeyboardFlag As UInteger
KEYBOARDF_5 = &H74
End Enum

_
Private Shared Function GetWindow(ByVal hl As Long, ByVal vm As Long) As IntPtr
End Function
< br /> _
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
End Function

_
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"< br /> 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, Nothing, objectValue, New Object( 0-1) {})
Dim type1 As Type = obj4.GetType
Dim obj2 As Object = type1.InvokeMember("Count", BindingFlags.GetProperty, Nothing, 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", BindingFlags.InvokeMethod, Nothing, obj4, New Object() {i})
Dim type3 As Type = obj5.GetType
Dim str As String = CStr(type3. InvokeMember("Name", BindingFlags.GetProperty, Nothing, obj5, Nothing))
If (str = "File Explorer") Then
type3.InvokeMember("Refresh", BindingFlags.InvokeMethod, Nothing, obj5 , 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 Sub


End Class

Leave a Comment

Your email address will not be published.