public static string[] GetDesktopNames(string winStationName) { IntPtr stationHandle = OpenWindowStation(winStationName, true, WinStationAccess.WINSTA_ENUMDESKTOPS | WinStationAccess.WINSTA_ENUMERATE); if (stationHandle == IntPtr.Zero) { throw new Win32ErrorCodeException("OpenWindowStation('" + winStationName + "')"); } try { IList <string> list = new List <string>(); EnumDesktopsDelegate callback = new EnumDesktopsDelegate((string desktopName, IntPtr lParam) => { list.Add(desktopName); return(true); }); if (!EnumDesktops(stationHandle, callback, IntPtr.Zero)) { throw new Win32ErrorCodeException("EnumDesktops('" + winStationName + "')"); } return(list.ToArray()); } finally { CloseWindowStation(stationHandle); } }
public static string[] EnumerateDesktops(string winStationName) { var winStation = OpenWindowStation(winStationName, true, 0x00020000); if (winStation == IntPtr.Zero) { throw new Exception("Winstation could not be opened : " + Marshal.GetLastWin32Error()); } var tArrayList = new ArrayList(); var desktopDelegate = new EnumDesktopsDelegate(HandleDesktopEntry); EnumDesktops(winStation, desktopDelegate, IntPtr.Zero); var desktops = new string[tArrayList.Count]; tArrayList.CopyTo(desktops); tArrayList.Clear(); CloseWindowStation(winStation); return(desktops); }
public static extern bool EnumDesktops(IntPtr hwinsta, EnumDesktopsDelegate lpEnumFunc, IntPtr lParam);
public static extern bool EnumDesktops( IntPtr winStation, EnumDesktopsDelegate EnumFunc, IntPtr lParam );
internal static extern bool EnumDesktops(IntPtr hWinSta, EnumDesktopsDelegate lpEnumFunc, IntPtr lParam);