The MASM Forum

General => The Laboratory => Topic started by: aw27 on March 14, 2019, 01:27:55 AM

Title: Challenge: Run as Administrator
Post by: aw27 on March 14, 2019, 01:27:55 AM
Without Manifest, without changing compatibility settings, without right clicking and select Run as Administrator or similar ways, how to run my program as Administrator?

Anyone?
Title: Re: Challenge: Run as Administrator
Post by: TimoVJL on March 14, 2019, 02:02:16 AM
my_setup.exe my_install.exe  ;)
Title: Re: Challenge: Run as Administrator
Post by: felipe on March 14, 2019, 02:16:56 AM
this challenge sounds a little against some of the forum rules :shock:
Title: Re: Challenge: Run as Administrator
Post by: aw27 on March 14, 2019, 02:28:28 AM
Only teasing...
Title: Re: Challenge: Run as Administrator
Post by: Siekmanski on March 14, 2019, 02:59:19 AM
OpenSCManager in combo with ShellExecute ?
Title: Re: Challenge: Run as Administrator
Post by: jj2007 on March 14, 2019, 05:11:30 AM
include \masm32\include\masm32rt.inc

.code
start:
  .if rv(ShellExecute, 0, chr$("runas"), rv(GetCommandLine), 0, 0, 0)>32
inkey "hi admin"
  .endif
  exit
end start
Title: Re: Challenge: Run as Administrator
Post by: aw27 on March 14, 2019, 05:13:09 AM
Very good JJ!
Only the guy that says "hi admin" is not the administrator.  :(
Title: Re: Challenge: Run as Administrator
Post by: Vortex on March 14, 2019, 06:27:55 AM
Hello,

Maybe this one :

CreateProcessWithLogonW :

https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createprocesswithlogonw
Title: Re: Challenge: Run as Administrator
Post by: jj2007 on March 14, 2019, 08:33:44 AM
Quote from: AW on March 14, 2019, 05:13:09 AM
Only the guy that says "hi admin" is not the administrator.  :(

Yep, you are right :P

include \masm32\include\masm32rt.inc

.code
start:
  invoke GetCommandLine
  xchg eax, ebx
  .if sdword ptr find$(1, ebx, "-A")>0
MsgBox 0, "I am the admin, really", "Hi", MB_OK
  .else
invoke ShellExecute, 0, chr$("runas"), ebx, chr$("-A"), 0, 0
  .endif
  exit
end start