locked
GetFolder (vbscript) RRS feed

  • Question

  • Hello

    I have to enumerate subfolders or shares of a remote computer. Usually for this task I use the GetFolder method:

    	FSO.GetFolder("\\computer\folder")
    
    

    What I need now is:

    	FSO.GetFolder("\\computer")
    
    

    But this returns an error: Path not found. This is not surprising as root is a computer and not a folder. But what can I do to get all folders or shares in it?

    Lg Marcello

    Monday, February 28, 2011 10:22 AM

Answers

  • I would suggest that you use Remote WMI, from this you can enumerate the shares, and even do all you need using WMI, by enumeration.

      Set objSWbemLocator = CreateObject( "WbemScripting.SWbemLocator" )
      Set objSWbemServices = objSWbemLocator.ConnectServer( strRemoteComputerName, "root\cimv2", strRemoteUserName, strUserPassword )
      Set objShares = GetObject( "winmgmts:\\" & strRemoteComputerName & "\root\cimv2" )

      Set arrCollection = objShares .ExecQuery( "SELECT * FROM Win32_Share where Type='0'" )
      For each Item In arrCollection
        strPath = Item.Path
        strShareName =  "\\" & strRemoteComputerName & "\" & Item.Name
    NOTE Here you can use your old way of doing your get Folder or define a new wmi query to get the needed information
        FSO.GetFolder( strShareName )
      Next

    Whatever you'd like

    Tuesday, March 1, 2011 7:27 PM

All replies

  • I would suggest that you use Remote WMI, from this you can enumerate the shares, and even do all you need using WMI, by enumeration.

      Set objSWbemLocator = CreateObject( "WbemScripting.SWbemLocator" )
      Set objSWbemServices = objSWbemLocator.ConnectServer( strRemoteComputerName, "root\cimv2", strRemoteUserName, strUserPassword )
      Set objShares = GetObject( "winmgmts:\\" & strRemoteComputerName & "\root\cimv2" )

      Set arrCollection = objShares .ExecQuery( "SELECT * FROM Win32_Share where Type='0'" )
      For each Item In arrCollection
        strPath = Item.Path
        strShareName =  "\\" & strRemoteComputerName & "\" & Item.Name
    NOTE Here you can use your old way of doing your get Folder or define a new wmi query to get the needed information
        FSO.GetFolder( strShareName )
      Next

    Whatever you'd like

    Tuesday, March 1, 2011 7:27 PM
  • Hi

    Cool.
    Seems to be exactly what I was looking for!!!!!

    Thank you very much.

    Lg Marcello

    Tuesday, March 1, 2011 8:28 PM
  • Btw. There's no need for the first two lines:

    Set objSWbemLocator ...
    Set objSWbemServices ...

    Lg Marcello
    Wednesday, March 2, 2011 6:57 AM