PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Finding a share's directory spec

 
 
NetworkElf
Guest
Posts: n/a
 
      27th Apr 2007
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.


 
Reply With Quote
 
 
 
 
zacks@construction-imaging.com
Guest
Posts: n/a
 
      27th Apr 2007
On Apr 27, 10:39 am, "NetworkElf" <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
 
NetworkElf
Guest
Posts: n/a
 
      27th Apr 2007

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Apr 27, 10:39 am, "NetworkElf" <(E-Mail Removed)> wrote:


>> 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.


 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      27th Apr 2007
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
 
Reply With Quote
 
NetworkElf
Guest
Posts: n/a
 
      27th Apr 2007

"Matthias Tacke" <(E-Mail Removed)> wrote in message
news:f0tc19$7ie$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      30th Apr 2007
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.



 
Reply With Quote
 
NetworkElf
Guest
Posts: n/a
 
      30th Apr 2007

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      1st May 2007
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.


 
Reply With Quote
 
NetworkElf
Guest
Posts: n/a
 
      2nd May 2007
----- Original Message -----
From: ""Jeffrey Tan[MSFT]"" <(E-Mail Removed)>
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...

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.


 
Reply With Quote
 
NetworkElf
Guest
Posts: n/a
 
      3rd May 2007

"NetworkElf" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritance of static members in the CLR spec vs the C# spec Tim Van Wassenhove Microsoft C# .NET 2 18th Aug 2007 09:35 PM
Re: Inheritance of static members in the CLR spec vs the C# spec GlennDoten Microsoft C# .NET 0 18th Aug 2007 04:06 PM
Finding My Export Spec =?Utf-8?B?REJH?= Microsoft Access 7 24th Jan 2006 09:08 PM
Finding Active Directory Groups and Users On a Directory Garrett Microsoft C# .NET 0 30th Nov 2004 07:47 PM
Active Directory Minimum hardware Spec ivor hughes Windows XP Hardware 2 8th Jun 2004 08:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:38 AM.