{
The reference to the article, thank the authors,
http://www.cnblogs.com/gnielee/archive/2010/04/08/1707169.html
http://www.java123.net/v/324099.html
According to a written by VC, found that there is a problem, after downsizing for c # version,
}
{import API}
The function WTSQueryUserToken (SessionId: dwords. PhToken: PHandle) : Boolean; Stdcall; External 'wtsapi32. DLL';
The function CreateEnvironmentBlock (lpEnvironment: PPVOID; HToken: THandle; BInherit: Boolean) : Boolean; Stdcall; External 'userenv. DLL';
{judge OS}
The function GetWindowsVersion: Double;
Var
Info: TOSVersionInfo;
The begin
FillChar (Info, sizeof (Info), 0).
Info. DwOSVersionInfoSize:=sizeof (OSVERSIONINFO);
GetVersionExW (Info);
Result:=StrToFloat (Info. DwMajorVersion. ToString () + ' '+ Info. DwMinorVersion. The ToString ());
end;
{the subject code}
The function RunAppTest: Boolean;
Var
Si: TStartupInfo;
PI: TProcessInformation;
HThisToken hDuplicatedToken: THandle;
SessionID: DWORD;
TokenInfoClass: TTokenInformationClass;
LpEnvironment: LPVOID;
Sa: TSecurityAttributes;
The begin
ZeroMemory (@ si, SizeOf (si));
ZeroMemory (@ PI, Sizeof (PI));
Si. Cb:=SizeOf (si);
Si. LpDesktop:='Winsta0 \ Default;
SessionID: WTSGetActiveConsoleSessionId=();
B:=WTSQueryUserToken (SessionID, @ hThisToken);
The Log. The Add (' WTSQueryUserToken + B2S (b));
B:=DuplicateTokenEx (hThisToken MAXIMUM_ALLOWED, @ sa, SecurityIdentification TokenPrimary, hDuplicatedToken);
The Log. The Add (' DuplicateTokenEx + B2S (b));
B:=CreateEnvironmentBlock (@ lpEnvironment hDuplicatedToken, False);
The Log. The Add (' CreateEnvironmentBlock + B2S (b));
B:=CreateProcessAsUserW (hDuplicatedToken,
'the calc. Exe,
Nil,
@ sa,
Nil,
False,
NORMAL_PRIORITY_CLASS or CREATE_NEW_CONSOLE or CREATE_UNICODE_ENVIRONMENT,
LpEnvironment,
'c: \ Windows \ system32',
Si,
PI);
The Log. The Add (' CreateProcessAsUserW + B2S (b));
{the CloseHandle code slightly}
end;
Supplementary information:
Online search system version number 1
{
Win95 win98 win_me win_Nt_3_5 win2000 5.0 3.51 4.90 4.10 4.0 5.1 win_xp win2003 vista, Windows 7 6.1 6.0 5.2 6.2 doing
}
2 in the service thread switching
If GetWindowsVersion<6.0 then
WinExec (' c: \ Windows \ system32 \ notepad exe ', SW_SHOWNORMAL)
The else
RunAppTest;
3 the Service Interactive attribute set to true (win2003 need)
Last night the ready-made code not found on the Internet, so we have to spend a little bit of time to code into D, hope to help people in need to save time,
CodePudding user response:
Under the Windows 7 operating system, not in the way you test successCodePudding user response:
Under the Windows 7 operating system is invalid,CodePudding user response:
Please amend winexec as ShellExecute (reference ShellAPI units), plus the service Interactive attribute set to true, basically have no questions, and you can give your service program can add tray icon, if Interactive not to true is not tray icon,