locked
File not found RRS feed

  • Question

  • Hello,

    I'm writing a Visual Basic (2010) application that needs to perform a checksum on files in the system32 and system32\drivers folders. Here is my code:

    Imports System.Security.Cryptography
    Imports System.Runtime.Remoting.Metadata.W3cXsd2001
    
    Private Function getFileMd5(ByVal filePath As String) As String
            ' get all the file contents
            Dim File() As Byte = System.IO.File.ReadAllBytes(filePath)
    
            ' create a new md5 object
            Dim Md5 As New MD5CryptoServiceProvider()
    
            ' compute the hash
            Dim byteHash() As Byte = Md5.ComputeHash(File)
    
            ' return the value
            Dim hash As String = New SoapHexBinary(byteHash).ToString
            Return hash
    End Function
    

    When testing this on a file on my desktop, it works fine. When using say, "C:\Windows\System32\drivers\afd.sys", I get the following error:

    Could not find file 'C:\Windows\System32\drivers\afd.sys'

    I'm supposing it is a permission problem (as the file does exist). I've added <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> to app.manifest to force it to run as administrator and still have a problem. I've tried googling for information on permissions, but have had no luck so far. 

    Any help would be appreciated.

    My system is Windows 7 Ultimate 64bit, but need to collect checksums for XP and Vista as well.

    Rick


    • Edited by Mutexx Sunday, September 9, 2012 10:34 PM
    Sunday, September 9, 2012 10:31 PM

Answers

  • Hi Mutexx,

    Welcome to the MSDN Forum.

    I have found this is not a permission issue, it is a Folder redirect issue: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx 

    Based on my test, I assume your project platform is x86, rather than x64, so when you try to access "C:\Windows\System32\drivers", and you will be redirected to "C:\Windows\SysWOW64\drivers". So please change your project platform to x64.

    For test, you can copy that file to "C:\Windows\SysWOW64\drivers" folder to verify this issue.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mutexx Monday, September 10, 2012 4:41 AM
    Monday, September 10, 2012 3:45 AM

All replies

  • I manually went into Start -> Computer -> C:\Windows\System32 and drag/dropped 'drivers' into my flashdrive E: where the folder and all of its files were copied. This allowed me to access the afd.sys file from the flashdrive with no problem but it's a roundabout way of doing business.

    I tried using a vb.net program to copy C:\Windows\System32\drivers\afd.sys to a temp folder on my desktop and received the "file not found" error too. The vb.net program was running as admin via Visual Studio and I had changed its windows settings to <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> also.

    Then I used Start -> Computer -> C:\Windows\System32\drivers to list the files in 'drivers' and was able with no problem to drag/drop a copy of afd.sys to my temp folder on my desktop even though my application would not do basically the same thing by copying the file.

    So I guess what I'm saying is you may have to drag/drop the folder and its files to another location in order to access those files for your checksum checking.


    You've taught me everything I know but not everything you know.


    Monday, September 10, 2012 3:12 AM
  • Hi Mutexx,

    Welcome to the MSDN Forum.

    I have found this is not a permission issue, it is a Folder redirect issue: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx 

    Based on my test, I assume your project platform is x86, rather than x64, so when you try to access "C:\Windows\System32\drivers", and you will be redirected to "C:\Windows\SysWOW64\drivers". So please change your project platform to x64.

    For test, you can copy that file to "C:\Windows\SysWOW64\drivers" folder to verify this issue.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mutexx Monday, September 10, 2012 4:41 AM
    Monday, September 10, 2012 3:45 AM
  • Thanks Mike,

    That was it. I haven't tried removing the "requireAdministrator" from the manifest yet, but I suspect that will still be required.

    I appreciate you and Mr. Monkeyboy taking time to help out. 

    This caused me a fair amount of heartache today, but thanks to you I can move on (and learn a little something new too, which isn't so bad ;-)

    Rick

    Monday, September 10, 2012 4:45 AM
  • Changing my applications properties -> compile -> target cpu -> x64 allowed me to access C:\Windows\System32\drivers\afd.sys and copy it.

    Good job Mike Feng, thanks!


    You've taught me everything I know but not everything you know.

    Monday, September 10, 2012 4:52 AM
  • Hi Mutexx and Monkeyboy,

    it is my pleasure and I am glad it is helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 10, 2012 5:02 AM