How can I get the Service Account name for the SQL Agent service for a particular SQL Server (SQL 2005). Is it possible to get using SQL statements or WMI ?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
Since SQL Server runs as a windows service you can use wmic to query the start name.
For me this outputs the following (since I've got multiple instances thoes are included as well)
You can add
/NODE
to query remote computers. As with any WMI query you will need sufficient privileges in order for this to workOr the same query using Powershell's Get-WmiObject (Supports remote/multiple computersnames):
Sample Output:
As Aaron Bertrand pointed out, you can use the undocumented
xp_regread
in SQL Server 2005 and SQL Server 2008, but there is a better way, starting with SQL Server 2008R2 SP1.From the article How to identify the SQL Server Service Account in T-SQL, you can use
sys.dm_server_services
like this:For a default instance:
For a named instance, you'll need the second argument to be:
Now, it may not work because you may not have access to xp_regread, and the location of this property may change from version to version (I only tested 2008, 2008 R2 and Denali - I don't have a 2005 instance handy to check).
In any case you are probably better off asking the DBA (as suggested in a comment) or, if you have access to the physical machine, just checking the service account in the Control Panel.
I know this is an old thread but here is my solution. This has been tested against SQL Server 2000, 2005, 2008, 2008 R2, 2012, 2014 and 2016.
You can use the sc.exe.
To find SQL instances services:
To get configuration: