开发者

How can I get NT authority/system in C#?

开发者 https://www.devze.com 2023-02-15 04:28 出处:网络
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.WindowsIdentit

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消