Registriert seit: 26. Mai 2006
Ort: Arnsberg
588 Beiträge
Delphi 11 Alexandria
|
Frage zu JWSCL / JEDI´s
10. Jul 2008, 16:03
Hallo,
ich habe in meinen Systemdienst JWSCL/ JEDI-Komponenten verwendet. Jetzt erhalte ich beim Systemstart die Fehlermeldung : der prozedureinsprung "wtscgetactiveconsolesessionid" wurde in der dll "kernel32.dll" nicht gefunden
Das OS ist Win2000, hier mein verwendeter Code:
Delphi-Quellcode:
type TWinVersion = (wvUnknown, wvWin95, wvWin98, wvWin98SE, wvWinNT, wvWinME, wvWin2000, wvWinXP, wvWinVista) ;
function GetWinVersion: TWinVersion;
var
osVerInfo: TOSVersionInfo;
majorVersion, minorVersion: Integer;
begin
Result := wvUnknown;
osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo) ;
if GetVersionEx(osVerInfo) then
begin
minorVersion := osVerInfo.dwMinorVersion;
majorVersion := osVerInfo.dwMajorVersion;
case osVerInfo.dwPlatformId of
VER_PLATFORM_WIN32_NT:
begin
if majorVersion <= 4 then
Result := wvWinNT
else if (majorVersion = 5) and (minorVersion = 0) then
Result := wvWin2000
else if (majorVersion = 5) and (minorVersion = 1) then
Result := wvWinXP
else if (majorVersion = 6) then
Result := wvWinVista;
end;
VER_PLATFORM_WIN32_WINDOWS:
begin
if (majorVersion = 4) and (minorVersion = 0) then
Result := wvWin95
else if (majorVersion = 4) and (minorVersion = 10) then
begin
if osVerInfo.szCSDVersion[1] = 'A' then
Result := wvWin98SE
else
Result := wvWin98;
end
else if (majorVersion = 4) and (minorVersion = 90) then
Result := wvWinME
else
Result := wvUnknown;
end;
end;
end;
end;
procedure StartApp(const App, Parameters, CurDir : TJwString);
var
StartupInfo : TStartupInfoA;
ProcInfo : TProcessInformation;
pEnv : Pointer;
pCurDir,
pCmdLine : TJwPChar;
ServiceToken, CopiedToken, UserToken : TJwSecurityToken;
PW :string;
begin
ZeroMemory(@StartupInfo, sizeof(StartupInfo));
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.lpDesktop := 'winsta0\default';
pCmdLine := TJwPChar('"'+App+'" ' + Parameters);
pCurDir := Nil;
if Length(CurDir) > 0 then
pCurDir := TJwPChar(CurDir);
//get the token from the service system session
ServiceToken := TJwSecurityToken.CreateTokenEffective(MAXIMUM_ALLOWED);
TJwAutoPointer.Wrap(ServiceToken);
//copy the token to be able to change the TokenSessionId
//Info: Win2000: Only 0
// WinXP: Service=0, 1.User=0, 2.User=1, 3.User=2, ...
// WinVista: Service=0, 1.User=1, 2.User=2, 3.User=3, ...
CopiedToken := TJwSecurityToken.CreateDuplicateExistingToken(ServiceToken.TokenHandle, MAXIMUM_ALLOWED);
TJwAutoPointer.Wrap(CopiedToken);
//get the token of the logged in user
if GetWinVersion = wvWin2000 then
UserToken := TJwSecurityToken.CreateCompatibilityQueryUserToken(MAXIMUM_ALLOWED, 'explorer.exe')
else //XP, 2003, Vista, 2008
UserToken := TJwSecurityToken.CreateWTSQueryUserTokenEx(nil, WtsGetActiveConsoleSessionID);
TJwAutoPointer.Wrap(UserToken);
//give the copied token the same sessionid as the logged in user
CopiedToken.TokenSessionId := UserToken.TokenSessionId;
//create the environment block using the logged in user
JwaWindows.CreateEnvironmentBlock(@pEnv, UserToken.TokenHandle, false);
try
if not CreateProcessAsUser(
CopiedToken.TokenHandle,
TJwPChar(App), //__in_opt LPCTSTR lpApplicationName,
pCmdLine, //__inout_opt LPTSTR lpCommandLine,
nil, //__in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
nil, //__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
false, //__in BOOL bInheritHandles,
CREATE_NEW_CONSOLE or CREATE_DEFAULT_ERROR_MODE or CREATE_UNICODE_ENVIRONMENT,
//__in DWORD dwCreationFlags,
pEnv, //__in_opt LPVOID lpEnvironment,
pCurDir, //__in_opt LPCTSTR lpCurrentDirectory,
StartupInfo, //__in LPSTARTUPINFO lpStartupInfo,
ProcInfo //__out LPPROCESS_INFORMATION lpProcessInformation
) then
raiseLastOsError;
finally
DestroyEnvironmentBlock(pEnv);
end;
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
...
ReadDir(PW3);
PW1 := 'Programm.exe';
PW2 := '';
if not IsExeRunning(PW1) then
StartApp(PW1, PW2, PW3);
...
Die StartApp-Routine habe ich hier im Forum gefunden, die GetWinVersion habe ich getestet und funktioniert. Ist meine Datei "kernel32.dll" nicht i.O. oder liegt es an StartApp ?
KUBA
Stefan Kubatzki E=mc2
|