473,434 Members | 1,820 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,434 software developers and data experts.

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

Sorry for the repost. I must have done something wrong when I tried to post
my reply (I can't seem to find it).

Anyway, I'd really appreciate any help that anyone could provide. My issue
is quickly becoming more and more urgent.

I've tried the code below using the server's local Administrator user name
and password. This gets me past the Access denied error but gives me a User
credentials cannot be used for local connections error.

ManagementScope ms;
ManagementClass mc;

ms = new ManagementScope();
ms.Options.Username = "username";
ms.Options.Password = "password";
ms.Options.Authentication = Authentication.PacketPrivacy;
ms.Path = new ManagementPath("//server/root/CIMv2");

mc = new ManagementClass(ms, new ManagementPath("Win32_Share"), null);
Maybe another thought... Should I not use WMI to try to get a list of
shared folders on the server? Should I use something else? If so, what?

"lecnac" <no****@company.com> wrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
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).



Apr 24 '06 #1
1 3674
You should not specify any credentials for "local" connections, the current
users security token will be used as access token. Note that you should not
specify the local server name in the management path, your code should look
like this:
ManagementClass mc;
ms.Path = new ManagementPath("./root/CIMv2");
using(mc = new ManagementClass(ms, new ManagementPath("Win32_Share"),
null))
{
....
}

Willy.
"lecnac" <no****@company.com> wrote in message
news:uE****************@TK2MSFTNGP04.phx.gbl...
| Sorry for the repost. I must have done something wrong when I tried to
post
| my reply (I can't seem to find it).
|
| Anyway, I'd really appreciate any help that anyone could provide. My
issue
| is quickly becoming more and more urgent.
|
|
|
| I've tried the code below using the server's local Administrator user name
| and password. This gets me past the Access denied error but gives me a
User
| credentials cannot be used for local connections error.
|
| ManagementScope ms;
| ManagementClass mc;
|
| ms = new ManagementScope();
| ms.Options.Username = "username";
| ms.Options.Password = "password";
| ms.Options.Authentication = Authentication.PacketPrivacy;
| ms.Path = new ManagementPath("//server/root/CIMv2");
|
| mc = new ManagementClass(ms, new ManagementPath("Win32_Share"), null);
|
|
| Maybe another thought... Should I not use WMI to try to get a list of
| shared folders on the server? Should I use something else? If so, what?
|
|
|
|
| > "lecnac" <no****@company.com> wrote in message
| > news:%2******************@TK2MSFTNGP02.phx.gbl...
| > > 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).
| > >
| > >
| > >
| >
| >
|
|
|
Apr 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Morten Gulbrandsen | last post by:
mysql> USE company; Database changed mysql> mysql> DROP TABLE IF EXISTS EMPLOYEE; -------------- DROP TABLE IF EXISTS EMPLOYEE -------------- Query OK, 0 rows affected (0.00 sec)
1
by: Miller | last post by:
Hi everybody! These messages have been found in the System log of the Event Viewer application. These error messages have been generated after each logon attempt. Although dial-in client have been...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows...
1
by: Harley | last post by:
i have an application that uses forms security to restrict access to a specific folder. now i need to secure another folder, in the same root, but redirect those users to another login. imagine,...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
2
by: Kevin R. | last post by:
I have been ignoring this problem for a few weeks now, but it's becoming a bit annoying not to mention unproductive. Here it goes: I compile my project with no errors. Then after I debug/run it,...
1
by: lecnac | last post by:
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...
1
by: lecnac | last post by:
Sorry for the repost. I must have done something wrong when I tried to post my reply (I can't seem to find it). Anyway, I'd really appreciate any help that anyone could provide. My issue is...
1
by: JordanRieger | last post by:
Here is a nasty issue that has been giving me grief for the last couple days. This requires good knowledge of IIS, MSXML, and Windows/NTFS permissions. We have an existing ASP (VBScript) app...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.