By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Environment.Machinename secutiry exception

P: n/a
I am very new to the language so please pardon my ignorance.

I am writing a small console application to gather hardware inventory
information. When I run the application locally all works well. It
gathers the needed information and writes that info to a remote SQL
server.

If I put the file in the scripts folder on our AD domain controller (so
that I can use it with login scripts) it fails to run. It also fails
when I run it from any network share. I am a domain admin and I have
admin rights on each of the PC's I've tried to run it on as well as
Full Control of the share and NTFS permissions. After debugging I find
the exception was thrown on this line of code.

myMachineName = Environment.MachineName.ToLower();

The exception is this:

System.Security.SecurityException was unhandled
Message="Request for the permission of type
'System.Security.Permissions.EnvironmentPermission , mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Obj ect demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Environment.get_MachineName()
at ITInventory.Program.Main(String[] args)

Any help you can offer would be greatly appreciated.

Jan 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
tmoffett,

The problem is the result of the location that the assembly is being
loaded from. By default, assemblies not loaded from the local machine run
with a reduced permission set.

In order to get around this, you would have to go to the .NET
configuration wizard and create a permission set which would grant you the
Environment permission for your assembly (best indicated with a strong name,
or at worst, a hash).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"tmoffett" <tm******@solarc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am very new to the language so please pardon my ignorance.

I am writing a small console application to gather hardware inventory
information. When I run the application locally all works well. It
gathers the needed information and writes that info to a remote SQL
server.

If I put the file in the scripts folder on our AD domain controller (so
that I can use it with login scripts) it fails to run. It also fails
when I run it from any network share. I am a domain admin and I have
admin rights on each of the PC's I've tried to run it on as well as
Full Control of the share and NTFS permissions. After debugging I find
the exception was thrown on this line of code.

myMachineName = Environment.MachineName.ToLower();

The exception is this:

System.Security.SecurityException was unhandled
Message="Request for the permission of type
'System.Security.Permissions.EnvironmentPermission , mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Obj ect demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Environment.get_MachineName()
at ITInventory.Program.Main(String[] args)

Any help you can offer would be greatly appreciated.

Jan 10 '06 #2

P: n/a
"tmoffett" <tm******@solarc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
If I put the file in the scripts folder on our AD domain controller (so
that I can use it with login scripts) it fails to run. It also fails
when I run it from any network share.


You may need to adjust your Local Intranet zone security to Full Trust. You
can find this in the .NET Framework x.x Configuration utility, which should
be in your Administrative Tools folder on the computer of interest.

-- Alan

Jan 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.