How can I automate a Topshelf interactive service install?

你。 提交于 2019-12-04 17:59:19

Travis pointed me in the right direction with the command line options. I had one more problem with the service account username I had, which was prefixed with a "$": domain\$myuser. I could not find a way to escape it so the "install" command would accept it.

We created a similar username "myuser" (without the $). Now this works just fine:

MyService.exe install -username:domain\myuser -password:Bar 

The username and password are configuration in the app.config for services in my setting. This is used in the service setup block in the RunAs.

Additionally, there are other command line options for Topshelf. I don't know if the documentation is 100% up to date but it's a good place to start.

For future readers:

See this url:

https://kristofmattei.be/2015/01/15/topshelf-install-powershell-get-credentials/

Here is the important quote from the url above

Start Quote

So the best version is:

$credentialsOfCurrentUser = Get-Credential -Message "Please enter your username & password for the service installs"
$networkCredentials = $credentialsOfCurrentUser.GetNetworkCredential();
$username = $credentialsOfCurrentUser.UserName
$password = $networkCredentials.Password

Now that we have those variables we can pass them on to the install of the Topshelf exe:


. $pathToServiceExe install -username `"$username`" -password `"$password`" --autostart


Notice the backticks (`) to ensure the double quotes are escaped.

End Quote

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!