Run exe as admin after install - windows

I need to run an AutoIt program with administrator privileges. I use #requireadmin while installing. Is that enough to run the program after install with administrative privileges without using #requireadmin or should I try something else?

You must use #requireadmin in the 2nd program because it is affects current script only.

When you install your program and it is run with admin privileges, you can create a scheduled task that has the "run with highest privileges" option set. Then later when your application is run without admin privileges it can run this task in order to gain admin privileges.
Search around for ObjCreate("Schedule.Service") or for task scheduler UDFs for how to do this. Also for examples and documentation for the task scheduler com object in windows here.

Related

Is there a method of running an application as a standard user?

I am currently testing permissions as an administrator and need to test something as a standard user. There are ways to make standard users run as administrator, but I can't think of a way to run as a standard user as an administrator. If I were to remove my administrator rights, it would take awhile for IT to give me my admin rights back. Is there a better option that doesn't include setting up my dev environment as another user? I'm trying to run Visual Studio as a standard user, if that helps.
Thanks in advance
Create a file with the contents "filename.reg":
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker]
#="Run without privilege elevation"
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker\command]
#="cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"%1\"\""
Run the file and apply registry changes, and then right click "Run without privilege elevation" on the file that needs to be tested. Found this solution from another thread! Thanks!

Check if electron app is launched with admin privileges on windows

Is there a way to check if an electron app is launched with the admin rights?
I only found electron-sudo lib to execute commands with admin privileges.
But I have multiple commands to execute and I do not want to prompt the user every time.
So how can I check if the app is started with admin privileges using electron ?
The best thing would be just to execute a command inside the software ex: .isAdminPrivilegesUsed (can be a script that is executed on Windows) that return true or false, and if false :
I will prompt the user that he has to restart the software with admin rights and close it
I checked into how to do this from Node and found this answer: How to know if node-webkit app is running with Administrator/elevated privilege?.
I checked into the answer, downloaded node-windows and tried it. The solution, however, brought up the UAC dialog and always responded with "The user has administrative privileges".
I dug into the node-windows code that handles the isAdminUser command and found that it tried to run NET SESSION and, if does not have privilege, tries to run it elevated causing the UAC dialog.
I pulled out the part that does the elevate and ended up with this snippet:
var exec = require('child_process').exec;
exec('NET SESSION', function(err,so,se) {
console.log(se.length === 0 ? "admin" : "not admin");
});
I tested this by running the application normally and with "Run as Administrator". The code above correctly displayed "not admin" when not run as administrator and "admin" when run as administrator.
This should work for the content of your .isAdminPrivilegesUsed method you referenced in the question.
You can now specify that an app should run with elevated privileges using the electron build tools:
electron-builder
Add the following to your package.json:
"build": {
"win": {
"requestedExecutionLevel": "highestAvailable"
}
},
highestAvailable or requireAdministrator available. For full details, see: https://www.electron.build/configuration/win.html#WindowsConfiguration-requestedExecutionLevel
electron-packager
When you call electron-packager add the following command-line parameter:
--win32metadata.requested-execution-level=highestAvailable
highestAvailable or requireAdministrator available. For full details, see https://electron.github.io/electron-packager/master/interfaces/electronpackager.win32metadataoptions.html#requested_execution_level
Note
These options make the program request elevated privileges rather than check whether the program is running with administrator privileges.
If you are using electron-packager, just add --win32metadata.requested-execution-level=requireAdministrator. Eg:
electron-packager app --asar=true --platform=win32 --arch=ia32 --win32metadata.requested-execution-level=requireAdministrator --overwrite
Not a direct answer to your question. Another option to solve this problem is to force the application to be executed as administrator.
This can be done by updating the manifest file for the application, one guide on how to do this with Electron is here: http://layer0.authentise.com/electron-and-uac-on-windows.html
A popular Electron app has a solution for this problem
https://github.com/microsoft/vscode
In the package.json file they have two useful dependencies:
https://www.npmjs.com/package/native-is-elevated
https://www.npmjs.com/package/#vscode/sudo-prompt
They check to see if permissions are elevated using native-is-elevated, and if not, prompt for an admin password using sudo-prompt.
You can read the source code for the process here:
https://github.com/microsoft/vscode/blob/8845f89c1e4183b54126cd629cd45c8f0f7549f2/src/vs/platform/native/electron-main/nativeHostMainService.ts#L491
I have created an example Electron app using this approach here:
https://github.com/kmturley/electron-runas-admin

task scheduler + windows 7 + won't run task

I have a script that I can run from its directory giving this command:
c:\Users\UserName\Desktop\Folder\V3>C:\Windows\Syste
m32\WScript.exe "c:\Users\UserName\Desktop\Folder\V3\filename.vbs"
but if I try and do it from this location c:\
c:\>C:\Windows\Syste
m32\WScript.exe "c:\Users\UserName\Desktop\Folder\V3\filename.vbs"
I get permission denied, and I do not understand fully.
What permission do I have to have for this to work?
Note: I am trying to schedule this task in task Scheduler Windows7 which has led me to this question as this is what the task scheduler does.
I do not have local admin rights.
found this useful re trying to solve this.
I am just unsure of my permissions.
worked this out see here
Basically itt turns out I have to put the location of every script.vbs in the Start in: (optional) parmaeter of the Action tab for each schedule.

Permissions Elevation for Windows 7?

Ive got a java app which needs to execute a driver installer exe file. On Linux we type "gksudo myCommand". Is there a way to elevate permissions from Windows command line?
You may run every application in windows with a different user e.g. Administrator. But the user who executes this command needs to have the credentials to do so.
Edit.:
In advance you can lookup the User Account Control (UAC) which is available in Windows 7 and Vista if it is possibly an alternative for you.
I decided to deploy an executable binary onto the system which calls the jar. This way the user can right click and run as administrator... That didn't work... SO I kept looking... Check this out..
Elevate.exe.. It's basically like Windows GKSudo!!!!
http://www.robotronic.de/elevate.html
So... I packaged the 32bit exe into my program and deploy it, then run it as necessary.
You can use runas command like runas /user:Administrator myCommand (it requires the users to type password).
You can also use Start-Process cmdlet like Start-Process -Verb runas myCommand in PowerShell (it requires the users to click the UAC dialog).
see: http://satob.hatenablog.com/entry/2017/06/17/013217

chmod +s for Windows?

I have an executable that needs to run as an administrator on a Windows system, and it's started by a service. For the sake of simplicity and security, I'd prefer just to let the service run as the 'system' account, but would like the executable that it spawns to run with administrative privileges.
Is there anything like a chmod +s on Windows that would allow me to do this, such that when I'm installing things and registering the service as an administrator, I can flag the executable to be able to run as an administrator, or to do this would I need to register the service to run as an admin?
On Windows Vista and later, you can embed a manifest file in the executable that requests Windows to start the program with administrator access (see Create and Embed an Application Manifest (UAC)). This may or may not be useful, because the service account still needs administrative privileges even though your service itself need not be running with full administrator access.

Resources