Jump to content

_Net_Share_ShareCheck with Hidden Share


tau161
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

:)

Link to comment
Share on other sites

$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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 9 months later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...