windows service installation "Administrator access is needed" - windows

I am using NSSM (the Non-Sucking Service Manager) to install a windows service from a batch file like this
"nssm install C:\stash\runstash.bat"
but it throws:
"Administrator access is needed to install a service"
When I check user accounts in control panel, it shows that I am logged in with a User Name in the "Administrators" group.
Does anyone knows any possible reasons for this issue?
Thanks

You running it from command line, right? Then run with admin rights. There few possible ways:
right click on cmd shortcut, the run as administrator
execute cmd /admin
I believe you have UAC on on your PC, that's most programs run with user grant by defaul

Related

stop and start IIS server for TFS build Access denied

I need to stop and start IIS server for TFS build. When do this using .bat file iisreset /stop, similarly for start.
When I do this I get
Access denied, you must be an administrator of the remote computer to use this command. Either have your account added to the administrator local group of the remote computer or to the domain administrator global group.
Please note: This is Windows server 2019
I am already admin of this machine.
I have given read/write access to everyone in this folder.
I have unset EnableLUA to '0' in the registry as told in link for site
Above all these, I restarted machine.
I still get error in TFS build.
When you start a build in TFS the execution of that build is effectively done by a build agent. A build agent is just a service running on any particular machine. So, your batch file that shall start/stop the IIS service will be executed by whatever build agent is running your particular build.
This in terms means that your batch file is executed by the user that is used to run the build service. If that user does not have the necessary admin rights you face this particular error message.
What you need to do is make sure that all accounts that you use to run your build agents have administrative permissions on whatever machine you want to start/stop IIS.
You are trying to do IISRESET in your batch script. You need to be an Administrator as basic right to execute IISRESET command. So the account which the build is running needs to be part of the Admin group on the box.
Other approach is to stop and start w3svc using sc config commands or NET STOP WAS /Y and NET START W3SVC
Both of your answers are correct, I added the 'Network Service' of TFS to admin group of machine. Then build was success. Administrative tools>Computer Management> Local Users and Groups>Groups>
Inside Administrators and Users add 'Network Services'. If you don't find 'Network Service' then change location to your computer node and add them.

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

Install appx through Powershell Plugin via Jenkins

I am stuck in a problem trying to install appx with Powershell -ExecutionPolicy Unrestricted add-appxpackage <path to appx> using the Powershell plugin in Jenkins and the below errors are logged:
add-appxpackage : Deployment failed with HRESULT: 0x80073CF9, Install failed.
Please contact your software vendor. (Exception from HRESULT: 0x80073CF9)
Deployment Add operation rejected on package
<path to appx> install request because the Local
System account is not allowed to perform this operation.
NOTE: For additional information, look for [ActivityId].
As I understand, this problem is mainly because Jenkins service on Windows gets installed as NT Authority\System. (If I use psexec.exe to open a command prompt that runs as Authority\System, I run into the same issue.) I then tried adding net localgroup "Administrators" NT Authority\System /add hoping the group might get added as Administrator and would let me install the appx, so I can run the tests, but with no success. Now I am stuck and I am not sure if there is really a way to install an appx via Jenkins or not OR if there is a way to invoke the Powershell script as an administrator via Jenkins. I have been through couple of SO links already, but none of them seems to fix the issue I am facing. Any pointers would be appreciated.
DO NOT try to add System to the Administrators group, it's a limited account for a reason and does not require administrative privileges.
Instead change the Jenkins service to run as a user that has the right permissions for what you're trying to do. That might mean you need to create an account specifically for the Jenkins service.
There are a few ways to change the service account, this answer gives the following as a solution:
sc.exe config "Service Name" obj= "DOMAIN\User" password= "password"

Failed to add current user to Hyper-V administrators group error when installing Visual Studio Community 2013

I used to have Visual Studio Express installed on my laptop, which worked well, but when I heard Community 2013 was made available for free I decided to install it. However, after running the install process I got the error:
Failed to add current user to Hyper-V administrators group
The account I am using is an admin account. When I checked for solutions I found many people indicating I had to Microsoft Management Console and add myself to the group, however this laptop has Windows 8.1 Core, not pro, so I cannot add the snapin. So I am not really sure what to do in this situation. Do I need to reinstall, running it as admin? Or will I get the same error again?
Try net localgroup "Hyper-V Administrators" <username> /add
in an elevated command prompt
It's case sensitive apparently:
Try net localgroup "Hyper-V Administrators" /add
Please check the right name of Hyper-V Administrators group. The group name may be different in the different locales.
Open the window Windows+R -> lusrmgr.msc in this window you may check all groups in your system
and use command
net localgroup "<Hyper-V group name>" <username> /add
For me below steps worked with me
preflight checks can all be individually disabled. For the HyperV check you can use:
minishift config set skip-check-hyperv-driver true
If you prefer the check to happen, but not fail startup, you can use the warn option instead:
minishift config set warn-check-hyperv-driver true

Resources