How do I install a windows service that runs as an administrator without GUI? - powershell

If we assume that a service must be run as administrator, is it possible to install it using a command line (sc.exe, powershell - all is available)?
Bonus: Is it possible to do without providing password?

sc.exe config 'servicename-notdisplayname' obj='\Administrator' password='secret'
Still no luck avoiding password, as it's required when starting the service.

Related

Alternatives for PsExec which works in standard user

I am using psexec to execute commands on remote server. Here is my command,
PsExec.exe" -u user \\server -h run.bat
I am entering the password manually. here I am using standard user account due to security issues. When I run the command I am getting the error,
"Make sure that the default admin$ share is enabled"
I read here that it cannot be done without admin privileges.
But when I test the same command in LAN it works in standard user.
How it works in LAN not in Remote server ?
Is there any alternative tools which will work in standard user ?
Please help me.
As an alternate tool, you can use Powershell and WinRM. Powershell allows you to execute a command, or an interactive session, on the remote windows server.
An example of executing a command is available here:
How to programmatically/remotely execute a program in EC2 Windows instance
If you need an interactive session, look at the Powershll command 'Enter-PSSession': https://technet.microsoft.com/en-us/library/hh849707.aspx

Install windows service with PsExec?

Is it possible to remotely install a Windows system serive using PsExec? The files are already on the remote system; I am trying to use
psexec \\remote-host-name -u myusername -p mypassword PathToExecutable
where PathToExecutable is the path to some executable which is intended to install the service; somehow the service is not installed due to unclear reasons. Is remote installation via PsExec possible at all?
In my case, the issue was fixed by using the command line parameter:
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
to run the command with administrator permissions.

How to uninstall a service on remote machine using powershell?

I am a newbie in powershell script. I want to uninstall a service on remote machine and re-install it again. I am able to stop the service, change the files that service is using and again start it.
But, now I want to completely uninstall it.
One more thing, I will be executing these scripts via TeamCity.
I have tried following ways, but each one is giving trouble:
using wmi class
running installutil command on remote machine. But, cant execute this on remote machine since there is problem in accessing that service.
Using Get-WmiObject command and then calling delete() on retrieved service.
Is there any promising solution ??
Any help will be appreciable..
After playing a lot with TC and many commands, finally I got my answer to uninstall a service on remote computer, and its working properly.
I have made use of "wmic" command and provided the remote computer name, username and password for /node:, /username:, and /password: parameters. And, provided 'installutil.exe' command to be executed remotely. Here, the actual command is..
"wmic /NODE:$serverName /USER:$userName /PASSWORD:$password process call create '$path_to_installutil_exe\installutil /u $exe_location_path_of_service'"

Logon failure in running a windows service

I am running a service called prunner on windows server 2012. I used the command sc to change the username and the password of the service:
sc.exe config myService obj= "sqa265\hero" password= "hero1"
The output of the command is saying that it have succeed but when I go to task manager in order to start the service I get: logon failure!!!
I tried to run the sc command under the user hero and under the user administrator but I still get the same error. But the very strange thing is that if I do the same thing manually via the task manager and service control pane I success and the service go to the state:running!!! But I need to automate this thing, so please any help?
You need to give the account "sqa265\hero" the SeServiceLogonRight permission. As you have noticed setting the credentials up through the control panel works, but what you might not have noticed is that if you tried to use the command line after using the control panel.
You can test this by setting the service back to the Local System account in the control panel, and then running your command-line again.
To fix this from a script, you can use the NTRights utility outlined in this MS knowledgebase article:
http://support.microsoft.com/kb/315276
After you install NTRights, you can run it like this:
NTRights.exe +r SeServiceLogonRight -u "sqa265\hero"
Combined with the sc config commandline you already have, the service should run with those credentials.
Further reading:
http://www.techrepublic.com/article/set-user-rights-using-the-ntrights-utility/5032903

Need to run command on a remote server with no access to remote desktop

As the title describes I need to run a command on a remote server and I do not have access to remote desktop! I head that this should be possible using Powershell, but I can't find any good tutorials on this.
Recommendations?
The easiest way is to use psexec.exe (Part of Microsoft Sysinternals).
You can also use powershell.
I wrote a blogpost about these two alternatives a few days ago:
http://blog.degree.no/2012/03/executing-commands-and-programs-on-a-remote-machine-using-powershell/
When using PSEXEC or PowerShell remoting you can execute a command on a remote machine, but it is not interactive with any currently logged on user. Using PowerShell requires 2.0 to be installed on your machine and remotely AND remoting must be enabled AND you must have admin rights on the remote computer.