473,241 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 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 4897
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: duncsss | last post by:
Hi, I'm using the following code to get the Machine name in an app System.Environment.MachineName On most computers this works fine but on one of our testers computers (machine is a windows...
2
by: Joscarfas | last post by:
Hello to all, As you can read the subject of this post, this is exactly what I'm trying to do. I need to disable some controls in my form base on secutiry level in MS Access; I've been...
0
by: Paul Duncan | last post by:
Hi, I'm using the following code to get the Machine name in an app System.Environment.MachineName On most computers this works fine but on one of our testers computers (machine is a windows...
1
by: cloudx | last post by:
Hi there, In VB we call API to get a computer name, is MachineName the replacement in C#? Thanks!
2
by: Ely | last post by:
When I call the Environment.Machinename to try to get the local machines name, I get a "Object reference not set to an instance of an object" error. This same code works fine on my local machine,...
10
by: Edward | last post by:
I've just taken over maintaining a system from a colleague who has left. I find the following line in her code: Dim params(2) As SqlClient.SqlParameter params(0) = New...
2
by: XxLicherxX | last post by:
Hello, I tried posting this in a different VB.net newsgroup, but never got a response. Please let me know if there is a better group to post this in. Thanks. For some reason I cannot look at...
4
by: samueltilden | last post by:
How can I get the machine name on which the C# code is compiled and then reference that value within the executable code, as in a "Help -- Preferably embed the answer in a .dll. Worst case would...
3
by: J | last post by:
The following code finds the existing file when run in the development environment, but not when deployed (in IIS on the same box). Why? String myFile = @"J:\My_jpgs\The Den\jvc90-03.JPG";...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.