Check User Privileges / Force Admin

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Check User Privileges / Force Admin

Post by stoavio » Sat Nov 01, 2014 1:42 pm

Good morning again -

Does LiveCode have any built-in functions for looking at the currently logged in user's permissions (ie: is the user a regular user or administrator?) My tool may need elevated privileges to perform certain tasks and I would like to perform an evaluation upfront to determine what scope of access the user running my tool actually has. If there is a built-in way to accomplish this without farming it out to another process (for example, parsing the output of net user <username>), that would be awesome.

In addition, can I make my tool require admin rights in order to run? I know in AutoIt you can toss a "#RequireAdmin" at the top of the script to make the application immediately prompt for administrator permission upon execution.

I am open to some creative solutions. I am always looking for the most efficient way of completing something using LC.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Check User Privileges / Force Admin

Post by Da_Elf » Sun Nov 02, 2014 12:24 am

in the main stack i set two custom properties, "cUserLevel" and "cUserID" which is altered when the user logs on or off. Then i just access that info wherever i need to

stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Re: Check User Privileges / Force Admin

Post by stoavio » Mon Nov 03, 2014 12:41 pm

Da_Elf wrote:in the main stack i set two custom properties, "cUserLevel" and "cUserID" which is altered when the user logs on or off. Then i just access that info wherever i need to
This sounds interesting. Can you elaborate? I see where you can create the custom properties but what are you supposed to put at their contents? Sorry, I haven't done any work with custom properties in LC yet but this sounds like it could be an elegant solution.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Check User Privileges / Force Admin

Post by SparkOut » Mon Nov 03, 2014 11:05 pm

I think a clarification is needed... Are you talking about the user status relative to your application or the status of the user relative to the installation of the operating system (windows administrator, root/sudoer,etc)? A system for the former is straightforward, a comprehensive (and cross platform) solution may involve more specific shell commands, etc.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Check User Privileges / Force Admin

Post by FourthWorld » Mon Nov 03, 2014 11:16 pm

See the notes on the "elevated" option for the "open process" command in the Dictionary:
Changes: Sometimes it is necessary to perform operations on the local machine as an administrator, and a typical pattern for a GUI application doing this is for it to prompt for authentication at certain points.

Modern operating systems do not permit a process to elevate itself, nor grant itself increased privilege. Instead, they only allow a running process to launch another process with increased privilege. Therefore, in order to support this, in version 4.5 a new form of the open process command was introduced that can launch a slave process with elevated permissions:

open elevated process process [ for [ text | binary ] ( read | write | update | neither ) ]

This form operates identically to the normal version, except that engine will ask the system to launch the given process with admin/root privileges.

The standard way for a GUI application that needs to perform privileged operations to be structured is to split the application into two parts: a GUI front-end that interacts with the user, and a command-line back-end that is run with elevated permissions. These two parts can then talk to each other using a standard master-slave approach, or some other form of IPC such as sockets
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Re: Check User Privileges / Force Admin

Post by stoavio » Wed Nov 05, 2014 12:28 pm

Thanks all!

Richard, that was just what I needed! :D

Post Reply