We help IT Professionals succeed at work.

Scripting Desktop Search to search network Drives

PTBNA
PTBNA asked
on
This code works for the local Drive:
Private Sub GetScriptedFileSystem()
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.Recordset")

    objConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"

   objRecordSet.Open "SELECT System.ItemPathDisplay FROM SYSTEMINDEX Where System.ItemFolderPathDisplay = 'C:\' AND System.ItemType <> 'folder'", objConnection

    objRecordSet.movefirst
    Do Until objRecordSet.EOF
        MsgBox (objRecordSet.fields.Item("System.ItemPathDisplay"))
        objRecordSet.movenext
    Loop
    objConnection.Close
End Sub

But if I change the Drive letter to a Netwoked drive: "P:\" then no records are returned.  Any Idea how to work around this??
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
You would have to know the name of the server where that drive points to, and use a remote query against that server, which is illustrated here:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1014.mspx

The main reason you can't read that, I believe, is because P drive is not a system drive of the machine you're executing it on.

Regards,

Rob.

Author

Commented:
Not sure about "System Drive", but the P is mapped to the server.

I also tried using this format to reach drive:  //fileserver/myshare/folder/  which also wouldn't work.  

I'll take a look at the scriptcenter and see if I can get it to work.  Using some standard drive/folder/file read functions it takes about 1.5 minutes to run.   I'm guessing using the recordset functions would be a lot faster.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Sorry, I may have confused you.  What I was getting at, is that because P drive physically exists on a remote PC, then you cannot run a local query to browse that drive.  It looks as if this method *can* be extended to remote PCs however:
http://www.developer.com/net/net/article.php/3678316

by using:
RemoteMachineName.SYSTEMINDEX

So, as long as you know whether P drive is mapped to a share on the C or D of the remote server, you should be able to use:
strServer = "REMOTEPC"
objRecordSet.Open "SELECT System.ItemPathDisplay FROM " & strServer & ".SYSTEMINDEX Where System.ItemFolderPathDisplay = 'C:\' AND System.ItemType <> 'folder'", objConnection

Regards,

Rob.

Author

Commented:
I'll give that a try.  Thanks for the help.  I have a work around working, but this looks like it would be a faster way to retrieve the file names.

At this time we are running Vista, and it looks more like a security issue than a programming one.  I'll try to see if it will work, but not holding out much hope without a lot of re-programming in excel to bypass the "Security" features.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
No worries, good luck and thanks for the grade.  Unfortunately, I don't use Vista, so I am unable to provide a more clear cut solution.....

Regards,

Rob.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.