Tag: windows identity

模拟在Powershell中使用WindowsIdentity抛出FileNotFoundException

我在PowerShell和C#中执行模拟遇到了一些奇怪的错误。 执行以下代码不会显示任何错误。 PSObject result = null; using (PowerShell powershell = PowerShell.Create()) { RunspaceConfiguration config = RunspaceConfiguration.Create(); powershell.Runspace = RunspaceFactory.CreateRunspace(config); powershell.Runspace.Open(); powershell.AddScript(String.Format(CmdletMap[PSVocab.OsBootTime], this.ComputerName)); result = powershell.Invoke().First(); powershell.Runspace.Close(); } return DateTime.Parse(result.ToString()); CmdletMap[PSVocab.OsBootTime]的PS脚本只是: $info = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer ; $info.ConvertToDateTime($info.LastBootUpTime) 上面的C#代码在本地工作正常。 但是,一旦我使用Windows模拟这样的块,就像这样: WindowsIdentity ImpersonatedIdentity = new WindowsIdentity(ImpersonateUserName); WindowsImpersonationContext impersonatedContext = ImpersonatedIdentity.Impersonate(); try { PSObject result = […]

仅使用域和用户名创建WindowsIdentity

我正在构建一个使用当前用户的WindowsIdentity获取用户信息的站点。 我从中得到的主要信息是ssid。 我为当前用户执行此操作,如下所示 IntPtr logonToken = WindowsIdentity.GetCurrent().Token; WindowsIdentity windowsId = new WindowsIdentity(logonToken); string ssid = windowsId.User.ToString(); 我现在需要做的是,并且失败了,就是获取域中存在的任意用户名的ssid。 我尝试了WindowsIdentity(字符串),但这给了我一个SecurityException 提供的名称不是正确形成的帐户名称。

如何从DOMAIN \ user格式的用户名创建WindowsIdentity / WindowsPrincipal

WindowsIdentity(string)构造函数要求用户username@domain.com格式。 但在我的情况下,我以旧DOMAIN\user格式从数据库中获取用户名(然后必须检查其Windows角色成员身份)。 从旧式用户名创建WindowsPrincipal的最佳方法是什么?

如何从ASP.NET页面获取当前登录的Windows帐户?

我有一个使用ASP.NET表单身份validation的ASP.NET 3.5应用程序。 我希望能够在页面中编辑数据时获取当前登录到计算机的Windows用户名(不登录到ASP.NET应用程序,但是登录到Windows)。 如果我使用Context.User.Identity.Name.Tostring() ,我会获得登录ASP.NET应用程序的用户名,但我需要Windows帐户名。 System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring() 此外,它仅在我从Visual Studio运行网站时有效,但在部署到IIS后,它返回NT AUTHORITY \ SYSTEM 。