Detect if run as Administrator?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
rullbandspelare
Pro Scripter
Posts: 148
Joined: Tue Mar 23, 2004 9:11 pm

Detect if run as Administrator?

Post by rullbandspelare » Fri Sep 22, 2017 7:20 pm

Hi!

Can I detect if the user has started the compiled .exe as "Run as Administrator"?

If The user does this then some things are different and I must fix that. Like Mapped drive letters and certificates.

Thanks!

User avatar
JRL
Automation Wizard
Posts: 3460
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Detect if run as Administrator?

Post by JRL » Fri Sep 22, 2017 7:57 pm

Test for something the admin has that the user does not. A file or a drive might work.

rullbandspelare
Pro Scripter
Posts: 148
Joined: Tue Mar 23, 2004 9:11 pm

Re: Detect if run as Administrator?

Post by rullbandspelare » Sat Sep 23, 2017 3:39 am

Thanks.

I was thinking that You could read the RP_ADMIN variable or something like that for that info.

This appears to work

Code: Select all

Let>WLN_NOCRLF=1
WriteLn>c:\windows\system32\drivers\etc\hosts,x,
If>x=0
MessageModal>Administrator
else
MessageModal>User
endif

ocnuybear
Pro Scripter
Posts: 96
Joined: Sun Jul 15, 2018 5:14 pm

Re: Detect if run as Administrator?

Post by ocnuybear » Fri Jul 01, 2022 11:03 am

Alternative Version:

Code: Select all

Let>nWLNRes=
WriteLn>C:\text.txt,nWLNRes,
IFNOT>nWLNRes=0
  MessageModal>!!!Please Run as Admin!!!
  Exit
ENDIF

User avatar
JRL
Automation Wizard
Posts: 3460
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Detect if run as Administrator?

Post by JRL » Fri Jul 01, 2022 7:21 pm

Good one!
I would add an Else to delete the test.txt file

Code: Select all

Let>nWLNRes=
WriteLn>C:\text.txt,nWLNRes,
IFNOT>nWLNRes=0
  MessageModal>!!!Please Run as Admin!!!
Else
  MDL>Yippie !!!
  DeleteFile>C:\text.txt
ENDIF
Exit>

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts