I have connected my remote machine using Master and slave method. And our Job is to remotely start and stop the tomcat service.
We are using powershell build to achieve this. in which, “Stop-Service Tomcat” command getting failed, throwing error that it requires an elevated access.
We also tried different combination of scripts which run powershell as admin mode within normal powershell, But still it requires a manual intervention of click ok in the remote server to procced.
Is there anyway in jenkins to run the powershell with elevated access in jenkins?
If the error is like
Stop-Service: Service ‘Tomcat’ cannot be stopped due to the following error: Cannot open ‘Tomcat’ service on computer ‘.’.
then I think you can fix it by modifying the security descriptor of the Tomcat service to grant the SERVICE_STOP (0x0020) access right to the user account as which the Jenkins agent runs. To modify the security descriptor, use “sc.exe sdset” or “Set-Service -SecurityDescriptorSddl”. The new security descriptor will persist across reboots.
Security Descriptor Definition Language: Security Descriptor Definition Language - Win32 apps | Microsoft Docs
Service Security and Access Rights: Service Security and Access Rights - Win32 apps | Microsoft Docs
However, if Stop-Service instead throws an error saying explicitly that it requires “elevated access”, then I don’t think changing the security descriptor will help.