我列举了我系统上的桌面(我正在使用 SysInternals Desktops
,所以我知道我有额外的)使用:
EnumDesktops(Nothing, AddressOf EnumDesktopsProc, Nothing)
使用这些声明:
Private Declare Auto Function EnumDesktops Lib "User32" (ByVal hWinSta As IntPtr, ByVal edp As EnumDesktopProc, ByVal lParam As IntPtr) As Boolean
Private Declare Auto Function OpenDesktop Lib "User32" (<MarshalAs(UnmanagedType.LPTStr)> ByVal DesktopName As String, ByVal dwFlags As Integer, <MarshalAs(UnmanagedType.Bool)>ByVal fInherit As Boolean, ByVal dwDesiredAccess As AccessMask) As DesktopHandle
Private desktopNames As New List(Of String)
Private Delegate Function EnumDesktopProc(<MarshalAs(UnmanagedType.LPTStr)>ByVal DesktopName As String, ByVal lParam As IntPtr) As Boolean
Private Function EnumDesktopsProc(
ByVal DesktopName As String,
ByVal lParam As IntPtr
) As Boolean
desktopNames.Add(DesktopName)
Return True
End Function
我检索到:
"WinSta0"
"Service-0x0-3e7$"
"Service-0x0-3e4$"
"Service-0x0-3e5$"
"SAWinSta"
"__X78B95_89_IW"
"Service-0x0-119d1e$"
"Service-0x0-4e05f$"
当我试图打开它们时:
OpenDesktop(DesktopName, 0, False, AccessMask.DESKTOP_ENUMERATE)
(这里和这里的数据在哪里复制AccessMask
很大,并且是一个)Enum
DesktopHandle
SafeHandle
他们都返回NULL
(Nothing
)并GetLastWin32Error
返回2 "The system cannot find the file specified."
。为什么?
我检查了没有效果的替代声明OpenDesktop
和不同的AccessMask
值(除非声明实际上是错误的)。我注意到在向 中添加“路径”时可能会出现不同的错误DesktopName
,特别是161 "The specified path is invalid."