Error Using WMI to Get List of Shared Folders on the Server

Discussion in 'ASP .Net' started by lecnac, Apr 21, 2006.

  1. lecnac

    lecnac Guest

    Here's some details:

    Server and workstation both in the same workgroup
    Logged into server as local Administrator
    Logged into workstation as a local user that is only in the Users group
    The local user on the workstation is also defined with same name and
    password on the server (and only in the Users group on the server)
    Server is Windows Server 2003 running IIS 6.0
    Workstation is Windows XP Professional
    ASP.NET 2.0 (C#) web site


    Web.config snippet
    <system.web>
    <authentication mode="Windows"/>
    <identity impersonate="true"/>
    </system.web>


    ..aspx.cs snippet (from Page_Load event)
    using (System.Management.ManagementClass exportedShares = new
    System.Management.ManagementClass("Win32_Share"))
    {
    System.Management.ManagementObjectCollection shares =
    exportedShares.GetInstances();

    foreach (System.Management.ManagementObject share in shares)
    {
    // Get shared folder information, for example
    Response.Write("Name: " + share["Name"].ToString());
    }
    }


    Open IE and navigate to the web site on the server (using
    http://servername/website). I get an access denied error. The exception is
    thrown on the line: System.Management.ManagementObjectCollection shares =
    exportedShares.GetInstances();. The exception details are:
    System.Management.ManagementException: Access denied



    What I'm trying to do is list all the shared folders on the server on a
    page. However, when I run this application from a different computer, I get
    the access denied error.

    ** How can I get a list of shared folders on the server no matter what
    computer is accessing the ASP.NET application?
    ** What do I need to do differently to get the above code and scenario to
    work?

    ** Is there a better way of doing this than WMI? If so, what?


    P.S., On the server, I tried give the local user full WMI permissions
    through Computer Management, and it didn't work (nothing changed; I still
    got the access denied error).
     
    lecnac, Apr 21, 2006
    #1
    1. Advertising

  2. this setup won't work. the web service is running with a secondary credital,
    so it can not access a network resource (one hop rule). you have three
    options

    1) set the web site to basic authenication
    2) switch to activce directory and kerberos.
    3) remove <identity impersonate="true"/> and give the app pool an account
    with network permissions.

    -- bruce (sqlwork.com)

    "lecnac" <> wrote in message
    news:%23gb5E%...
    > Here's some details:
    >
    > Server and workstation both in the same workgroup
    > Logged into server as local Administrator
    > Logged into workstation as a local user that is only in the Users group
    > The local user on the workstation is also defined with same name and
    > password on the server (and only in the Users group on the server)
    > Server is Windows Server 2003 running IIS 6.0
    > Workstation is Windows XP Professional
    > ASP.NET 2.0 (C#) web site
    >
    >
    > Web.config snippet
    > <system.web>
    > <authentication mode="Windows"/>
    > <identity impersonate="true"/>
    > </system.web>
    >
    >
    > .aspx.cs snippet (from Page_Load event)
    > using (System.Management.ManagementClass exportedShares = new
    > System.Management.ManagementClass("Win32_Share"))
    > {
    > System.Management.ManagementObjectCollection shares =
    > exportedShares.GetInstances();
    >
    > foreach (System.Management.ManagementObject share in shares)
    > {
    > // Get shared folder information, for example
    > Response.Write("Name: " + share["Name"].ToString());
    > }
    > }
    >
    >
    > Open IE and navigate to the web site on the server (using
    > http://servername/website). I get an access denied error. The exception
    > is
    > thrown on the line: System.Management.ManagementObjectCollection shares =
    > exportedShares.GetInstances();. The exception details are:
    > System.Management.ManagementException: Access denied
    >
    >
    >
    > What I'm trying to do is list all the shared folders on the server on a
    > page. However, when I run this application from a different computer, I
    > get
    > the access denied error.
    >
    > ** How can I get a list of shared folders on the server no matter what
    > computer is accessing the ASP.NET application?
    > ** What do I need to do differently to get the above code and scenario to
    > work?
    >
    > ** Is there a better way of doing this than WMI? If so, what?
    >
    >
    > P.S., On the server, I tried give the local user full WMI permissions
    > through Computer Management, and it didn't work (nothing changed; I still
    > got the access denied error).
    >
    >
    >
     
    bruce barker \(sqlwork.com\), Apr 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Baron
    Replies:
    3
    Views:
    5,886
    Scott Allen
    Apr 29, 2005
  2. lecnac
    Replies:
    0
    Views:
    446
    lecnac
    Apr 24, 2006
  3. lecnac
    Replies:
    0
    Views:
    475
    lecnac
    Apr 24, 2006
  4. lecnac
    Replies:
    1
    Views:
    3,784
    Jeff Dillon
    Apr 24, 2006
  5. Douglass Turner
    Replies:
    2
    Views:
    2,051
    Manfred Bartz
    Sep 4, 2003
Loading...

Share This Page