HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Can I check the services currently running through SSMS?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canthessmsservicesrunningthroughcheckcurrently

Problem

I want to check which services has started and which has not by running a script/query on SSMS.

Solution

You can do this with CLR or PowerShell. From PowerShell you can use things like Get-Process or Get-Service for some of this information. With C# you could look at this answer but I don't know of any ready-made code for SQLCLR. Note that with PowerShell you'll need to run the command in the context of the remote computer, e.g.

Invoke-Command -ComputerName RemoteComputerName { Get-Service }

// or if your version of PS is modern enough:

Get-Service -ComputerName RemoteComputerName


You can also use xp_cmdshell to call things like tasklist, net start, wmic or 3rd-party things like Process Explorer (though I haven't tried to invoke that via command line):

EXEC master..xp_cmdshell 'tasklist';
EXEC master..xp_cmdshell 'net start';
EXEC master..xp_cmdshell 'wmic service get';


The latter has much more valuable information, but the output is absolutely horrible to work with.

Of course this all assumes that you and/or the SQL Server service account has sufficient privileges to call these functions.

(Adopted from my answer to a similar question on SO.)

Code Snippets

EXEC master..xp_cmdshell 'tasklist';
EXEC master..xp_cmdshell 'net start';
EXEC master..xp_cmdshell 'wmic service get';

Context

StackExchange Database Administrators Q#20806, answer score: 6

Revisions (0)

No revisions yet.