youtuber Posted January 13, 2020 Share Posted January 13, 2020 (edited) I have two separate programs, one x86 and one x64. If $type is 86 then @ProgramFilesDir & "\MyProgram\x86.exe" it should work with x64 @ProgramFilesDir & "\MyProgram\x64.exe" In this case, the exe file in the $type variable does not work Global $ProgramLocation $type = @ScriptDir & "\Test.exe" ShellExecute(_TypeLocationRun($ProgramLocation,$type)) Func _TypeLocationRun($ProgramLocation, $FileBinType) Local $stType = DllStructCreate("dword;") $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $FileBinType, "ptr", DllStructGetPtr($stType)) Switch DllStructGetData($stType, 1) Case 0 $FileBinType = "x86" Case 6 $FileBinType = "x64" EndSwitch If StringInStr($FileBinType, "x86") Then $ProgramLocation = @ProgramFilesDir & "\MyProgram\x86.exe" Else $ProgramLocation = @ProgramFilesDir & "\MyProgram\x64.exe" EndIf Return $ProgramLocation EndFunc ;==>_TypeLocationRun Edited January 13, 2020 by youtuber Link to comment Share on other sites More sharing options...
Danp2 Posted January 13, 2020 Share Posted January 13, 2020 Not really understanding what you are trying to accomplish. Have you looked at @OSArch and _WinAPI_GetBinaryType in the help file? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
UEZ Posted January 13, 2020 Share Posted January 13, 2020 @ProgramFilesDir output depends on the Autoit script execution format. If you compile it as x86 then @ProgramFilesDir will be "C:\Program Files (x86)" otherwise as x64 "C:\Program Files". You cannot use for this purpose @ProgramFilesDir. I would suggest If StringInStr($FileBinType, "x86") Then $ProgramLocation = EnvGet("ProgramFiles(x86)") & "\MyProgram\x86.exe" Else $ProgramLocation = EnvGet("ProgramFiles") & "\MyProgram\x64.exe" EndIf youtuber 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
youtuber Posted January 13, 2020 Author Share Posted January 13, 2020 (edited) This code works fine for me, but I want to use it as a function to avoid code redundancy. $type = @ScriptDir & "\Test.exe" Local $stType = DllStructCreate("dword;") $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $type, "ptr", DllStructGetPtr($stType)) Switch DllStructGetData($stType, 1) Case 0 $FileBinType = "x86" Case 6 $FileBinType = "x64" EndSwitch If StringInStr($FileBinType, "x86") Then $ProgramLocation = @ProgramFilesDir & "\MyProgram\x86.exe" Else $ProgramLocation = @ProgramFilesDir & "\MyProgram\x64.exe" EndIf ShellExecute($ProgramLocation, $type) or #include <WinAPIFiles.au3> Local $sText, $sPath = @ScriptDir & '\Test.exe' If _WinAPI_GetBinaryType($sPath) Then Switch @extended Case $SCS_32BIT_BINARY $sText = 'x86' Case $SCS_64BIT_BINARY $sText = 'x64' EndSwitch EndIf If StringInStr($sText, "x86") Then $ProgramLocation = @ProgramFilesDir & "\MyProgram\x86.exe" Else $ProgramLocation = @ProgramFilesDir & "\MyProgram\x64.exe" EndIf ShellExecute($ProgramLocation, $sPath) Edited January 13, 2020 by youtuber Link to comment Share on other sites More sharing options...
Nine Posted January 13, 2020 Share Posted January 13, 2020 I think there may be a conflict with your Global $ProgramLocation and your local parameter Func _TypeLocationRun($ProgramLocation, $FileBinType) having the same name. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted January 13, 2020 Share Posted January 13, 2020 Not really sure why you have the first parameter in your function as it isn't required, I'd probably use somethine like: Global $g_sFilepath = @ScriptDir & "\Test.exe" ShellExecute(_TypeLocationRun($g_sFilepath), $g_sFilepath) Func _TypeLocationRun($_sFilepath) Local $stType = DllStructCreate("dword;") Local $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $_sFilepath, "ptr", DllStructGetPtr($stType)) Switch DllStructGetData($stType, 1) Case 0 Return @ProgramFilesDir & "\MyProgram\x86.exe" Case 6 Return @ProgramFilesDir & "\MyProgram\x64.exe" Case Else Return "" EndSwitch EndFunc ;==>_TypeLocationRun youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted January 13, 2020 Author Share Posted January 13, 2020 12 minutes ago, Subz said: Global $g_sFilepath = @ScriptDir & "\Test.exe" ShellExecute(_TypeLocationRun($g_sFilepath), $g_sFilepath) Func _TypeLocationRun($_sFilepath) Local $stType = DllStructCreate("dword;") Local $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $_sFilepath, "ptr", DllStructGetPtr($stType)) Switch DllStructGetData($stType, 1) Case 0 Return @ProgramFilesDir & "\MyProgram\x86.exe" Case 6 Return @ProgramFilesDir & "\MyProgram\x64.exe" Case Else Return "" EndSwitch EndFunc ;==>_TypeLocationRun @Subz Yes this works great for me thank you Link to comment Share on other sites More sharing options...
UEZ Posted January 13, 2020 Share Posted January 13, 2020 (edited) I've a logical problem to understand how this will work properly. Let's say Test.exe is a x86 file but the AutoIt script is compiled as x64. My understanding is that the AutoIt script should execute the appropriate exe in MyProgram folder. In this case DllStructGetData($stType, 1) will return 0 (x86) but @ProgramFilesDir points to "C:\Program Files" the x64 folder because the AutoIt script is compiled as x64. But it should execute "C:\Program Files (x86)\MyProgram\x86.exe", shouldn't it? Example: #AutoIt3Wrapper_UseX64=y #include <WinAPIFiles.au3> _WinAPI_GetBinaryType("c:\Program Files (x86)\AutoIt3\Au3Info.exe") Switch @extended Case $SCS_32BIT_BINARY ConsoleWrite(EnvGet("ProgramFiles(x86)") & " <> " & @ProgramFilesDir & @CRLF) EndSwitch Btw, you can use _WinAPI_GetBinaryType too. Edited January 13, 2020 by UEZ youtuber 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now