開發者嘗試在 VB.NET 2015 中透過 EnumWindows 列舉所有 WorkerW 視窗,尋找 SHELLDLL_DefView 並將自訂表單的父視窗設定為該視窗,以達到將視窗嵌入 Windows 7 桌面的效果。然而實測發現使用 Spy++ 檢視時,視窗並未成功嵌入桌面層。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Private Declare Function EnumWindows Lib "user32" Alias "EnumWindows" (ByVal MyCallBack As EnumWindowsProc, ByVal lParam As Integer) As Integer
Private Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
Private Function EnumWindowsProcCallBack(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
If hwnd = FindWindow("WorkerW", vbNullString) Then
If hwnd = FindWindowEx(hwnd, vbNull, "SHELLDLL_DefView", vbNullString) Then
SetParent(Me.Handle, hwnd)
EnumWindowsProcCallBack = False
Else
EnumWindowsProcCallBack = True
End If
Else
EnumWindowsProcCallBack = True
End If
End Function
Dim MyCallBack As EnumWindowsProc
MyCallBack = New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
EnumWindows(MyCallBack, 0)
最佳回答指出:回調函數指標僅在當前進程有效,無法跨進程傳遞給 Explorer.exe 執行。將委派指標傳遞給 EnumWindows 會導致目標進程(Explorer)嘗試執行不屬於其記憶體空間的代碼,造成崩潛或無效果。
WriteProcessMemory 將組合語言/機器碼注入 Explorer 進程,再用 CreateRemoteThread 執行。但 VB.NET 編譯的托管代碼無法直接注入,必須用 C++ 編寫純機器碼。若非底層系統開發需求,建議改用正規 Shell 擴展或桌面小工具架構,避免進程注入帶來的穩定性與安全性風險。