WMI Enumeration of remote shares

N

Nick

Hi there,

I'm having great difficulties enumerating the shares on remote machines
on my network using WMI. On one system i get RPC Server is not running
(which it is) and on another I get access denied even though I'm passing it
the correct login credentials.

I've also tried the ConnectionTester in the following article,

http://www.devcity.net/Articles/144/6/article.aspx

This produces exactly the same results. Any idea what's going on? My
query is as follows,

SELECT * FROM Win32_Share

This works locally but not on a remote system. Maybe WMI isn't the way
to do this? Any help would be greatly appreciated.

Nick.
 
J

Jialiang Ge [MSFT]

Hello Nick,

Thanks for using Microsoft Newsgroup Service. My name is Jialiang and it is
my pleasure to work with you on this issue.

Analysis:
=============

I have reviewed the article you mentioned and tested the sample. Everything
worked correctly in my environment (including both local and remote call).

Also, according to your requirements, I made a few adjustments to the
original sample to test Win32_Share, and it worked well. Here is the
original sample and my adjusted version:

1. The original sample:

moc = WmiConn.ExecWmiQuery("Select * From Win32_Product")
If Not moc Is Nothing Then
Console.WriteLine(" - Programs installed on {0} -",
WmiConn.ServerName)
Dim mo As System.Management.ManagementObject
For Each mo In moc
Console.WriteLine(mo.GetPropertyValue("Caption"))
Next
Console.WriteLine(" - End of list -")
moc = Nothing
mo = Nothing
End If

2. The adjusted one I tested:

moc = WmiConn.ExecWmiQuery("Select * From Win32_Share")
If Not moc Is Nothing Then
Console.WriteLine(" - Shares -")
Dim mo As System.Management.ManagementObject
For Each mo In moc
Console.WriteLine(" {0} ", mo.GetPropertyValue("Name"))
Next
Console.WriteLine(" - End of list -")
moc = Nothing
mo = Nothing
End If

The above code worked well. So, the code itself should be OK.

Suggestion:
=============

Based on my further research, I suspect that the permissions may not be
correctly assigned to access WMI. I would like to suggest that we perform
the following steps:

Suggestion 1.

1. Log in the remote computer.
2. Click Control Panel -> Administrative Tool -> Computer Management ->
Services and Applications -> WMI control
3. Right click the "WMI control", and then select Properties. The
Properties dialog will pop up.
4. Select the tab "Security". (In the following steps, I will take
Root\CIMV2 as an example. You may adjust your steps accordingly.)
5. Select Root\CIMV2 and then click "Security" and assign "Remote Enable"
and "Read Security" to "Everyone" or the user you used to access WMI
control.
6. Click OK several times until the WMI control properties dialog close.
7. Select Services and Applications -> Services.
8. Right click Windows Management Instrumentation and select Restart.
9. After the WMI service restarts, run the sample again and see how it
works now.

Suggestion 2.
We can impersonate the current thread as an admin of the remote computer.
For an example of impersonation, please refer to this KB article:
http://support.microsoft.com/kb/306158.

Information Needed:
========================

If the issue still persists after performing the above steps, please help
collect the following information for further investigation:

1. If possible, please test the sample on another cleanly installed
computer and check how it works. This test will help us narrow down whether
it is a computer configuration problem.

2. If possible, please send me your source code and I will perform more
tests.

Note: The code will only be used for troubleshooting purposes and will be
deleted after we resolve this case.

Thanks for your time and efforts!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Nick

Hi Jialiang,

Thanks a million for your time and lengthy reply, it has been most
information.

By the looks of things unfortunately I think this is going to take me down
the wrong route, I do not want to need to enable WMI access on the remote
system for this to be able to work so I can only presume that I have chose
the wrong method.

The code is for an explorer style folder browser, enabling selection of
local folders as well as network shares, so having to setup WMI on the
remote shares will just create unnecessary messing about.

I think I had best use the NetShareEnum API instead.

Thanks a million for your time and help!

Nick.

"Jialiang Ge [MSFT]" said:
Hello Nick,

Thanks for using Microsoft Newsgroup Service. My name is Jialiang and it
is
my pleasure to work with you on this issue.

Analysis:
=============

I have reviewed the article you mentioned and tested the sample.
Everything
worked correctly in my environment (including both local and remote call).

Also, according to your requirements, I made a few adjustments to the
original sample to test Win32_Share, and it worked well. Here is the
original sample and my adjusted version:

1. The original sample:

moc = WmiConn.ExecWmiQuery("Select * From Win32_Product")
If Not moc Is Nothing Then
Console.WriteLine(" - Programs installed on {0} -",
WmiConn.ServerName)
Dim mo As System.Management.ManagementObject
For Each mo In moc
Console.WriteLine(mo.GetPropertyValue("Caption"))
Next
Console.WriteLine(" - End of list -")
moc = Nothing
mo = Nothing
End If

2. The adjusted one I tested:

moc = WmiConn.ExecWmiQuery("Select * From Win32_Share")
If Not moc Is Nothing Then
Console.WriteLine(" - Shares -")
Dim mo As System.Management.ManagementObject
For Each mo In moc
Console.WriteLine(" {0} ", mo.GetPropertyValue("Name"))
Next
Console.WriteLine(" - End of list -")
moc = Nothing
mo = Nothing
End If

The above code worked well. So, the code itself should be OK.

Suggestion:
=============

Based on my further research, I suspect that the permissions may not be
correctly assigned to access WMI. I would like to suggest that we perform
the following steps:

Suggestion 1.

1. Log in the remote computer.
2. Click Control Panel -> Administrative Tool -> Computer Management ->
Services and Applications -> WMI control
3. Right click the "WMI control", and then select Properties. The
Properties dialog will pop up.
4. Select the tab "Security". (In the following steps, I will take
Root\CIMV2 as an example. You may adjust your steps accordingly.)
5. Select Root\CIMV2 and then click "Security" and assign "Remote Enable"
and "Read Security" to "Everyone" or the user you used to access WMI
control.
6. Click OK several times until the WMI control properties dialog close.
7. Select Services and Applications -> Services.
8. Right click Windows Management Instrumentation and select Restart.
9. After the WMI service restarts, run the sample again and see how it
works now.

Suggestion 2.
We can impersonate the current thread as an admin of the remote computer.
For an example of impersonation, please refer to this KB article:
http://support.microsoft.com/kb/306158.

Information Needed:
========================

If the issue still persists after performing the above steps, please help
collect the following information for further investigation:

1. If possible, please test the sample on another cleanly installed
computer and check how it works. This test will help us narrow down
whether
it is a computer configuration problem.

2. If possible, please send me your source code and I will perform more
tests.

Note: The code will only be used for troubleshooting purposes and will be
deleted after we resolve this case.

Thanks for your time and efforts!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working
with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
Joined
Dec 27, 2008
Messages
1
Reaction score
0
Hi
I've also try to use "Win32_Share" WMI but it doesn't work like I want. Instead of it I wanted to use NetShareEnum (API) function. It works great but when remote computer does not response it waits 5 seconds (timeout). I want to set timeout value to 2 seconds. Anybody knows if it's possible ?
I've found that ConnectionOptions (.Net class) probably have this functionality but calling ManagementObjectCollection.Get() gives me "acces denied" exception (becouse of WMI security).
My point is to make application which can quickly view LAN shares so setting security is impossible.
Any help would be appreciated :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top