我是新来的,如果我发帖有误,请告诉我。
我正在尝试启动具有 GUI 的 exe,而无需登录到 Windows 7。我尝试过:Windows 任务计划程序、NSSM、SC 命令、启动文件夹中的批处理文件、启动文件夹中的可执行文件,
此外,SC 命令已尝试使用许多不同的参数和选项。通过提供本地用户名和密码,我尝试了 NSSM、Windows 任务计划程序和 SC 命令,可以选择使用特定帐户(不确定详细信息)。所有这些都已尝试使用批处理文件和可执行文件。批处理文件的唯一目的是启动可执行文件。我认为这种间接方法可能会在一定程度上有所帮助,但是在登录之前尝试启动程序没有区别。
关键是 GUI,因为例如,我能够使用 Windows 任务调度程序、NSSM 和 SC 命令启动一个批处理文件,该批处理文件在登录之前创建了一个空白文本文件(按时间验证)。
但是,如果我尝试启动,比如 notepad.exe(启动 notepad.exe),它将无法正常工作。记事本不会作为任务出现,不会有窗口,也不会作为进程出现。我曾尝试将 txt 文件创建命令放在批处理文件中的启动命令之后,并创建文件(因此批处理文件不会在开始时挂起),但记事本没有任何痕迹。我的一些同行还建议这是 GUI 的结果,以及它必须如何进行桌面会话。
有什么工作: 1. 允许在启动时登录而无需密码。2. 执行批处理文件,启动程序,然后锁定计算机。3. 桌面只会闪烁约 1 秒。
问题:这还不够好,因为它是一个漏洞,即使它只是瞬间。
找到了一个和我有类似问题的人,并将其作为他的解决方案,但他承认,这不是一种安全的方法。 https://serverfault.com/questions/583517/start-program-on-computer-startup-when-nobody-is-logged-on-and-show-the-window-w
还有另一种我不太了解的途径,我认为可能可行。它与功能LogonUser()、ImpersonateLoggedOnUser()、CreateProcessAsUser()、CreateProcessWithLogonW()相关。我希望将它作为能够“登录”并启动程序的服务运行。
创建会话的代码:
bool startProcess(string path) {
_STARTUPINFOA info;
info.cb = sizeof(info);
info.lpReserved = NULL;
//The name of the desktop to which we want to connect.
info.lpDesktop = NULL;
//The title assigned to the GUI window.
info.lpTitle = NULL;
//Offset of the window from top left corner
info.dwX = 0;
info.dwY = 0;
//Size of the GUI window that is created.
info.dwXSize = 1000;
info.dwYSize = 900;
//Specifies the nunmber of columns of a console (if applicable) of characters.
info.dwXCountChars = 30;
//Specifris the number of rows of characters of a console window
info.dwYCountChars = 0;
//Specifies the color when opening the new GUI
info.dwFillAttribute = 0;
//Specifies different visual attributes, such as for the cursor.
info.dwFlags = 0;
//This must be zero.
info.cbReserved2 = 0;
//This must be NULL.
info.lpReserved2 = NULL;
info.dwFlags = 0;
//This is NULL because of the value of dwFlags.
info.hStdInput = NULL;
//This is ignored because of dwFlahs.
info.wShowWindow = 0;
//This is NULL because of the dwFlags.
info.hStdOutput = NULL;
//This is NULL because of the value of dwFlags.
info.hStdError = NULL;
PROCESS_INFORMATION ThreadInfo;
bool success = CreateProcessAsUserA(theHandle, path.c_str(), NULL, NULL, NULL, false, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &info, &ThreadInfo);
//lpStartupInfo might be useful in the situation that a display window is not being shown.
threadHandle = ThreadInfo.hThread;
if (!success) {
return false;
}
else {
return true;
}
}
我认为不那么重要的东西,在大多数情况下都没有遇到,但在我四处乱窜时会出现:
遇到的错误:错误1053:服务没有及时响应开始控制请求
尝试:清理注册表下载框架 NET 4.5。