Jump to content
Sign in to follow this  
PnoT

Is it possible to run a function with elevated privs?

Recommended Posts

PnoT

I need my program to run as a user (non admin) but certain buttons that are tied to _functions will need to be run as an admin. Is this possible? If not what are my alternatives?

I could use the button to run an additional .exe script with the RunAs command but that seems like a waste and I'll have to deploy more files to every machine.

I was also toying with the idea of using #RequireAdmin in the script, which would make all of my admin _functions work BUT will throw off the @Username @homeshare and other variables i need intact.

Share this post


Link to post
Share on other sites
WiSp

Yes it's possible. Have your button call a function, in the function you can either prompt for credentials or embed them.

Share this post


Link to post
Share on other sites
Richard Robertson

You cannot run functions under a separate user than the main process.

Why would running as admin change the username etc variables?

Share this post


Link to post
Share on other sites
PnoT

You cannot run functions under a separate user than the main process.

Why would running as admin change the username etc variables?

Try running an application with Runas or using #Requireadmin and then try and poll @Username. It will pull the admins username instead of the current logged on user. That is an issue for me.

I need the application to pull all the current user's info but also need the ability to run a function or command as an admin. The tool I've built is for technical support but things such as installing a program, with a button i have created in the gui, will not work without admin rights.

Is there some way to get around this?

Edited by PnoT

Share this post


Link to post
Share on other sites
PnoT

Yes it's possible. Have your button call a function, in the function you can either prompt for credentials or embed them.

How is that accomplished?

Share this post


Link to post
Share on other sites
Richard Robertson

Can you bind @UserName to a variable before you #RequireAdmin? I have no idea is this will work or not because I can't test it.

Local $sUserName = @UserName
#RequireAdmin
MsgBox(0, "", $sUserName)

That won't work because #RequireAdmin applies to the entire script. It doesn't matter where you put it.

You can make two processes. Start one process that doesn't have #RequireAdmin. Have it save the user etc data to a file, and then call the main program that has #RequireAdmin and have it read the file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×