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

Finding a share's directory spec

Hi all,

I'm writing a service that needs to discover the full directory path for a
given locally based share at startup. IOW, I need to have the service
running on someserver to take \\someserver\someshare and give me
c:\somedir\somedir\shareddir.

I'm not quite sure where to start reading about how to do this. Could
someone give me a push in the right direction, please?

Thank you.

ne.
Apr 27 '07 #1
17 1823
On Apr 27, 10:39 am, "NetworkElf" <Network...@nospam.nospamwrote:
Hi all,

I'm writing a service that needs to discover the full directory path for a
given locally based share at startup. IOW, I need to have the service
running on someserver to take \\someserver\someshare and give me
c:\somedir\somedir\shareddir.

I'm not quite sure where to start reading about how to do this. Could
someone give me a push in the right direction, please?

Thank you.

ne.
A real kludgy way to do it would be to fire off a Command Prompt
Window process, feed it the "NET SHARE <sharename>" command and parse
the output for the path.

Apr 27 '07 #2

<za***@construction-imaging.comwrote in message
news:11**********************@r35g2000prh.googlegr oups.com...
On Apr 27, 10:39 am, "NetworkElf" <Network...@nospam.nospamwrote:
>I'm writing a service that needs to discover the full directory path for
a
given locally based share at startup. IOW, I need to have the service
running on someserver to take \\someserver\someshare and give me
c:\somedir\somedir\shareddir.

I'm not quite sure where to start reading about how to do this. Could
someone give me a push in the right direction, please?

A real kludgy way to do it would be to fire off a Command Prompt
Window process, feed it the "NET SHARE <sharename>" command and parse
the output for the path.
I had considered that, but decided I'd rather avoid that route if I can. I'm
certain the functionality is within vb.net, I've just not been able to find
what I need yet.

Thank you.
Apr 27 '07 #3
NetworkElf wrote:
>
I had considered that, but decided I'd rather avoid that route if I can. I'm
certain the functionality is within vb.net, I've just not been able to find
what I need yet.
There is a wmi class win32_ShareToDirectory.

Found it with scriptomatic for wsh/vbs.

This is my untested try to convert to vb.net

' The wmi Win32_ShareToDirectory class allows you to get that information
' You need to add a reference to System.Management for this example.

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher(_
"Select * from Win32_ShareToDirectory")

moReturn = moSearch.Get

For Each mo In moReturn
Debug.WriteLine(mo("Share"))
Debug.Indent()
Debug.WriteLine(mo("SharedElement"))
Debug.Unindent()
Next
HTH

--
Greetings
Matthias
Apr 27 '07 #4

"Matthias Tacke" <Ma******@Tacke.dewrote in message
news:f0**********@news.albasani.net...
NetworkElf wrote:
>>
I had considered that, but decided I'd rather avoid that route if I can.
I'm certain the functionality is within vb.net, I've just not been able
to find what I need yet.
There is a wmi class win32_ShareToDirectory.
Thank you. It seems as if I were on the correct track earlier, but I didn't
pursue it far enough. This is very helpful.

At the moment, I'm suffering from post-lunch malaise after being attacked by
an Indian buffet. I'll take a shot at it next week and post my results.
Apr 27 '07 #5
Hi,

Yes, you may query this information through WMI Win32_Share class. More
specific, Win32_Share.Path property contains the local path to this share.
The code snippet works well on my side:

Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject
For Each objShare In objClass.GetInstances()
Console.WriteLine(String.Format("{0} -{1}",
objShare.Properties("Name").Value, objShare.Properties("Path").Value))
Next objShare

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 30 '07 #6

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:HL**************@TK2MSFTNGHUB02.phx.gbl...
Hi,

Yes, you may query this information through WMI Win32_Share class. More
specific, Win32_Share.Path property contains the local path to this share.
The code snippet works well on my side:

Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject
For Each objShare In objClass.GetInstances()
Console.WriteLine(String.Format("{0} -{1}",
objShare.Properties("Name").Value, objShare.Properties("Path").Value))
Next objShare
Thank you, Jeffrey.
Apr 30 '07 #7
Ok, if you still need any help or have any concern, please feel free to
tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
May 1 '07 #8
----- Original Message -----
From: ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Monday, April 30, 2007 10:06 PM
Subject: Re: Finding a share's directory spec

Ok, if you still need any help or have any concern, please feel free to
tell me, thanks.
You shouldn't have asked... :D

I used the following code:

Dim VPHOMEpath As String = ""
Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject

For Each objShare In objClass.GetInstances()

If objShare.Properties("Name").Value = "VPHOME" Then

VPHOMEpath = objShare.Properties("Path").Value

End If

Next objShare

Now, if I use it in a standard vb.net app and run it, VPHOMEpath gets the
proper path returned and everything runs fine. If I take the exact same code
and paste it into another project that's running as a service, the wheels
fly off the wagon. Apparently, objShare.Properties("Path").Value returns a
null value when running as a service.

Now, the only difference I can think of is that the standard app is running
under my credentials and the service is running on the local service
account. I would prefer not to run it under a userID if I can avoid it...

Does anyone have any thoughts?

Thank you.
May 2 '07 #9

"NetworkElf" <Ne********@nospam.nospamwrote in message
news:eO**************@TK2MSFTNGP05.phx.gbl...
>
Now, the only difference I can think of is that the standard app is
running under my credentials and the service is running on the local
service account. I would prefer not to run it under a userID if I can
avoid it...
This was the problem. When I switched it from running under NT
AUTHORITY\LocalService to Log on as: Local System account, the problem went
away. I'm still not totally clear as to why.

Any insights would be welcome.

Thanks,

ne.
May 3 '07 #10
Hi,

Sorry for the late response, I am out of office these 2 days.

Ok, I will perform research on this problem and get back to you ASAP.
Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 7 '07 #11
Hi,

By writting a sample in Windows Service, I can reproduce your problem. It
seems that the code works well under LocalService account while failed to
get "Path" property. I am suspecting it is a security problem. I will spend
more time to dig into it. Thanks for your patient.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 7 '07 #12
Hi,

Sorry for letting you wait.

I am currently contacting the WMI team for collaborating troubleshoot this
issue now, and I finally got response from a developer from WMI team. I
have passed the sample Windows Service project to them for local reproduce
and my OS version information. Once we got any findings, I will feedback
here ASAP. Thanks for your patient.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 9 '07 #13
Hi,

Sorry for letting you wait.

Further discussion with the WMI team shows that LocalService account does
not have permission to access the path for shares. You may view the DACL on
shared folders in Computer Management->System Tools -Shared Folders ->
Shares. You may right click any share folder in right panel and view the
"Security" tabpage.

As you can see, LocalSystem and Administrators will be granted full control
access to them, while LocalService does not have an ACE entry, which means
the LocalService will have no access to them.

Currently, due to the constraint DACL setting on the shared folder, we have
to run the service under Administrators account or LocalSystem account.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 10 '07 #14

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:u1**************@TK2MSFTNGHUB02.phx.gbl...
Hi,

Sorry for letting you wait.
Not a problem. Thanks for finding out.
Further discussion with the WMI team shows that LocalService account does
not have permission to access the path for shares. You may view the DACL
on
shared folders in Computer Management->System Tools -Shared Folders ->
Shares. You may right click any share folder in right panel and view the
"Security" tabpage.

As you can see, LocalSystem and Administrators will be granted full
control
access to them, while LocalService does not have an ACE entry, which means
the LocalService will have no access to them.

Currently, due to the constraint DACL setting on the shared folder, we
have
to run the service under Administrators account or LocalSystem account.
That certainly explains what was going on. I'm going to do some reading
today to find out how to make my service install and use LocalSystem by
default, rather than LocalService.

Otherwise, the service is running like a charm. I appreciate everyone's help
in getting it going. It was a great first project to write. I'm now making a
list of refinements to roll into it at a later time.

Thanks.

ne.
May 10 '07 #15
Hi,

Thanks for your kindly feedback.

To configure your .Net Windows Service project to run under LocalSystem
account, you may follow the steps below:
1. Double click "ProjectInstaller.cs" in the Solution Explorer to open its
designer in left panel
2. Select "serviceProcessInstaller1" component in the designer
3. In the right side of the Property Browser, there is an item named
"Account", you may click this item dropdown list and select "LocalSystem".
4. Rebuild this project.

Finally, actually, there is another way to obtain the local file share
information without using WMI. That is using NetShareGetInfo Win32 API.
However, you have to p/invoke this API to use it.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 11 '07 #16
Hi,

Have you reviewed my last reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to feedback,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 15 '07 #17

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:XA**************@TK2MSFTNGHUB02.phx.gbl...
Hi,

Have you reviewed my last reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to feedback,
thanks.
Jeffrey,

Thanks for the info. I'll try it as soon as I can.

ne.
May 17 '07 #18

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

Similar topics

22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
1
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted....
4
by: | last post by:
Hi, Im running IIS and all my data is stored on a network share e.g \\10.0.0.111\domain.com\main The problem i'm facing is that i dont know how to point my aspx.vb files to any dlls in the bin...
2
by: yxq | last post by:
Hello I want to create and delete the folder share, i found that it is ok for generic folder, but it does not work for Root directory(i.e c:\, d:\) The code...
2
by: Steven J. Reed | last post by:
I have a Web Service that needs to find a Virtual Directory name, determine the actual path of that directory, then read / write files to that directory. How can I find a virtual directory then...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
0
by: NSF12345 | last post by:
Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\oldpc\main share\Folder\file.txt") Then" way of...
2
by: datamonk | last post by:
I am working on a package in SSIS that needs to check a directory to see if any files that begin with a three character string (PDE) exist, and set the value of a variable accordingly to determine...
0
by: cw808 | last post by:
Hi all. I'm new here but hoping I can get some help for my problem. My situation is that I need to upload files through a C# .NET web application to a file server. I done a search and followed...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.