我有一个 WPF 应用程序需要获取用户的 Windows 用户名。我正在使用以下代码行:
MessageBox.Show("Your username is:\n" + WindowsIdentity.GetCurrent().Name);
这在我的计算机和我们其他开发人员的计算机上运行良好,但对其他人来说,它会崩溃。我假设这是一个权限问题。这是错误:
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: notesformultipleproperties.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 51cb04a1
Problem Signature 04: PresentationFramework
Problem Signature 05: 4.0.0.0
Problem Signature 06: 504dc7da
Problem Signature 07: 7b4d
Problem Signature 08: 0
Problem Signature 09: System.Windows.Markup.XamlParse
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
无论用户拥有什么权限,我都可以允许这行代码运行吗?