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

1

u/bigredluigi Mar 08 '20

I had a similar problem but I made the code to run as a service in the system account. How I did this...I don't recall but that's how I did it.