unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ScktComp, IniFiles;
type
TLoginSrv =
class(TService)
ServerSocket1: TServerSocket;
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServiceStart(Sender: TService;
var Started: Boolean);
procedure ServiceStop(Sender: TService;
var Stopped: Boolean);
private
{ Private-Deklarationen }
public
AppName:
String;
AppVers:
String;
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
LoginSrv: TLoginSrv;
implementation
{$R *.DFM}
////////////////////////////////////////////////////////////////////////////////
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
LoginSrv.Controller(CtrlCode);
end;
////////////////////////////////////////////////////////////////////////////////
function TLoginSrv.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
////////////////////////////////////////////////////////////////////////////////
function GetComputerName:
String;
var
Buffer:
Array[0..MAX_COMPUTERNAME_LENGTH+1]
of Char;
Size: DWORD;
begin
size:=256;
Windows.GetComputerName(Buffer, Size);
Result:=StrPas(Buffer);
end;
////////////////////////////////////////////////////////////////////////////////
procedure TLoginSrv.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
IniDat: TIniFile;
StrList: TStringList;
ErrCode: Cardinal;
FileName, Username, Password:
String;
begin
FileName := ExtractFilePath(ParamStr(0))+AppName+'
.tmp';
StrList := TStringList.Create;
StrList.Text := Socket.ReceiveText;
StrList.SaveToFile(FileName);
IniDat := TIniFile.Create(FileName);
Username := IniDat.ReadString('
Authentification', '
Username','
');
Password := IniDat.ReadString('
Authentification', '
Password','
');
LogonUser(PChar(Username), PChar(GetComputerName), PChar(Password), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ErrCode);
IniDat.WriteInteger('
Authentification', '
ErrCode', ErrCode);
IniDat.WriteString('
Authentification', '
ErrCodeStr', SysErrorMessage(ErrCode));
IniDat.WriteInteger('
Authentification', '
GetLastError', GetLastError);
IniDat.WriteString('
Authentification', '
GetLastErrorStr', SysErrorMessage(GetLastError));
StrList.Clear;
StrList.LoadFromFile(FileName);
LoginSrv.ServerSocket1.Socket.Connections[0].SendText(StrList.Text);
LoginSrv.ServerSocket1.Socket.Disconnect(0);
IniDat.Free;
StrList.Free;
if FileExists(FileName)
then DeleteFile(FileName);
end;
////////////////////////////////////////////////////////////////////////////////
procedure TLoginSrv.ServiceStart(Sender: TService;
var Started: Boolean);
begin
ServerSocket1.Open;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TLoginSrv.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
ServerSocket1.Close;
end;
////////////////////////////////////////////////////////////////////////////////
end.