unit UStarter;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, abccompf, abctray,StrUtils,ShellAPI, abcutil,Registry,ClipBrd;
type
TFTStarterOfAnbarApp = class(TForm)
Tray: TabcTrayIcon;
Runner: TabcLauncher;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Authenticate;
function EnPassword(a:string):string;
end;
const
LOGON_WITH_PROFILE = 1;
LOGON_NETCREDENTIALS_ONLY = 2;
var
FTNNonameOfGama: TFTStarterOfAnbarApp;CurrentDir:string;
implementation
uses Utils;
{$R *.dfm}
function CreateProcessWithLogonW(
lpUsername,
lpDomain,
lpPassword:PWideChar;
dwLogonFlags:dword;
lpApplicationName: PWideChar;
lpCommandLine: PWideChar;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PWideChar;
const lpStartupInfo: tSTARTUPINFO;
var lpProcessInformation: TProcessInformation
): BOOL; stdcall; external ‹advapi32.dll’;
procedure RunAsUser(const Domain, Username, Password, Command:
string);
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
wDomain, wUsername, wPassword, wCommand: PWideChar;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOWNORMAL;
GetMem(
wDomain,
Length(Domain) * SizeOf(WideChar) + SizeOf(WideChar));
GetMem(
wUsername,
Length(Username) * SizeOf(WideChar) + SizeOf(WideChar));
GetMem(
wPassword,
Length(Password) * SizeOf(WideChar) + SizeOf(WideChar));
GetMem(
wCommand,
Length(Command) * SizeOf(WideChar) + SizeOf(WideChar));
StringToWideChar(
Domain,
wDomain,
Length(Domain) * SizeOf(WideChar) + SizeOf(WideChar));
StringToWideChar(
Username,
wUsername,
Length(Username) * SizeOf(WideChar) + SizeOf(WideChar));
StringToWideChar(
Password,
wPassword,
Length(Password) * SizeOf(WideChar) + SizeOf(WideChar));
StringToWideChar(
Command,
wCommand,
Length(Command) * SizeOf(WideChar) + SizeOf(WideChar));
if not CreateProcessWithLogonW(
wUsername,
wDomain,
wPassword,
2,
nil,
wCommand,
0,
nil,
nil,
StartupInfo,
ProcessInfo) then
if not CreateProcessWithLogonW(
wUsername,
wDomain,
wPassword,
1,
nil,
wCommand,
0,
nil,
nil,
StartupInfo,
ProcessInfo) then
if not CreateProcessWithLogonW(
wUsername,
wDomain,
wPassword,
0,
nil,
wCommand,
0,
nil,
nil,
StartupInfo,
ProcessInfo) then
RaiseLastOSError;
FreeMem(wDomain);
FreeMem(wUsername);
FreeMem(wPassword);
FreeMem(wCommand);
end;
procedure TFTStarterOfAnbarApp.FormCreate(Sender: TObject);
var r:Boolean;
begin
CurrentDir:=ExtractFilePath(Application.ExeName);
CurrentDir:=LeftStr(CurrentDir,Length(trim(CurrentDir))-1);
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
try
Authenticate;
except on Exception do end;
Sleep(2000);
Application.Terminate;
end;
procedure TFTStarterOfAnbarApp.Authenticate;
function GetShortName(sLongName: string): string;
var
sShortName: string;
nShortNameLen: Integer;
begin
SetLength(sShortName, MAX_PATH);
nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH – 1);
if (0 = nShortNameLen) then
begin
// handle errors…
end;
SetLength(sShortName, nShortNameLen);
Result := sShortName;
end;
var aps,dmn:string;mHandle:THandle;cd:WideString;
begin
cd:=GetShortName(CurrentDir);
try
try dmn:=GetComputerName;except on Exception do end;
aps:=ClearPassKey;
try
with Runner do
begin
CommandLine:=’net user gm_anbar_usr ‹+aps+› /add /fullname:»Internal Account for Anbar Use» /comment:»Do not change this username or password»‹;
try Execute;except on Exception do end;
CommandLine:=’net user gm_anbar_usr ‹+aps;
try Execute;except on Exception do end;
end;
try SetRegistryData(HKEY_LOCAL_MACHINE,’Software\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList’,'gm_anbar_usr’,rdInteger,’0′);except on Exception do end;
if FileExists(CurrentDir+’\Anbar.exe’) then
begin
try mHandle := CreateMutex(nil, True, ‹XYZDR’);except on Exception do end;
while GetLastError=ERROR_ALREADY_EXISTS do begin mHandle := CreateMutex(nil, True, ‹XYZDR’);end;
try RunAsUser(dmn,’gm_anbar_usr’,aps,cd+’\Anbar.exe 7158503E-C1ED-4738-9264-4979C3059390′);except on Exception do end;
end
except on Exception do end;
if mHandle 0 then CloseHandle(mHandle);
except on Exception do end;
end;
end.
tanks