You've already forked lazarus-ccr
V0.2.5.0: Better windows IsAdmin function
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5667 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
<IsPartOfProject Value="True"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<CursorPos X="33" Y="27"/>
|
||||
<UsageCount Value="44"/>
|
||||
<UsageCount Value="46"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
@ -21,7 +21,7 @@
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<TopLine Value="64"/>
|
||||
<CursorPos X="19" Y="103"/>
|
||||
<UsageCount Value="44"/>
|
||||
<UsageCount Value="46"/>
|
||||
<Loaded Value="True"/>
|
||||
<LoadedDesigner Value="True"/>
|
||||
</Unit1>
|
||||
@ -32,27 +32,28 @@
|
||||
<WindowIndex Value="1"/>
|
||||
<TopLine Value="3"/>
|
||||
<CursorPos X="76" Y="8"/>
|
||||
<UsageCount Value="27"/>
|
||||
<UsageCount Value="29"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="..\lazautoupdate_httpclient.pas"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<CursorPos X="97" Y="12"/>
|
||||
<UsageCount Value="21"/>
|
||||
<UsageCount Value="22"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<WindowIndex Value="1"/>
|
||||
<TopLine Value="1766"/>
|
||||
<CursorPos X="111" Y="1791"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<TopLine Value="483"/>
|
||||
<CursorPos Y="545"/>
|
||||
<ExtraEditorCount Value="2"/>
|
||||
<ExtraEditor1>
|
||||
<EditorIndex Value="4"/>
|
||||
<TopLine Value="1163"/>
|
||||
<CursorPos X="11" Y="1253"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<WindowIndex Value="1"/>
|
||||
<TopLine Value="539"/>
|
||||
<CursorPos Y="548"/>
|
||||
</ExtraEditor1>
|
||||
<ExtraEditor2>
|
||||
<EditorIndex Value="-1"/>
|
||||
@ -60,7 +61,7 @@
|
||||
<TopLine Value="-1"/>
|
||||
<CursorPos X="-1" Y="-1"/>
|
||||
</ExtraEditor2>
|
||||
<UsageCount Value="21"/>
|
||||
<UsageCount Value="22"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
@ -104,7 +105,7 @@
|
||||
<EditorIndex Value="2"/>
|
||||
<TopLine Value="25"/>
|
||||
<CursorPos X="25" Y="55"/>
|
||||
<UsageCount Value="19"/>
|
||||
<UsageCount Value="20"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit10>
|
||||
<Unit11>
|
||||
@ -119,7 +120,7 @@
|
||||
<EditorIndex Value="5"/>
|
||||
<TopLine Value="25"/>
|
||||
<CursorPos X="71" Y="44"/>
|
||||
<UsageCount Value="16"/>
|
||||
<UsageCount Value="17"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit12>
|
||||
<Unit13>
|
||||
@ -149,143 +150,139 @@
|
||||
<WindowIndex Value="1"/>
|
||||
<TopLine Value="35"/>
|
||||
<CursorPos X="40" Y="51"/>
|
||||
<UsageCount Value="11"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit16>
|
||||
<Unit17>
|
||||
<Filename Value="C:\NewPascal\projects\snippets\usefulunits\uuser.pas"/>
|
||||
<UnitName Value="uUser"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="6"/>
|
||||
<CursorPos Y="25"/>
|
||||
<UsageCount Value="10"/>
|
||||
<CursorPos X="33" Y="16"/>
|
||||
<UsageCount Value="11"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit17>
|
||||
</Units>
|
||||
<General>
|
||||
<ActiveWindowIndexAtStart Value="1"/>
|
||||
</General>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="56" Column="27" TopLine="28"/>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="14" TopLine="3"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="533" Column="45" TopLine="519"/>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="22" TopLine="3"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="16"/>
|
||||
<Caret Line="20" Column="7" TopLine="7"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="13" Column="43" TopLine="12"/>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="25"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="14" TopLine="3"/>
|
||||
<Caret Line="24"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="22" TopLine="3"/>
|
||||
<Caret Line="25"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="20" Column="7" TopLine="7"/>
|
||||
<Caret Line="26" Column="8" TopLine="2"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="25"/>
|
||||
<Caret Line="16" TopLine="3"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="24"/>
|
||||
<Caret Line="26" Column="2" TopLine="5"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="25"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="56" Column="27" TopLine="28"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="26" Column="8" TopLine="2"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="52" Column="19" TopLine="28"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="16" TopLine="3"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="56" Column="19" TopLine="28"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="..\open_ssl.pas"/>
|
||||
<Caret Line="26" Column="2" TopLine="5"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="926" Column="38" TopLine="889"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="56" Column="27" TopLine="28"/>
|
||||
<Caret Line="55" Column="27" TopLine="29"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="52" Column="19" TopLine="28"/>
|
||||
<Caret Line="926" Column="38" TopLine="892"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="56" Column="19" TopLine="28"/>
|
||||
<Caret Line="1083" Column="39" TopLine="1045"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="926" Column="38" TopLine="889"/>
|
||||
<Caret Line="51" Column="22" TopLine="28"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="55" Column="27" TopLine="29"/>
|
||||
<Caret Line="52" Column="19" TopLine="28"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="926" Column="38" TopLine="892"/>
|
||||
<Caret Line="55" Column="19" TopLine="28"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="1083" Column="39" TopLine="1045"/>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="53" Column="103" TopLine="32"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="51" Column="22" TopLine="28"/>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="82" Column="9" TopLine="47"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="52" Column="19" TopLine="28"/>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="89" Column="30" TopLine="58"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="55" Column="19" TopLine="28"/>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="15" Column="23"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="53" Column="103" TopLine="32"/>
|
||||
<Caret Line="79" Column="26" TopLine="53"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="82" Column="9" TopLine="47"/>
|
||||
<Caret Line="157" Column="94" TopLine="115"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="89" Column="30" TopLine="58"/>
|
||||
<Caret Line="95" TopLine="64"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="15" Column="23"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="518" Column="16" TopLine="483"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="79" Column="26" TopLine="53"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="1823" Column="4" TopLine="1796"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="157" Column="94" TopLine="115"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="577" Column="7" TopLine="544"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="umainform.pas"/>
|
||||
<Caret Line="95" TopLine="64"/>
|
||||
<Filename Value="..\ulazautoupdate.pas"/>
|
||||
<Caret Line="539" Column="7" TopLine="516"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectSession>
|
||||
|
@ -1,7 +1,7 @@
|
||||
object mainform: Tmainform
|
||||
Left = 558
|
||||
Left = 125
|
||||
Height = 209
|
||||
Top = 210
|
||||
Top = 292
|
||||
Width = 335
|
||||
BorderIcons = [biSystemMenu]
|
||||
Caption = 'mainform'
|
||||
|
@ -128,12 +128,7 @@ const
|
||||
{$IFDEF CPU64}C_UPDATER = 'updatehmwin64.exe';
|
||||
C_LOCALUPDATER = 'lauupdatewin64.exe';{$ENDIF}
|
||||
// Windows Constants
|
||||
CONST
|
||||
GENERIC_READ = $80000000;
|
||||
GENERIC_WRITE = $40000000;
|
||||
GENERIC_EXECUTE = $20000000;
|
||||
GENERIC_ALL = $10000000;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
{$IFDEF CPU32}C_UPDATER = 'updatehmlinux32';
|
||||
C_LOCALUPDATER = 'lauupdatelinux32';{$ENDIF}
|
||||
@ -263,7 +258,7 @@ type
|
||||
procedure SetShowDialogs(AValue: boolean);
|
||||
procedure SetDebugMode(AValue: boolean);
|
||||
function GetThreadDownloadReturnCode: integer;
|
||||
function IsSourceForgeVersionNewer(const sznewINIPath: string): boolean;
|
||||
function IsOnlineVersionNewer(const sznewINIPath: string): boolean;
|
||||
function VersionStringToNumber(AVersionString: string): integer;
|
||||
function DoSilentUpdate: boolean;
|
||||
protected
|
||||
@ -482,7 +477,71 @@ begin
|
||||
ShowMessage(fApplicationVersionString);
|
||||
end;
|
||||
{$IFDEF WINDOWS}
|
||||
function IsWindowsAdmin: boolean;
|
||||
function IsWindowsAdmin: Boolean;
|
||||
const
|
||||
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority =
|
||||
(Value: (0, 0, 0, 0, 0, 5));
|
||||
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
|
||||
DOMAIN_ALIAS_RID_ADMINS = $00000220;
|
||||
var
|
||||
hAccessToken: THandle;
|
||||
ptgGroups: PTokenGroups;
|
||||
dwInfoBufferSize: DWORD;
|
||||
psidAdministrators: PSID;
|
||||
x: Integer;
|
||||
bSuccess: BOOL;
|
||||
LastError: integer;
|
||||
begin
|
||||
|
||||
if Win32Platform <> VER_PLATFORM_WIN32_NT then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Result := False;
|
||||
bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,
|
||||
hAccessToken);
|
||||
if not bSuccess then
|
||||
begin
|
||||
if GetLastError = ERROR_NO_TOKEN then
|
||||
bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,
|
||||
hAccessToken);
|
||||
end;
|
||||
if bSuccess then
|
||||
begin
|
||||
GetMem(ptgGroups, 1024);
|
||||
bSuccess := GetTokenInformation(hAccessToken, TokenGroups,
|
||||
ptgGroups, 1024, @dwInfoBufferSize);
|
||||
LastError := GetLastError;
|
||||
if not bSuccess then
|
||||
showmessage(format('GetLastError %d',[LastError]));
|
||||
CloseHandle(hAccessToken);
|
||||
if bSuccess then
|
||||
begin
|
||||
AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,
|
||||
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
||||
0, 0, 0, 0, 0, 0, psidAdministrators);
|
||||
{$R-}
|
||||
for x := 0 to ptgGroups^.GroupCount - 1 do
|
||||
if EqualSid(psidAdministrators, ptgGroups^.Groups[x].Sid) then
|
||||
begin
|
||||
Result := True;
|
||||
break;
|
||||
end;
|
||||
{$R+}
|
||||
FreeSid(psidAdministrators);
|
||||
end;
|
||||
FreeMem(ptgGroups);
|
||||
end;
|
||||
end;
|
||||
|
||||
function IsWindowsAdminWinXP: boolean;
|
||||
CONST
|
||||
GENERIC_READ = $80000000;
|
||||
GENERIC_WRITE = $40000000;
|
||||
GENERIC_EXECUTE = $20000000;
|
||||
GENERIC_ALL = $10000000;
|
||||
var
|
||||
hSC: THandle;
|
||||
begin
|
||||
@ -857,7 +916,7 @@ begin
|
||||
mtInformation, [mbOK], 0);
|
||||
end;
|
||||
|
||||
function TLazAutoUpdate.IsSourceForgeVersionNewer(const sznewINIPath: string): boolean;
|
||||
function TLazAutoUpdate.IsOnlineVersionNewer(const sznewINIPath: string): boolean;
|
||||
// Compares version contained in szTempXMLPath INI file
|
||||
// to fApplicationVersionNumber
|
||||
var
|
||||
@ -1058,7 +1117,7 @@ begin
|
||||
fOndebugEvent(Self, 'NewVersionAvailable',
|
||||
Format('Downloaded %s OK', [szTargetPath]));
|
||||
fParentApplication.ProcessMessages;
|
||||
Result := IsSourceForgeVersionNewer(szTargetPath);
|
||||
Result := IsOnlineVersionNewer(szTargetPath);
|
||||
if fFireDebugEvent then
|
||||
fOndebugEvent(Self, 'NewVersionAvailable',
|
||||
Format(C_DownloadedBytes, [szTargetPath, fDownloadSize]));
|
||||
@ -1785,6 +1844,7 @@ var
|
||||
begin
|
||||
Result := False;
|
||||
{$IFDEF WINDOWS}
|
||||
|
||||
If NOT IsWindowsAdmin then
|
||||
begin
|
||||
szParams:='Only Windows users whith Administrator status can update this application.' + lineending;
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user