tau161 Posted January 11, 2009 Share Posted January 11, 2009 (edited) 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 January 18, 2009 by tau161 Link to comment Share on other sites More sharing options...
pdaughe Posted January 11, 2009 Share Posted January 11, 2009 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 More sharing options...
tau161 Posted January 11, 2009 Author Share Posted January 11, 2009 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? Link to comment Share on other sites More sharing options...
rasim Posted January 11, 2009 Share Posted January 11, 2009 tau161Example:$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) NextMSDN Link to comment Share on other sites More sharing options...
tau161 Posted January 11, 2009 Author Share Posted January 11, 2009 (edited) $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 January 12, 2009 by tau161 Link to comment Share on other sites More sharing options...
rasim Posted January 12, 2009 Share Posted January 12, 2009 Make sure that ;Specifies the DNS or NetBIOS name of the remote server. Without double backslashes. Link to comment Share on other sites More sharing options...
tau161 Posted January 12, 2009 Author Share Posted January 12, 2009 (edited) 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 January 18, 2009 by tau161 Link to comment Share on other sites More sharing options...
tau161 Posted January 18, 2009 Author Share Posted January 18, 2009 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 More sharing options...
Sundance Posted November 12, 2009 Share Posted November 12, 2009 (edited) Hi Tau, i can confirm this behavior. It won't see c$ or IPC$ in our network. greetz Sundance Edited November 12, 2009 by Sundance Link to comment Share on other sites More sharing options...
99ojo Posted November 12, 2009 Share Posted November 12, 2009 (edited) Hi Tau,i can confirm this behavior. It won't see c$ or IPC$ in our network. greetzSundanceHi,try:If FileExists ("\\server\share$")= 1 Then DriveMap.....;-))StefanP.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 November 12, 2009 by 99ojo Link to comment Share on other sites More sharing options...
Sundance Posted November 12, 2009 Share Posted November 12, 2009 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. Link to comment Share on other sites More sharing options...
99ojo Posted November 12, 2009 Share Posted November 12, 2009 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 :-)greetzSundancePS: wie klein doch die Welt ist.HaHa, Bonn der Mittelpunkt..... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now