Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:25:35+00:00 2026-05-15T22:25:35+00:00

How can I execute FCIV and obtain a hash for a file using VBA?

  • 0

How can I execute FCIV and obtain a hash for a file using VBA?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:25:36+00:00Added an answer on May 15, 2026 at 10:25 pm

    Every pure VBA implementation I have seen has been painfully slow (sometimes over a minute per file). There may be a way to do this by tapping a Windows COM library but I am not currently aware of any such method. (I hope someome knows of one though and you’ll see why in a second:)) The best I have been able to come up with is a somewhat ugly workaound so the following suggestion may not be suitable in all scenarios but there is a very fast command line utility available from MS here: http://support.microsoft.com/kb/841290. The utility does MD5 and SHA1. Although the site says it’s for Windows XP I can verify it works with versions up through and including Windows 7. I haven’t tried it on 64 bit though.

    A few caveats:
    1. This utility is unsupported. I have never had any issues with it. But it’s still a consideration.
    2. The utility would have to be present on any machine you intended to run the code on and this may not be feasible in all circumstances.
    3. Obviously this is a bit of a hack/kludge so you may want to test it a little for error conditions etc.
    4. I just banged this together. I haven’t tested it/worked with it. So take 3 seriously:)

    Option Explicit
    
    Public Enum EHashType
        MD5
        SHA1
    End Enum
    
    ''//Update this value to wherever you install FCIV:
    Private Const mcstrFCIVPath As String = "C:\Windows\FCIV.exe"
    
    Public Sub TestGetFileHash()
        Dim strMyFilePath As String
        Dim strMsg As String
        strMyFilePath = Excel.Application.GetOpenFilename
        If strMyFilePath <> "False" Then
            strMsg = "MD5: " & GetFileHash(strMyFilePath, MD5)
            strMsg = strMsg & vbNewLine & "SHA1: " & GetFileHash(strMyFilePath, SHA1)
            MsgBox strMsg, vbInformation, "Hash of: " & strMyFilePath
        End If
    End Sub
    
    Public Function GetFileHash(ByVal path As String, ByVal hashType As EHashType) As String
        Dim strRtnVal As String
        Dim strExec As String
        Dim strTempPath As String
        strTempPath = Environ$("TEMP") & "\" & CStr(CDbl(Now))
        If LenB(Dir(strTempPath)) Then
            Kill strTempPath
        End If
        strExec = Join(Array(Environ$("COMSPEC"), "/C", """" & mcstrFCIVPath, HashTypeToString(hashType), """" & path & """", "> " & strTempPath & """"))
        Shell strExec, vbHide
        Do
            If LenB(Dir(strTempPath)) Then
                strRtnVal = GetFileText(strTempPath)
            End If
        Loop Until LenB(strRtnVal)
        strRtnVal = Split(Split(strRtnVal, vbNewLine)(3))(0)
        GetFileHash = strRtnVal
    End Function
    
    Private Function HashTypeToString(ByVal hashType As String) As String
        Dim strRtnVal As String
        Select Case hashType
            Case EHashType.MD5
                strRtnVal = "-md5"
            Case EHashType.SHA1
                strRtnVal = "-sha1"
            Case Else
                Err.Raise vbObjectError, "HashTypeToString", "Unexpected Hash Type"
        End Select
        HashTypeToString = strRtnVal
    End Function
    
    Private Function GetFileText(ByVal filePath As String) As String
        Dim strRtnVal As String
        Dim lngFileNum As Long
        lngFileNum = FreeFile
        Open filePath For Binary Access Read As lngFileNum
        strRtnVal = String$(LOF(lngFileNum), vbNullChar)
        Get lngFileNum, , strRtnVal
        Close lngFileNum
        GetFileText = strRtnVal
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.