I installed an SQL server using the login NT authority/system and now I need in C# to retrieve that valu开发者_Go百科e as a string. Any ideas how I can do that?
System.Security.Principal.WindowsIdentity.GetCurrent().Name //WorkstationId
Environment.MachineName.ToString(); //UserId
Is that what you were looking for?
Sorry, apart from my little joke :) for accessing service information, you would use ServiceController class but unfortunately that will not work since that information is not exposed.
Your choice is to read the registry and open the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SQLAgent$SQLEXPRESS2008
or any other sql service you have and then read the ObjectName
entry.
For reading registry, have a look here.
精彩评论