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. .NET (Core and Framework)
  4. System.Environment.MachineName Exception

System.Environment.MachineName Exception

Scheduled Pinned Locked Moved .NET (Core and Framework)
workspacecsharpasp-netsecurityhelp
3 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; }

    A 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; }

      A Offline
      A Offline
      Aryadip
      wrote on last edited by
      #2

      Hi, Try using [ Assembly:EnvironmentPermission(SecurityAction.Assert)] attribute for your class... regards, Aryadip. Cheers !! and have a Funky day !!

      T 1 Reply Last reply
      0
      • A Aryadip

        Hi, Try using [ Assembly:EnvironmentPermission(SecurityAction.Assert)] attribute for your class... regards, Aryadip. Cheers !! and have a Funky day !!

        T Offline
        T Offline
        TigerNinja_
        wrote on last edited by
        #3

        Aryadip wrote: Try using [ Assembly:EnvironmentPermission(SecurityAction.Assert)] MS docs caution the use of Assert. I think MS suggests setting up permissions via the mscorcfg snap-in instead of bypassing security. Please correct me if I am wrong. Thanks.

        R.Bischoff

        Denn Gott hat die Menschen so sehr geliebt, daß er seinen einzigen Sohn für sie hergab. Jeder, der an ihn glaubt, wird nicht verlorengehen, sondern das ewige Leben haben

        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