System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
When you run an application that calls the SystemInformation.UserName property of the System.Windows.Forms assembly, and the application has Local Intranet zone
permissions, you receive the following exception:
An
unhandled exception of type 'System.Security.SecurityException' occurred in
mscorlib.dll.
Additional information: Request for the permission of
type System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
The System.Security.Permissions.EnvironmentPermission class in Mscorlib.dll controls the access to the user environment
variables. SystemInformation.UserName in the application requests the permission from the EnvironmentPermission class to access the UserName environment variable. However, in the Local Intranet zone, System.Windows.Forms does not have permissions to access the Windows user name, and
the request is not served by Mscorlib.dll. Therefore, a security exception is
raised when you run the application.
In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, start a new console
application by using Microsoft Visual Basic or Microsoft Visual C#.
In Solution Explorer, right-click
ConsoleApplication1, and then click Add
Reference.
On the .NET tab, click to select
System.Windows.Forms.dll, and then click
Select.
In the code editor, add the following statement as the
first line of code:
Visual Basic .NET or Visual Basic 2005 Code
Imports System.Windows.Forms
Visual C# .NET Code
using System.Windows.Forms;
Add the following code to the Main procedure:
Visual Basic .NET or Visual Basic 2005 Code
'display the UserName that is currently logged
Console.WriteLine(SystemInformation.UserName)
Visual C# .NET Code
//display the UserName that is currently logged
Console.WriteLine(SystemInformation.UserName);
Click Start, point to Microsoft
Visual Studio .NET, point to Visual Studio .NET
Tools, and then click Visual Studio .NET Command
Prompt.
Note In Visual Studio 2005, click Start, point to Microsoft
Visual Studio 2005, point to Visual Studio 2005
Tools, and then click Visual Studio 2005 Command
Prompt.
Run the following statement at the command prompt:
sn -k mykey.snk
In the ConsoleApplication1 Solution
Explorer, double-click AssemblyInfo.vb.
Note Replace local_file_path with the path
of Mykey.snk on your local computer.
On the Build menu, click Build
Solution.
Click Start, point to
Administrative Tools, and then click Microsoft .NET
Framework Configuration.
In the .NET Framework Configuration window, expand
Runtime Security Policy, and then expand
Machine.
In the Machine window, expand Code Groups,
and then expand All_Code.
Right-click LocalIntranet_Zone, and then
click Properties.
On the General tab, click to select
This policy level will only have the permissions from the permission
set associated with this code group check box.
Click the Membership Condition tab. Under
Choose the condition type for this code group, click to select
Strong Name.
Click Import, locate the
ConsoleApplication1.exe file, and then click to select the file. Click
Open.
Click OK to apply the assigned
properties.
In ConsoleApplication1, click
Start on the Debug menu.
You receive
the exception mentioned in the "Symptoms" section of this article.