지정한 터미널 세션에서 프로그램을 시작하는 방법
2125 단어 delphi 기초 관련OS
uses JwaWinbase, JwaWtsApi32;
var hToken: THandle;
si: _STARTUPINFOA;
pi: _PROCESS_INFORMATION;
var Ret: Cardinal;
sTitle: string;
sMsg: string;
begin
ZeroMemory(@si, SizeOf(si));
si.cb := SizeOf(si);
si.lpDesktop := nil;
if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken) then
begin
if CreateProcessAsUser(hToken, nil, 'notepad.exe', nil, nil, False,
0, nil, nil, si, pi) then
begin
// Do some stuff
end;
end;
end;
I specified WtsGetActiveConsoleSessionID as the SessionID, this function retrieves the Terminal Services session currently attached to the physical console. The physical console is the monitor, keyboard, and mouse. Note that it is not necessary that Terminal Services be running for this function to succeed. In Windows 2000 the console is always session 0 but for Windows XP/2003/Vista this can be any number. So if you want to launch a process in session 5 the code is:
if WTSQueryUserToken(5, hToken) then
begin
if CreateProcessAsUser(hToken, nil, 'notepad.exe', nil, nil, False,
0, nil, nil, si, pi) then
begin
// Do some stuff
end;
end;
WtsQueryUserToken is defined in the unit JwaWtsApi32 and WtsGetActiveConsoleSessionID is defined in the unit JwaWinBase. Both units are part of theJedi APILibrary.
This will launch notepad in the console session but offcourse you can replace the function WtsGetActiveConsoleSessionId with a specific SessionID. Just remember that only the system account is allowed to use WtsQueryUserToken. So you will need to launch this code from a service.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Application Development in WebOSDevelop applications in WebOS Recognize the abstract class Application The operating system accepts classes that impleme...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.