471,354 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Environment.Machinename secutiry exception

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
2 4773
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
"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.

Similar topics

reply views Thread by Paul Duncan | last post: by
1 post views Thread by cloudx | last post: by
2 posts views Thread by Ely | last post: by
4 posts views Thread by samueltilden | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.