Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.Environment.MachineName exception

System.Environment.MachineName exception

Scheduled Pinned Locked Moved C#
workspacecsharpasp-netsecurityhelp
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 99738
    wrote on last edited by
    #1

    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 2000 desktop pc, not a networking share either), it's throwing the following exception. Request for the permission of type System.Security.Permissions.EnvironmentPermission, mscorlib, Version = 1.0.50000.0, Culture = neutral, publicKeyToken = blahblahblah failed. I have no idea what is causing this. I tried messing around with the .Net Configuration. Figured mscorlib didn't have permission rights. also......... I can't get any computer information in general. Trying to do some WMI core queries as well from code and getting a "Security Error" Exception. Below is the code that gets the disk size. public string GetsDiskSize(){ ManagementClass cimobject; ManagementObjectCollection moc; cimobject = new ManagementClass("Win32_DiskDrive"); moc = cimobject.GetInstances(); try { // BIOS INFO foreach(ManagementObject mo in moc){ this.m_sDiskSize = GetSystemValue("Size",mo); mo.Dispose(); break; } } catch(Exception ex){ System.Windows.Forms.MessageBox.Show("GetsDiskSize " + ex.Message); cimobject.Dispose(); moc.Dispose(); return ex.Message; } cimobject.Dispose(); moc.Dispose(); return this.m_sDiskSize; } Thx for your time, Paul

    J H 2 Replies Last reply
    0
    • U User 99738

      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 2000 desktop pc, not a networking share either), it's throwing the following exception. Request for the permission of type System.Security.Permissions.EnvironmentPermission, mscorlib, Version = 1.0.50000.0, Culture = neutral, publicKeyToken = blahblahblah failed. I have no idea what is causing this. I tried messing around with the .Net Configuration. Figured mscorlib didn't have permission rights. also......... I can't get any computer information in general. Trying to do some WMI core queries as well from code and getting a "Security Error" Exception. Below is the code that gets the disk size. public string GetsDiskSize(){ ManagementClass cimobject; ManagementObjectCollection moc; cimobject = new ManagementClass("Win32_DiskDrive"); moc = cimobject.GetInstances(); try { // BIOS INFO foreach(ManagementObject mo in moc){ this.m_sDiskSize = GetSystemValue("Size",mo); mo.Dispose(); break; } } catch(Exception ex){ System.Windows.Forms.MessageBox.Show("GetsDiskSize " + ex.Message); cimobject.Dispose(); moc.Dispose(); return ex.Message; } cimobject.Dispose(); moc.Dispose(); return this.m_sDiskSize; } Thx for your time, Paul

      J Offline
      J Offline
      Jeff Varszegi
      wrote on last edited by
      #2

      What are the permissions of the person running the program (your tester) on the machine?

      U 1 Reply Last reply
      0
      • J Jeff Varszegi

        What are the permissions of the person running the program (your tester) on the machine?

        U Offline
        U Offline
        User 99738
        wrote on last edited by
        #3

        User is logged in as an admin. Not sure what you mean by permission?

        J 1 Reply Last reply
        0
        • U User 99738

          User is logged in as an admin. Not sure what you mean by permission?

          J Offline
          J Offline
          Jeff Varszegi
          wrote on last edited by
          #4

          That's what I meant. So did you use the configuration utility to check the permissions of your program's DLL? That's probably the one that doesn't have rights, not mscorlib.

          U 1 Reply Last reply
          0
          • J Jeff Varszegi

            That's what I meant. So did you use the configuration utility to check the permissions of your program's DLL? That's probably the one that doesn't have rights, not mscorlib.

            U Offline
            U Offline
            User 99738
            wrote on last edited by
            #5

            Since I have limited time with my client, it would be best if I could simulate this error on my local machine. Can you think of any ways I can give this app, assemblies, groups less rigths, ty

            J 1 Reply Last reply
            0
            • U User 99738

              Since I have limited time with my client, it would be best if I could simulate this error on my local machine. Can you think of any ways I can give this app, assemblies, groups less rigths, ty

              J Offline
              J Offline
              Jeff Varszegi
              wrote on last edited by
              #6

              I have to leave work in just a couple of minutes, but if I don't see an answer posted for you later, I'll try it from home. So is your assembly signed, and if so, how?

              U 1 Reply Last reply
              0
              • U User 99738

                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 2000 desktop pc, not a networking share either), it's throwing the following exception. Request for the permission of type System.Security.Permissions.EnvironmentPermission, mscorlib, Version = 1.0.50000.0, Culture = neutral, publicKeyToken = blahblahblah failed. I have no idea what is causing this. I tried messing around with the .Net Configuration. Figured mscorlib didn't have permission rights. also......... I can't get any computer information in general. Trying to do some WMI core queries as well from code and getting a "Security Error" Exception. Below is the code that gets the disk size. public string GetsDiskSize(){ ManagementClass cimobject; ManagementObjectCollection moc; cimobject = new ManagementClass("Win32_DiskDrive"); moc = cimobject.GetInstances(); try { // BIOS INFO foreach(ManagementObject mo in moc){ this.m_sDiskSize = GetSystemValue("Size",mo); mo.Dispose(); break; } } catch(Exception ex){ System.Windows.Forms.MessageBox.Show("GetsDiskSize " + ex.Message); cimobject.Dispose(); moc.Dispose(); return ex.Message; } cimobject.Dispose(); moc.Dispose(); return this.m_sDiskSize; } Thx for your time, Paul

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                Are they running this locally or across the network? If it's the latter case, you must create a code group that grants the application (by a myriad of evidence) so that it has the necessary permissions (or just take the cheap route and grant your code FullTrust). If you use third-party controls in your application, you're better off using site evidence (like the Url membership condition, using a URL like ftp://NETSERVER1/ShareName/AppDirectory/\*). Read Understanding .NET Code Access Security[^] for more information.

                Microsoft MVP, Visual C# My Articles

                U 1 Reply Last reply
                0
                • H Heath Stewart

                  Are they running this locally or across the network? If it's the latter case, you must create a code group that grants the application (by a myriad of evidence) so that it has the necessary permissions (or just take the cheap route and grant your code FullTrust). If you use third-party controls in your application, you're better off using site evidence (like the Url membership condition, using a URL like ftp://NETSERVER1/ShareName/AppDirectory/\*). Read Understanding .NET Code Access Security[^] for more information.

                  Microsoft MVP, Visual C# My Articles

                  U Offline
                  U Offline
                  User 99738
                  wrote on last edited by
                  #8

                  This is just running locally. If you know of anyway I could simulate this locally that would be helpful as well. thx Paul

                  U H 2 Replies Last reply
                  0
                  • U User 99738

                    This is just running locally. If you know of anyway I could simulate this locally that would be helpful as well. thx Paul

                    U Offline
                    U Offline
                    User 99738
                    wrote on last edited by
                    #9

                    Last message was a little vague, sorry This is just running locally (not over a network). Since I have limited time with my client was wonderiing if you know of anyway I could simulate this on my local machine and is there was a way to include a security policy with the executeable or deployment package.

                    1 Reply Last reply
                    0
                    • J Jeff Varszegi

                      I have to leave work in just a couple of minutes, but if I don't see an answer posted for you later, I'll try it from home. So is your assembly signed, and if so, how?

                      U Offline
                      U Offline
                      User 99738
                      wrote on last edited by
                      #10

                      Hi, I don't believe it is signed. If it is I didn't do it. :) thx, Paul

                      1 Reply Last reply
                      0
                      • U User 99738

                        This is just running locally. If you know of anyway I could simulate this locally that would be helpful as well. thx Paul

                        H Offline
                        H Offline
                        Heath Stewart
                        wrote on last edited by
                        #11

                        Create a local user on your machine with the same permissions as the test users (like perhaps they're just in the "Domain Users" group). Log in as that user and test it. If you want to debug your app, don't forget to move the source code to an accessible directory (or give that new user permissions to access your directories) and recompile so that the path to the PDB files is correct.

                        Microsoft MVP, Visual C# My Articles

                        U 1 Reply Last reply
                        0
                        • H Heath Stewart

                          Create a local user on your machine with the same permissions as the test users (like perhaps they're just in the "Domain Users" group). Log in as that user and test it. If you want to debug your app, don't forget to move the source code to an accessible directory (or give that new user permissions to access your directories) and recompile so that the path to the PDB files is correct.

                          Microsoft MVP, Visual C# My Articles

                          U Offline
                          U Offline
                          User 99738
                          wrote on last edited by
                          #12

                          I'm not sure what test users permissions are??? sorry, but I created a new user with guests rights. What could I possibly change? (Something .net relative perhaps, changing assembly trust, library trust, executable trust .......) Thanks, Paul

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups