- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道!我不应该从 Windows 服务运行 GUI 应用程序,但这是我应该完成的要求。将来自网络的不同代码放在一起,我有以下过程。由于 CreateProcessAsUser,我在日志中看到访问冲突错误。我尝试过不同的设置但没有运气。知道这段代码有什么问题吗?
procedure TMyService.RunApp;
var
SessionID: DWORD;
UserToken: THandle;
CmdLine: PChar;
si: _STARTUPINFOW;
pi: _PROCESS_INFORMATION;
begin
SessionId:= WtsGetActiveConsoleSessionID;
if SessionID = $FFFFFFFF then Exit;
if WTSQueryUserToken(SessionID, UserToken) then begin
CmdLine:= 'notepad.exe';
ZeroMemory(@si, SizeOf(si));
si.cb := SizeOf(si);
SI.lpDesktop := PChar('winsta0\Default');
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_SHOWNORMAL;
ZeroMemory(@pi, SizeOf(pi));
try
CreateProcessAsUser(UserToken, nil, CmdLine, nil, nil, False,
0, nil, nil, si, pi);
except on E: Exception do
// Log exception ...
end;
CloseHandle(UserToken);
end else begin
// Log GetLastError ...
end;
end;
顺便说一句,WTSQueryUserToken 是从 JEDI API 库使用的,定义为:
function WTSQueryUserToken(SessionId: ULONG; var phToken: THandle): BOOL; stdcall;
最佳答案
第三个参数必须是指向可修改字符串的指针,如 MSDN 上所述:
The Unicode version of this function, CreateProcessAsUserW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.
字符串文字存储在只读存储器中。试试这个:
var
CmdLine: string;
....
CmdLine := 'notepad.exe';
UniqueString(CmdLine); // make modifiable;
....
if not CreateProcessAsUser(..., PChar(CmdLine), ...) then
// handle error
关于delphi - 从服务运行应用程序,CreateProcessAsUser 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989658/
我有一个启动我的应用程序的 Windows 服务。此服务是一个调度程序,用于执行最终用户定义的一些自定义操作。 它作为 LocalSystem 帐户运行,并将启动我的应用程序(有窗口)。 为此,我使用
我正在尝试使用以下代码从另一个用户帐户下的另一个 Windows 应用程序调用执行应用程序: procedure TForm1.Button3Click(Sender: TObject); var
我正在尝试使用我的服务启动 GUI 应用程序。我在 VS2012 上开发了该服务并在 Windows 7 上运行。但是 CreateProcessAsUser 函数即使成功返回也不会启动应用程序。以下
我的服务在本地系统权限下运行,需要在用户 session 中启动具有管理员权限的应用程序。 我得到的是: WTSGetActiveConsoleSessionID() WTSQueryUserToke
我在 MSDN 上读到 UAC 的实现: http://technet.microsoft.com/en-us/magazine/2007.06.uac.aspx 偶然发现这条有趣的线: Althou
我知道!我不应该从 Windows 服务运行 GUI 应用程序,但这是我应该完成的要求。将来自网络的不同代码放在一起,我有以下过程。由于 CreateProcessAsUser,我在日志中看到访问冲突
我需要 ShellExecute作为另一个用户,目前我使用 CreateProcessAsUser 启动一个辅助进程调用 ShellExecute ,但这似乎太过分了(错误的父进程等)。有没有更好的方
我试过混合代码 here和 here从通过 QtService 初始化的服务运行 GUI exe,但每当我运行下面的代码时,我都会从 CreateProcessAsUser 收到错误 5。 另外,我看
我有服务,我需要使用此服务的当前用户权限运行 gui 应用程序。这是我的代码,它总是返回带有 1305 CreateProcessAsUser 函数的 GetLastError。我该如何修复它或者我的
我编写 Windows 服务来启动具有指定路径的应用程序,并发送一个文件名作为其参数。 => 我在 C# 代码上使用 CreateProcessAsUser: 如果文件名来自a,b,c...z字符=>
我有一个在“SYSTEM”帐户下运行的 Windows 服务,它检查每个登录用户是否正在运行特定的应用程序。如果应用程序未运行,服务将启动它(在相应的用户名下)。 我正在尝试使用 CreateProc
我正在尝试使用 CreateProcessAsUser 启动 UI,但该窗口并未作为前台窗口出现。 如果它是一个普通窗口我不介意,但是这个窗口触发了 UAC 提示并且它也没有显示在前台。 最佳答案 根
我正在使用 CreateProcessAsUser 在用户指定的凭据下创建一个进程。 我希望发布的是代码的相关部分。如果您想查看更多内容,请告诉我。 获取 token 的第一个 LogonUser:
我已经阅读了 Stack Overflow 上关于 CreateProcessAsUser 的所有帖子,但很少有已解决的问题,所以我不会在这个问题上屏住呼吸。但似乎我肯定遗漏了一些东西,所以这可能很容
我正在运行一个具有 SYSTEM 权限的程序。我从 LogonUser(szUserName, NULL, szPassword, LOGON32_LOGON_NETWORK, LOGON32_PRO
我有一个系统服务,它使用 CreateProcessAsUser 方法启动应用程序。 此服务使用模拟在事件 session 中启动应用程序。该应用程序正在按预期启动,我设法通过使用使窗口出现在前面:
我的应用程序中有两个进程。1. "myService.exe"这是一个 Windows 服务。2. “myApp.exe”与“myService.exe”位于同一目录。 此进程由“myService.
我在 C# 中使用 CreateProcessAsUser 通过服务启动进程我的服务需要等待进程退出,但我不知道该怎么做,我不想使用检查进程列表中的进程存在 最佳答案 PROCESS_INFORMAT
我们有一个作为 LocalSystem 运行的服务。我们使用 CreateProcessAsUser 和 LoadUserProfile 以特定用户身份启动工作应用程序。效果很好。但是,如果我们尝试使
我有一个在系统帐户中运行的服务,它应该在用户模式下启动一个应用程序。在 C++ 中没问题,但在 .NET 中我遇到了很多问题。 最后,我复制当前用户 session 的用户 token (explor
我是一名优秀的程序员,十分优秀!