Jump to content
Sign in to follow this  
tau161

_Net_Share_ShareCheck with Hidden Share

Recommended Posts

tau161

I am working on a little in-house network console for my company. I found the _Net_Share_ShareCheck as the perfect way to check for shares before I risk freezing things by mapping a share that doesn't exist. However , as far as I can determine, _Net_Share_ShareCheck isn't able to check the existence of hidden shares (i.e. shareName$ ). It returns a -1 just the same as a share that doesn't exist. Can someone confirm this for me? Is this by design, or is it a bug? And if it's true, is there a workaround?

Edited by tau161

Share this post


Link to post
Share on other sites
pdaughe

I am working on a little in-house network console for my company. I found the _Net_Share_ShareCheck as the perfect way to check for shares before I risk freezing things by mapping a share that doesn't exist. However , as far as I can determine, _Net_Share_ShareCheck isn't able to check the existence of hidden shares (i.e. shareName$ ). It returns a -1 just the same as a share that doesn't exist. Can someone confirm this for me? Is this by design, or is it a bug? And if it's true, is there a workaround?

WMI will show them to you.

Share this post


Link to post
Share on other sites
tau161

WMI will show them to you.

Hi pdaughe. Can you be more specific. And I forgot to mention, I am checking for a hidden share on Computer A from across the network on Computer B. - How would I account for that using WMI?

Share this post


Link to post
Share on other sites
rasim

tau161

Example:

$strComputer = "." ;Specifies the DNS or NetBIOS name of the remote server (. is a local computer)

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Share")

For $objItem In $colItems
    ConsoleWrite("AccessMask: " & $objItem.AccessMask & @LF & _
                 "AllowMaximum: " & $objItem.AllowMaximum & @LF & _
                 "Caption: " & $objItem.Caption & @LF & _
                 "Description: " & $objItem.Description & @LF & _
                 "InstallDate: " & $objItem.InstallDate & @LF & _
                 "MaximumAllowed: " & $objItem.MaximumAllowed & @LF & _
                 "Name: " & $objItem.Name & @LF & _
                 "Path: " & $objItem.Path & @LF & _
                 "Status: " & $objItem.Status & @LF & _
                 "Type: " & $objItem.Type & @LF & @LF)
Next

MSDN

:)

Share this post


Link to post
Share on other sites
tau161

$strComputer = "." ;Specifies the DNS or NetBIOS name of the remote server (. is a local computer)

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Share")

For $objItem In $colItems
    ConsoleWrite("AccessMask: " & $objItem.AccessMask & @LF & _
                 "AllowMaximum: " & $objItem.AllowMaximum & @LF & _
                 "Caption: " & $objItem.Caption & @LF & _
                 "Description: " & $objItem.Description & @LF & _
                 "InstallDate: " & $objItem.InstallDate & @LF & _
                 "MaximumAllowed: " & $objItem.MaximumAllowed & @LF & _
                 "Name: " & $objItem.Name & @LF & _
                 "Path: " & $objItem.Path & @LF & _
                 "Status: " & $objItem.Status & @LF & _
                 "Type: " & $objItem.Type & @LF & @LF)
NextoÝ÷ Ûú®¢×zYh­«"8ZL¨¹ú+Ê«­êeȦi¹^¶îØ^±Êâ¦Øî²×âë¬x-éhq©¢jnµêçjgºÜ!zr-¯+h²æì¶+nµè­Â+aj·¦¢×¢jnµêçjg¨®·¦¢×¢jnµêÈ=§]­ë,"­¶®º+jëh×6 Variable must be of type "Object"
$colItems = $objWMIService.ExecQuery("Select * from Win32_Share")
$colItems = $objWMIService^ ERROR

Since this doesn't happen with the local computer, I figure I must be leaving out a step to be able to query a remote computer, maybe?? Can you help me troubleshoot.

Edited by tau161

Share this post


Link to post
Share on other sites
rasim

Make sure that ;Specifies the DNS or NetBIOS name of the remote server. Without double backslashes.

Share this post


Link to post
Share on other sites
tau161

Make sure that ;Specifies the DNS or NetBIOS name of the remote server. Without double backslashes.

$strComputer = "EditStation3"

This does not work for me with remote host names, e.g. "EditStation3" - no double backslashes - from "EditStation1". I've attempted from several computers with several valid remote host names. Only the local computer name works. If that code bit works for everyone else with remote computers but not for me, then is there some preparatory code that I should have in there before referencing remote computers with WMI?

All help is welcome. Thanks.

Edited by tau161

Share this post


Link to post
Share on other sites
tau161

I am working on an in-house network console for my company. I found the _Net_Share_ShareCheck function as the perfect way to check for shares to avoid mapping a share that doesn't exist. However , as far as I can determine, _Net_Share_ShareCheck isn't able to check the existence of hidden shares (i.e. shareName$ ). It returns a -1 just the same as a share that doesn't exist. Can someone confirm or contradict this for me? Is this by design, or is it a bug?

While I'm exploring other options, can anyone confirm or contradict the above behavior with _Net_Share_ShareCheck() for me. Is it a bug? Is it by design? Neither?... Is it just behaving strangely on our computers only? Etc.

Thanks.

Share this post


Link to post
Share on other sites
Sundance

Hi Tau,

i can confirm this behavior. It won't see c$ or IPC$ in our network.

greetz

Sundance

Edited by Sundance

Share this post


Link to post
Share on other sites
99ojo

Hi Tau,

i can confirm this behavior. It won't see c$ or IPC$ in our network.

greetz

Sundance

Hi,

try:

If FileExists ("\\server\share$")= 1 Then DriveMap.....

;-))

Stefan

P.S: I can confirm as well, that _Net_Share_ShareCheck fails (Return -1) on hidden shares. But i can see c$, ipc$ or admin$ with _Net_Share_ShareEnum. So you might use ..ShareEnum function or the FileExists.

Edited by 99ojo

Share this post


Link to post
Share on other sites
Sundance

Hi 99ojo,

i thought of the same ...

I do a regread( and if it fails i know that i have a problem and do a net use \\PC ...

Gonna think about it :-)

greetz

Sundance

PS: wie klein doch die Welt ist.

Share this post


Link to post
Share on other sites
99ojo

Hi 99ojo,

i thought of the same ...

I do a regread( and if it fails i know that i have a problem and do a net use \\PC ...

Gonna think about it :-)

greetz

Sundance

PS: wie klein doch die Welt ist.

HaHa,

:)

Bonn der Mittelpunkt.....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×