- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想创建新的窗口站和 Windows 桌面并将我的进程附加到它。我该怎么做
我需要知道
正在创建 Window station 并附加我的桌面
有效地创建和切换桌面
如何将进程附加到 winlogon 桌面(如果可能)
销毁创建的桌面并返回windows桌面
最佳答案
每个“ session ”只有一个交互式窗口站,但您可以有多个 session 。
http://blogs.technet.com/markrussinovich/archive/2010/02/24/3315174.aspx
我不知道直接创建登录 session 的 API,但如果您使用的是 Windows Server 版本,您可以使用远程桌面创建本地 session ,在那里自动运行您的程序,然后在程序结束后再次注销(您在远程桌面 session 中运行的程序完成后可能会注销)。
下面的代码将使用 MSTSC ActiveX 控件以编程方式创建 RDP session 。您将需要手动生成 ActiveX stub 并将它们添加到您的项目中。
在 Visual Studio 命令提示符中键入以下内容:
aximp.exe %windir%\system32\mstscax.dll
将生成的文件(MSTSCLib.dll 和 AxMSTSCLib.dll)复制到项目目录。
将这两个文件添加到项目引用中。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using AxMSTSCLib;using MSTSCLib;using System.Runtime.InteropServices;namespace AutoLogin{ public partial class Form1 : Form { private AxMSTSCLib.AxMsRdpClient5 rdpClient; public Form1() { InitializeComponent(); rdpClient = new AxMSTSCLib.AxMsRdpClient5(); ((ISupportInitialize)rdpClient).BeginInit(); rdpClient.Enabled = true; rdpClient.Location = new System.Drawing.Point(0, 0); rdpClient.Name = "MsRdpClient"; rdpClient.Size = ClientSize; rdpClient.TabIndex = 1; rdpClient.Anchor = (AnchorStyles) (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right); Controls.Add(rdpClient); ((ISupportInitialize)rdpClient).EndInit(); }
void axRemoteDesktop_OnDisconnected
(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
{
Application.Idle += ExitTimerEvent;
}
public void ExitTimerEvent(object source, EventArgs e)
{
Application.Idle -= ExitTimerEvent;
// Attempt to close down the session we just connected to (there
// appears to be no way to get the session id, so we just close all
// disconnected sessions.
if (rdpClient.Connected == 1) {
rdpClient.Disconnect();
}
LogoffDisconnectedSessions();
Close();
}
private Timer logoffTimer;
private void Form1_Load(object sender, EventArgs e)
{
// Close down any existing disconnected sessions, the number of
// available sessions is limited.
LogoffDisconnectedSessions();
String username = "username";
String password = "password";
rdpClient.Server = "localhost";
rdpClient.UserName = username;
rdpClient.AdvancedSettings2.ClearTextPassword = password;
rdpClient.Domain = "";
rdpClient.FullScreen = false;
rdpClient.AdvancedSettings2.RedirectDrives = false;
rdpClient.AdvancedSettings2.RedirectPrinters = false;
rdpClient.AdvancedSettings2.RedirectPorts = false;
rdpClient.AdvancedSettings2.RedirectSmartCards = false;
rdpClient.AdvancedSettings6.RedirectClipboard = false;
rdpClient.AdvancedSettings6.MinutesToIdleTimeout = 1;
rdpClient.OnDisconnected += new
AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler
(axRemoteDesktop_OnDisconnected);
rdpClient.Connect();
logoffTimer = new Timer();
logoffTimer.Tick += new EventHandler(LogoutTimerEvent);
logoffTimer.Interval = 150000;
logoffTimer.Start();
}
private void Form1_Close(object sender, FormClosedEventArgs e)
{
Application.Idle -= ExitTimerEvent;
if (rdpClient.Connected == 1) {
rdpClient.Disconnect();
}
}
public void LogoutTimerEvent(object source, EventArgs e)
{
logoffTimer.Stop();
rdpClient.Disconnect();
}
enum WTS_CONNECTSTATE_CLASS
{
WTSActive,
WTSConnected,
WTSConnectQuery,
WTSShadow,
WTSDisconnected,
WTSIdle,
WTSListen,
WTSReset,
WTSDown,
WTSInit
};
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct WTS_SESSION_INFO
{
public int SessionId;
public string pWinStationName;
public WTS_CONNECTSTATE_CLASS State;
}
[DllImport("wtsapi32.dll")]
private static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);
private static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
[DllImport("wtsapi32.dll", CharSet = CharSet.Auto)]
private static extern bool WTSEnumerateSessions(
IntPtr hServer,
[MarshalAs(UnmanagedType.U4)]
int Reserved,
[MarshalAs(UnmanagedType.U4)]
int Version,
ref IntPtr ppSessionInfo,
[MarshalAs(UnmanagedType.U4)]
ref int pCount);
[DllImport("wtsapi32.dll")]
private static extern void WTSFreeMemory(IntPtr pMemory);
private void LogoffDisconnectedSessions()
{
IntPtr buffer = IntPtr.Zero;
int count = 0;
if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1,
ref buffer, ref count)) {
WTS_SESSION_INFO sessionInfo = new WTS_SESSION_INFO();
for (int index = 0; index < count; index++) {
sessionInfo = (WTS_SESSION_INFO)Marshal.PtrToStructure(
new IntPtr(buffer.ToInt32() +
(Marshal.SizeOf(sessionInfo) * index)),
typeof(WTS_SESSION_INFO));
WTS_CONNECTSTATE_CLASS state = sessionInfo.State;
if (state == WTS_CONNECTSTATE_CLASS.WTSDisconnected)
{
WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE,
sessionInfo.SessionId, true);
}
}
}
WTSFreeMemory(buffer);
}
}
关于c# - 我如何使用 C# 创建窗口站和 Windows 桌面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1344916/
前不久,哔哩哔哩(一般常称为 B 站)发布了一篇文章《2021.07.13 我们是这样崩的》,详细回顾了他们在 2021.07.13 晚上全站崩溃约 3 小时的至暗时刻,以及万分紧张的故障定位与恢复过
想象一下这种情况,周围有一些智能手机和计算机,它们的 WiFi 适配器(无线适配器)打开,但没有必要连接到网络。 有没有办法通过 Linux 机器查看 MAC 地址? 任何见解表示赞赏。 最佳答案 断
我无法创建新的 Window Station 来运行我的应用程序 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { wprintf(L"
在 Conda 环境中安装包后,我想对该包中的代码进行一些更改。 在哪里可以找到包含已安装包的 site-packages 目录? 我有 Anaconda Python 2.7 base 发行版,但找
今天去改了matplotlib的配置。搜索 matplotlibrc 发现我有两个: 查看site-packages 文件夹,我发现很多包的名称中都有波浪号: ~klearn 是 sklearn ,但
我是一名优秀的程序员,十分优秀!