Forum Discussion

lherry's avatar
lherry
Contributor
3 years ago
Solved

Is there any solution to know if the running app is x86 or x64 ?

Hi all,

I'm having troubles to find a proper way to check if the running app is an x86 app or an x64 one.

For TestComplete / TestExecute, I can base my check the file path, but for other applications ?

I thought there was a "tag" that inform the OS of the platform it is designed for, but I can't find an easy way to extract it...

In my case, our tests are scripts driven and we are using 32 bits constraints for specific apps, and I would like to write an explicit log if the TestComplete is the x64 one and the tested app is the x86 one...

Thanks for your help and ideas !

Loïc

  • In the Object Browser, the property ProcessType will indicate this,

    rraghvani_0-1675068971459.png

    Windows Task Manager will have "(32 bit)" shown next to the file name.

    You can use PowerShell script to retrieve this information as well.

     

3 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    In the Object Browser, the property ProcessType will indicate this,

    rraghvani_0-1675068971459.png

    Windows Task Manager will have "(32 bit)" shown next to the file name.

    You can use PowerShell script to retrieve this information as well.

     

  • Thanks for your reply (and sorry I hadn't seen that object browser property)

    Anyway, I'll have to run the app to know if it's a 32 or 64 bit application...

    But that'll be enough to me!

    • AlexKaras's avatar
      AlexKaras
      Community Hero

      Hi,

       

      Anyway, I'll have to run the app to know if it's a 32 or 64 bit application...

      Ages ago I used this code to get executable bitness using AutomatedBuildStudio - another fantastic tool by SmartBear that has been discontinued for some reason... 😞

      I hope that you will be able to port it to the language that your test project is based on.

      '////////////////////////////////////////////////////
      '//                    VBScript                    //
      '//         AutomatedQA Corp (c) 2002-2004         //
      '//               ALK (c) 2003-2012                //
      '////////////////////////////////////////////////////
      
      ' The following macro constant(s) must be defined:
      ' <none>
      '
      ' The following macro variable(s) must be defined:
      ' smIsNativeBinary_vFileToAnalyse
      ' smGetBinaryBitness_BinaryBitness
      '
      ' The following macro operation(s) must be defined:
      ' <none>
      '-------------------------------------------------------------------------------
      
      Option Explicit
      '-----------------------------------------------------------------------------
      
      ' Function reads iBytesToRead bytes from the ADO stream (advancing pointer position in stream accordingly)
      ' and returns read bytes as a string
      Function StreamReadBytesAsString(ByRef stream, ByVal iBytesToRead)
        Dim i
        Dim bBuffer ' byte array
        Dim strHex
      
        bBuffer = stream.Read(iBytesToRead)
        strHex = ""
        For i = 1 To iBytesToRead
          strHex = strHex & Chr(AscB(MidB(bBuffer, i, 1)))
        Next
      
        StreamReadBytesAsString = strHex
      End Function
      '-----------------------------------------------------------------------------
      
      ' Function reads iBytesToRead bytes from the ADO stream (advancing pointer position in stream accordingly)
      ' and returns read bytes as a number
      Function StreamReadBytesAsNumber(ByRef stream, ByVal iBytesToRead)
        Dim i
        Dim bBuffer ' byte array
        Dim strHex
      
        bBuffer = stream.Read(iBytesToRead)
        strHex = ""
        For i = 1 To iBytesToRead
          strHex = Utilities.Format("%.2x", Array(AscB(MidB(bBuffer, i, 1)))) & strHex
        Next
      
        StreamReadBytesAsNumber = Eval("&H" & strHex)
      End Function
      '-----------------------------------------------------------------------------
      
      'From: http://geekswithblogs.net/rupreet/archive/2005/11/02/58873.aspx
      'also: http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx (http://msdn.microsoft.com/library/windows/hardware/gg463125)
      'also: http://stackoverflow.com/questions/480696/how-to-find-if-native-dll-is-compiled-as-x64-or-x86
      'also: http://stackoverflow.com/questions/1817152/detect-whether-the-assembly-was-built-for-net-compact-framework/1817231#1817231
      'also: http://stackoverflow.com/questions/1946322/how-do-i-find-out-if-a-net-assembly-contains-unmanaged-code
      Function GetExecutableBitness(ByVal strFullFileName)
        Const cPEHeaderSize = &H14
        Const cDataDictionaryEntrySize = &H8 ' size of the Directory entry of the DataDictionary structure
      
        Dim Stream
        Dim strHex
        Dim iPEOffset
        Dim iImageBitness
      '  Dim iPEHeaderSize
      
        GetExecutableBitness = "-1"
      
        Set Stream = CreateObject("ADODB.Stream")
        Stream.Type = 1 ' Binary (adTypeBinary)
      '  Stream.Mode = 1 ' adModeRead
        Stream.Open
        Stream.LoadFromFile strFullFileName
      
        ' Check 'MZ' signature
        Stream.Position = &H0 ' = 0d contains MZ signature
        strHex = StreamReadBytesAsNumber(Stream, 2)
        If (strHex <> 23117) Then ' MZ = 0x4D 0x5A (23117 = 0x5A4D)
          Call Log.Error("'MZ' signature was not found in the " & strFullFileName & _
              " file. The value at offset 0x0 is " & strHex & "d (0x" & Hex(strHex) & "h). Expected: 0x5A4D")
          Exit Function
        End If
      
        Stream.Position = &H3C ' = 60d contains offset to PE header
        iPEOffset = StreamReadBytesAsNumber(Stream, 4)
      'Log.Message "PE header (from 0x3Ch) starts at " & iPEOffset & "d (0x" & Hex(iPEOffset) & "h)"
      
        ' Check 'PE' signature
        Stream.Position = iPEOffset ' move to the PE header start
        strHex = StreamReadBytesAsNumber(Stream, 4)
        If (strHex <> 17744) Then ' PE = 0x50 0x45 (17744 = 0x4550)
          Call Log.Error("'PE' signature was not found in the " & strFullFileName & _
              " file. The value at offset 0x" & Hex(iPEOffset) & " is " & strHex & "d (0x" & Hex(strHex) & _
              "h). Expected: 0x4550")
          Exit Function
        End If
      '  strHex = StreamReadBytesAsString(Stream, 2)
      '  If ("PE" <> strHex) Then _
      '    Log.Error(strFullFileName & " file does not contain the required 'PE' signature")
      
        ' Get image bitness (this magic immediately follows 'PE' signature)
        iImageBitness = StreamReadBytesAsNumber(Stream, 2)
        Select Case iImageBitness
          Case &H14C ' i386 (32-bit)
            GetExecutableBitness = "32"
          Case &H8664 ' AMD64 (64-bit)
            GetExecutableBitness = "64"
          Case Else
            Log.Error("Unsupported image file architecture: " & iImageBitness & "d (0x" & Hex(iImageBitness) & _
                "h). Expected: 0x14C (32-bit) or 0x8664 (64-bit)")
        End Select
      
        Stream.Close
        Set Stream = Nothing
      End Function
      '-----------------------------------------------------------------------------
      
      Sub Main
      '  Dim strUNCFile
      '
      'strUNCFile = "D:\Program Files\Automated QA\TestComplete 7\Bin\msxml4r.dll"
      ''strUNCFile = "\\192.168.0.1\c$\Program Files\Oracle\VirtualBox\VirtualBox.exe"
      'Log.Message "strUNCFile = " & strUNCFile
      'Call GetExecutableBitness(strUNCFile)
      '
        Variables.smGetBinaryBitness_BinaryBitness = GetExecutableBitness(Variables.smGetBinaryBitness_BinaryFullName)
      End Sub
      '-------------------------------------------------------------------------------