r/visualbasic • • Mar 07 '20

VB.NET Help Search through C:\ProgramFiles - Unauthorized access help

So I've got a piece of code (below) which is supposed to scan every logical drive on a computer to track down an executable. For some reason, the program cannot access C:\Program files, which is an issue as that is where the executable is. Does anyone know of a way I can brute force the program to look into program files?

Code

            For Each Drive In System.IO.Directory.GetLogicalDrives()
                Dim ActiveDrive As New IO.DirectoryInfo(Drive)  'choose next drive letter in list
                For Each FoundDirectory In ActiveDrive.GetDirectories() 'For every folder in drive
                    Try
                        For Each File As IO.FileInfo In FoundDirectory.GetFiles(Executable, IO.SearchOption.AllDirectories)
                            NewExecutablePath = File.FullName   'Get .exe full location
                            NewInstallStatus = True             'Prepare to set installed to true in database
                        Next
                    Catch ex As UnauthorizedAccessException
                    End Try
                Next
            Next

all help is appreciated.

5 Upvotes

5 comments sorted by

View all comments

3

u/faust2099 Mar 07 '20

That's how windows protect it's file system, usually you get around this by running the program in administrator mode.

1

u/TheFotty Mar 08 '20

That is how it works for write privileges, but standard user accounts can definitely read those files and folders, otherwise they wouldn't be able to run programs installed there.