[英]How to check PostgreSql is installed or not in windows machine using C#.net?
[英]C#.NET Getting User Name of machine using Windows Service
我很難獲得使用Windows服務登錄到計算機的用戶名。
當同時使用System.Environment.UserName或WindowsIdentity.GetCurrent()。UserName我得到NTAUTHORITY \\ SYSTEM但是當這個應用程序被推送時,我需要能夠映射到登錄到系統的人的UserID。 將使用的操作系統將是Windows XP。
任何幫助將非常感激。
嘗試這個:
var connectionOptions = new ConnectionOptions();
var scope = new System.Management.ManagementScope("\\\\localhost", connectionOptions);
var query = new System.Management.ObjectQuery("select * from Win32_ComputerSystem");
var searcher = new ManagementObjectSearcher(scope, query);
foreach (var row in searcher.Get())
{
Console.WriteLine(row["UserName"].ToString().ToLower());
}
僅對於XP,此建議應適用: 為每個進程,用戶或會話的非交互式用戶獲取Window Station?
OpenWindowStation
來獲取“winsta0”的句柄 GetUserObjectInformation
以找出誰擁有winsta0 但是,當您將應用程序升級到Vista,Windows 7或更高版本時,此方法將會中斷,其中服務在交互式登錄的不同會話中運行。 您需要調用終端服務API以獲取已登錄用戶的列表,並選擇“交互式”用戶。
Windows服務始終在服務“屬性/登錄”選項卡中提供的憑據下運行。 這與當前在其會話中登錄到Windows的人員/人員的憑據無關。
NTAUTHORITY \\ SYSTEM的值是正確的,因為您的服務在“本地系統帳戶”憑據下運行。
您無法在“當前登錄”用戶的帳戶下運行Windows服務 - 這不是Windows服務的用途。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.