Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send administrative commands to my C# Windows Service using own PowerShell CmdLets

I have a C# Windows application which runs a service. I would like to leverage PowerShell in order to offer a command line management interface for administering my running service.

From my point of view, I am trying to offer the same administrative interface a la Exchange 2007.

Do you have any suggestion or sample code on how to start/design the management cmdlets in order "connect" to the running service to query or send administrative commands?

How can I access service's internal runtime state from powershell command line? For example I would like to implement a cmdlet called Get-ConnectionsInfo to find out how many outbound connections my Windows service is using when the cmdlet is executed.

A practical example or web link to an example would be more than welcomed.

Thanks, Robert

like image 713
Robert Mircea Avatar asked Oct 25 '08 22:10

Robert Mircea


People also ask

How do I Run a command with administrator privileges?

Press Windows+R to open the “Run” box. Type “cmd” into the box and then press Ctrl+Shift+Enter to run the command as an administrator.

What is the command for admin in cmd?

Using the run command To do so, open a run-box, write cmd , and press Control + Shift + Enter to open the command prompt as an administrator.

What does * * mean in cmd?

In this case, we used the * wildcard to mean "all files in the current directory". This command prints the line containing the given string, and if there's more than one file in the list, the name of the file where it was found.

How do I get Command Prompt in C?

For example, to move into C:\Windows>, type cd\windows at the prompt.


2 Answers

A solution would be for your Windows Service to expose an administrative interface through WCF. Your PowerShell commands would use this WCF service to pull out information and make the Windows Service perform actions.

like image 167
Magnus Lindhe Avatar answered Oct 12 '22 08:10

Magnus Lindhe


The key here is to start by writting an API that you can access from .Net, then you can easily wrap the calls to this API into a DLL that exposes classes that are PowerShell cmdlets. If you want someone to be able to administer your service remotely then I think probably the best thing is to create either a webservice or WCF Service that does this and then you can wrap that in PowerShell. If you have a look on codeplex you will find some examples of administer remote web based services like GoGrid and SQL Data Services that will give you some sample code to get you started.

like image 31
Darren Gosbell Avatar answered Oct 12 '22 08:10

Darren Gosbell