Jump to content

Is it possible to run a function with elevated privs?


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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.

Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...