Hi,

I am working on a Project that has to search some specific folders and inside those folders I want to check if any file resides.

I used the following techniques but they are not working if I need to connect to the machine as USER:

If Directory.Exists("\\" & Me.CheckedListBox1.Items(i).ToString & \D\DirectoryName\) = True Then ' D is the D Drive
           If File.Exists("\\" & Me.CheckedListBox1.Items(i).ToString & "\D\Test.txt") = True Then

msgbox ("Test.txt Exists in " & Me.CheckedListBox1.Items(i).ToString & \D\DirectoryName\ )

End if

Now the problem is I have to Login as Administrator to run the program or at least on the Server. If some has any idea please dont forget to share it.

Waiting for a response.

Regards,

Waqas

Recommended Answers

All 6 Replies

Are the same mapped drives available while logged on as a user? If its a security error, you need to lower the security settings on your lan

I am not mapping the network drive. What I have done is I took a Checklist box then I am adding the IP Addresses of the Servers into it.

If you take a look on my Code its says "\\" that means I am trying to find the code as of the run command.

i.e. \\10.10.10.2\{Driverletter}\NEWFOLDER\TEST.TXT
(NEWFOLDER\TEST.TXT is always the same.)

Thanks & Regards,

Waqas

If access the \\machine\share only works when you are logged on as administrator and not a normal user then that is a security issue. You need to grant the user account access to see that share.

This is more of a windows security issue than a code issue.

Dim ServerName = "pc_name"
Dim AdminUserName = "Administrator"
Dim DomainName = "domain_name"
Dim AdminPassword = "password"
' Initialize WMI
Dim objSWbemLocator As New WbemScripting.SWbemLocator
' Connect to remote PC


Dim objSWbemServices = objSWbemLocator.ConnectServer _
                       (ServerName, "root\cimv2", _
                       AdminUserName, AdminPassword, _
                       "MS_409", "ntlmdomain:" + DomainName)


Dim Drive,Path,FileName,Ext as String

Drive = chr(34) + "c:" + Chr(34)
Path = chr(34) + "\\newfolder\\" + chr(34)  
FileName = chr(34) + "test" + chr(34) 
Ext = chr(34) + "txt" + chr(34) 

 Dim oCIM_DataFile = objSWbemServices.ExecQuery _
                     ("select * from CIM_DataFile where drive = " & Drive _ 
                     & " and path = " & Path & " and filename = " & FileName _ 
                     & " and extension = " & Ext)

For Each obj In oCIM_DataFile
    ' If your program execution got here, then the file exist
    Debug.Print (obj.FileName)
Next

Thanks a Zillion... That's what I was searching for....

You made my day Sameer Bhai.

Regards & Eid Greetings,

Syed Waqas Ahmad

You are welcome

But you had spelled my name is wrong way, It take me a second to recognize that you are talking to me (lol)

Have a good day.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.