![]() |
WTSQuerySessionInformationA falscher Parameter
Stehe gerade am Schlauch, mir liefert der Aufruf false zurück und der RaiseLastOsError sagt falscher Paramter.
Delphi-Quellcode:
Ich vermute das ich irgendwo einen Nebeneffekt bekomme, da wenn ich es in einem 0815 testprogramm den selben code starte er durchläufttype TWTSQuerySessionInformationA = function(hServer: THandle; SessionId: DWORD; WTSInfoClass: _WTS_INFO_CLASS; var ppBuffer: Pointer; var pBytesReturned: DWORD): BOOL; stdcall; const WTS_CURRENT_SESSION = DWORD(-1); var ppBuffer: Pointer; pBytesReturned: DWORD begin _TWTSQuerySessionInformationA := GetProcAddress(LoadLibrary(PAnsiChar('wtsapi32.dll')), PAnsiChar('WTSQuerySessionInformationA')); Result := TWTSQuerySessionInformationA(_TWTSQuerySessionInformationA)(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientName, ppBuffer, pBytesReturned); try if not Result then RaiseLastOSError; except end; end; Was könnte mein Programm da "verbrechen" das ich dann so einen Fehler bekomme? - wer ne idee? |
AW: WTSQuerySessionInformationA falscher Parameter
Delphi-Quellcode:
program Project1;
{$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, Winapi.Windows; type _WTS_INFO_CLASS = DWORD; // _WTS_INFO_CLASS <--- muss vier Byte groß sein (also DWORD), kleiner mit Word (SizeOf == 2) oder // Byte (SizeOf == 1) wie die meisten Delphi-Enums geht schief. const WTSInitialProgram: _WTS_INFO_CLASS = 0; WTSApplicationName: _WTS_INFO_CLASS = 1; WTSWorkingDirectory: _WTS_INFO_CLASS = 2; WTSOEMId: _WTS_INFO_CLASS = 3; WTSSessionId: _WTS_INFO_CLASS = 4; WTSUserName: _WTS_INFO_CLASS = 5; WTSWinStationName: _WTS_INFO_CLASS = 6; WTSDomainName: _WTS_INFO_CLASS = 7; WTSConnectState: _WTS_INFO_CLASS = 8; WTSClientBuildNumber: _WTS_INFO_CLASS = 9; WTSClientName: _WTS_INFO_CLASS = 10; type TWTSQuerySessionInformationA = function(hServer: THandle; SessionId: DWORD; WTSInfoClass: _WTS_INFO_CLASS; var ppBuffer: Pointer; var pBytesReturned: DWORD): BOOL; stdcall; const WTS_CURRENT_SESSION = DWORD(-1); WTS_CURRENT_SERVER_HANDLE = 0; function TestWTS: BOOL; var ppBuffer: Pointer; pBytesReturned: DWORD; _TWTSQuerySessionInformationA: TWTSQuerySessionInformationA; begin _TWTSQuerySessionInformationA := GetProcAddress(LoadLibraryA(PAnsiChar('wtsapi32.dll')), PAnsiChar('WTSQuerySessionInformationA')); Result := TWTSQuerySessionInformationA(_TWTSQuerySessionInformationA)(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientName, ppBuffer, pBytesReturned); try if Result then begin Writeln('Call to WTSQuerySessionInformation was successful'); end else RaiseLastOSError; except end; end; begin try TestWTS; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. |
AW: WTSQuerySessionInformationA falscher Parameter
Oh cool danke - darauf bin ich nicht gekommen aber logisch im nachhinein.
Danke noch mal funkt so |
AW: WTSQuerySessionInformationA falscher Parameter
Delphi-Quellcode:
{$MinEnumSize 4}
![]() PS: statt der ANSI-Versionen A vielleicht langsam auch mal auf Unicode W umsteigen?
Delphi-Quellcode:
Der Name in ppBuffer ist dann natürlich Unicode (PWideChar) und nicht mehr ANSI.
TWTSQuerySessionInformationW = function(hServer: THandle; SessionId: DWORD; WTSInfoClass: _WTS_INFO_CLASS; var ppBuffer: Pointer; var pBytesReturned: DWORD): BOOL; stdcall;
_TWTSQuerySessionInformationW := GetProcAddress(LoadLibrary('wtsapi32.dll'), 'WTSQuerySessionInformationW'); Die Funktion gibt es nun schon seit Vista/WindowsServer2008. Da alles vor Windows 10 bereits tot ist, könnte man das auch statisch einbinden, anstatt dynamisch, aber falls man will, dann ginge es auch als Delayed-Loading. ![]() Imports und Hooks kann man sich sparen, weil ist seit Jahren integriert. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:03 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz