Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:11:47+00:00 2026-05-16T03:11:47+00:00

Also in the following code, which is more efficient? if (Length(ParamStr(1)) <> 0) then

  • 0

Also in the following code, which is more efficient?

if (Length(ParamStr(1)) <> 0) then

or

if (ParamStr(1) <> ”) then

{$A8,B-,C-,D-,E-,F-,G+,H+,I-,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V-,W-,X+,Y-,Z1}

program LaunchUAC;

uses
    Windows, ShellAPI;

{$R 'MANIFEST.RES'}
(*
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) eyeClaxton Software (www.eyeclaxton.com) -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        processorArchitecture="x86"
        version="1.0.0.0"
        name="eyeClaxton.asInvoker.LaunchUAC" type="win32" />
    <description>asInvoker LaunchUAC</description>
    <dependency>
    <dependentAssembly>
    <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="x86"/>
    </dependentAssembly>
    </dependency>
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
    </application>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
        <requestedPrivileges>
            <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
        </requestedPrivileges>
    </security>
    </trustInfo>
</assembly>
*)

function IsMinimumVista(): Boolean;
var
    OSVerInfo: TOSVersionInfo;
begin
    OSVerInfo.dwOSVersionInfoSize := SizeOf(OSVerInfo);
    Result := Windows.GetVersionEx(OSVerInfo) and (OSVerInfo.dwMajorVersion > 5);
end;

procedure RunAsAdmin(theHandle: hWnd; theFilename: string;
    theParams: string; theShow: Integer; bWaitFor: Boolean = True);
var
    ShellExInfo: TShellExecuteInfo;
    hHandle: DWORD;
    Msg: TMsg;
    MsgResult: LongBool;
begin
    Windows.ZeroMemory(@ShellExInfo, SizeOf(ShellExInfo));
    ShellExInfo.cbSize := SizeOf(TShellExecuteInfo);
    ShellExInfo.Wnd := theHandle;
    ShellExInfo.fMask := SEE_MASK_FLAG_DDEWAIT;
    if bWaitFor then
        ShellExInfo.fMask := ShellExInfo.fMask or SEE_MASK_NOCLOSEPROCESS;
    if (Launch.IsMinimumVista()) then
        ShellExInfo.lpVerb := PChar('runas');
    ShellExInfo.lpFile := PChar(theFilename);
    if (Length(theParams) <> 0) then
        ShellExInfo.lpParameters := PChar(theParams);
    ShellExInfo.nShow := theShow;

    hHandle := 0;
    if ShellAPI.ShellExecuteEx(@ShellExInfo) then
    try
        hHandle := ShellExInfo.hProcess;
        if bWaitFor then
        begin
            while (Windows.WaitForSingleObject(hHandle, 50) <> WAIT_OBJECT_0) do
                repeat
                    MsgResult := PeekMessage(Msg, ShellExInfo.Wnd, 0, 0, PM_REMOVE);
                    if MsgResult then
                    begin
                        Windows.TranslateMessage(Msg);
                        Windows.DispatchMessage(Msg);
                    end;
                until (not (MsgResult));
        end;
    finally
        if (hHandle <> 0) then
            Windows.CloseHandle(hHandle);
    end;
end;

begin
    if (Length(ParamStr(1)) <> 0) then
        Launch.RunAsAdmin(0, ParamStr(1), ParamStr(2), SW_SHOWNORMAL)
    else
        Windows.MessageBeep(MB_ICONERROR);
end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:11:48+00:00Added an answer on May 16, 2026 at 3:11 am

    If you’re determined to avoid threads, I would suggest using MsgWaitForMultipleObjects but only have your spawned process handle in the array. Once you get a return value of WAIT_OBJECT_0, you can call GetExitCodeProcess.

    At a guess,since you’re using Pascal strings which have a pre-calculated length, checking the length should be more efficient than doing a compare against an empty string, but it’s entirely possible the compiler may convert one into the other anyway, if it’s smart enough to spot the compare against ”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following pieces of code, which one is more efficient? The real method
The following code sample (also at http://jsfiddle.net/MZwBS/ ) var items = []; items.push({ example:
Why does following code snippet doesn't work? It doesn't gives any error, but also
I have downloaded sample code from Apple Center.I also have gone through following question:
I have the following piece of code which is not working the way I
I'm using Autoconf to build my c++ project. It uses third party code which
I have the following code which should remove all HTML from a part of
I have the following code which gives the warning in the title. I am
Given the following code which works: for (i=0; i<nLinears; i++) { for (j=0; j<nLinearPts[i]-1;
I have the following code which sometimes return as true and sometimes doesn't. Any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.