MattHiggs Posted Wednesday at 12:34 PM Posted Wednesday at 12:34 PM Hello all. I am attempting to use Autoit to launch the GUI for a particular portable application and automate control interactions in an autoit script. However, when I try to launch the GUI with either the Run or ShellExecute functions, the GUI is not getting launched. I could be wrong, but I am pretty confident that the problem that I am running into is the fact that this particular portable application doubles as both GUI application and a command line application: double clicking the file opens the application's GUI, while calling the executable from the command prompt utilizes its command line interface, and I believe that my attempts to launch the application's GUI using the Run and ShellExecute functions are activating the application's command line interface, because it is defiantly not launching the GUI like I want. My question is if there is a way to force autoit to open the application's GUI instead. For reference, the problematic application that is at the heart of this question can be obtained below: https://github.com/superfly-inc/showkeyplus/releases
IronFine Posted Wednesday at 12:55 PM Posted Wednesday at 12:55 PM I can't replicate your issue. Can you share your code-snippet where you try to launch the app?
ioa747 Posted Wednesday at 01:04 PM Posted Wednesday at 01:04 PM I tried it and both ShellExecute working as expect. ; ShellExecute(@DesktopDir & "\ShowKeyPlus_x86\ShowKeyPlus.exe") ShellExecute("explorer", @DesktopDir & "\ShowKeyPlus_x86\ShowKeyPlus.exe") I know that I know nothing
MattHiggs Posted Wednesday at 01:26 PM Author Posted Wednesday at 01:26 PM Hmm. Well, I was using the 64 bit version, so I don't know if that makes a difference, but here is the code I have tried: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.17.1 (Beta) Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here If Not WinExists ( "ShowKeyPlus" ) Then Run ( @ScriptDir & "\ShowKeyPlus.exe", @ScriptDir, @SW_SHOW ) WinWait ( "ShowKeyPlus" ) EndIf WinActivate ( "ShowKeyPlus" ) WinWaitActive ( "ShowKeyPlus" )
ioa747 Posted Wednesday at 01:33 PM Posted Wednesday at 01:33 PM try without #AutoIt3Wrapper_Change2CUI=y I know that I know nothing
Developers Jos Posted Wednesday at 01:46 PM Developers Posted Wednesday at 01:46 PM (edited) Could it be you have another windows open that contains the text "ShowKeyPlus", as that will make the If false and fail to start it? or maybe try testing for the "ShowKeyPlus.exe" process itself instead of a text in the window title? Edited Wednesday at 01:48 PM by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioa747 Posted Wednesday at 01:51 PM Posted Wednesday at 01:51 PM #RequireAdmin #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y ;~ #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> If Not WinExists("ShowKeyPlus") Then Run(@ScriptDir & "\ShowKeyPlus_x64\ShowKeyPlus.exe") Local $hWnd = WinWaitActive("ShowKeyPlus", "", 3) If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window not found") ConsoleWrite("$hWnd=" & $hWnd & @CRLF) WinActivate($hWnd) I know that I know nothing
IronFine Posted Wednesday at 02:28 PM Posted Wednesday at 02:28 PM 51 minutes ago, MattHiggs said: Quality is not the best, but after you double-click on the compiled script the folder is becoming active again. Is the folder that contains the script by any chance named "ShowKeyPlus"? If so, the script will activate that explorer window.
argumentum Posted Wednesday at 04:43 PM Posted Wednesday at 04:43 PM (edited) #RequireAdmin #include <WinAPIProc.au3> ShellExecute("ShowKeyPlus.exe", "", @ScriptDir, "Open") ; load it WinActivate_GuiAndExeToHandle("ShowKeyPlus", "ShowKeyPlus.exe", 5000) ; WinActivate() it Func WinActivate_GuiAndExeToHandle($sTitle, $sExe, $iTimeoutMs = 5000) Local $hWin, $hTimer = TimerInit() Do If TimerDiff($hTimer) > $iTimeoutMs Then ExitLoop $hWin = GuiAndExeToHandle($sTitle, $sExe) If Not $hWin Then Sleep(300) Until $hWin If $hWin Then WinActivate($hWin) Return SetError(Int(Not $hWin), 0, $hWin) EndFunc ;==>WinActivate_GuiAndExeToHandle Func GuiAndExeToHandle($sTitle, $sExe) Local $n, $iPID, $sProcessFileName, $aWinList = WinList($sTitle) For $n = 1 To UBound($aWinList) - 1 $iPID = WinGetProcess($aWinList[$n][1]) If $iPID Then $sProcessFileName = _WinAPI_GetProcessFileName($iPID) ConsoleWrite($sProcessFileName & @CRLF) If StringInStr($sProcessFileName, $sExe) Then Return $aWinList[$n][1] EndIf Next Return 0 EndFunc ;==>GuiAndExeToHandle ;~ Run(@ComSpec & ' /c ShowKeyPlus.exe ShowKeyPlus.txt') ; this works too @MattHiggs: Born 2015 (to the forum), met his demise due to a M$ windows class PS: try Downloads - ShareX for a nice "screen to gif" thingy, without marketing ( it's free too ) Edited Wednesday at 05:14 PM by argumentum better Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted Wednesday at 10:59 PM Posted Wednesday at 10:59 PM (edited) here is a native solution without ShowKeyPlus, from a VBS translation Spoiler Option Explicit Dim objshell,path,DigitalID, Result Set objshell = CreateObject("WScript.Shell") 'Set registry key path Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" 'Registry key value DigitalID = objshell.RegRead(Path & "DigitalProductId") Dim ProductName,ProductID,ProductKey,ProductData 'Get ProductName, ProductID, ProductKey ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName") ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID") ProductKey = "Installed Key: " & ConvertToKey(DigitalID) ProductData = ProductName & vbNewLine & ProductID & vbNewLine & ProductKey 'Show messbox if save to a file If vbYes = MsgBox(ProductData & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then Save ProductData End If 'Convert binary to chars Function ConvertToKey(Key) Const KeyOffset = 52 Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert 'Check if OS is Windows 8 isWin8 = (Key(66) \ 6) And 1 Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4) i = 24 Maps = "BCDFGHJKMPQRTVWXY2346789" Do Current= 0 j = 14 Do Current = Current* 256 Current = Key(j + KeyOffset) + Current Key(j + KeyOffset) = (Current \ 24) Current=Current Mod 24 j = j -1 Loop While j >= 0 i = i -1 KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput Last = Current Loop While i >= 0 If (isWin8 = 1) Then keypart1 = Mid(KeyOutput, 2, Last) insert = "N" KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0) If Last = 0 Then KeyOutput = insert & KeyOutput End If ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5) End Function 'Save data to a file Function Save(Data) Dim fso, fName, txt,objshell,UserName Set objshell = CreateObject("wscript.shell") 'Get current user name 'UserName = objshell.ExpandEnvironmentStrings("%UserName%") 'Create a text file on desktop fName = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\WindowsKeyInfo.txt" 'WScript.Echo "fName: " & fName Set fso = CreateObject("Scripting.FileSystemObject") Set txt = fso.CreateTextFile(fName) txt.Writeline Data txt.Close End Function I couldn't manage the Binary array properly, so I introduced the "WScript.Shell" Object If someone manages to do it, I'd be happy to see it. expandcollapse popup;~ #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $info = ShowKeyPlus() ConsoleWrite($info & @CRLF) Func ShowKeyPlus() Local $oShell, $sProductName, $sProductID, $sProductKey, $sProductData $oShell = ObjCreate("WScript.Shell") If @error Then MsgBox(16, "Error", "Could not create WScript.Shell object.") Exit EndIf $sProductName = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName") $sProductID = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId") Local $aDigitalID = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId") If Not IsArray($aDigitalID) Or UBound($aDigitalID) < 164 Then MsgBox(16, "Error", "Could not read the DigitalProductId from the registry.") Exit EndIf $sProductKey = ConvertToKey($aDigitalID) $sProductData = "Product Name: " & $sProductName & @CRLF & _ "Product ID: " & $sProductID & @CRLF & _ "Installed Key: " & $sProductKey Return $sProductData EndFunc Func ConvertToKey($aKeyBytes) Local Const $iKeyOffset = 52 Local Const $sMaps = "BCDFGHJKMPQRTVWXY2346789" Local $isWin8, $i, $j, $iCurrent, $sKeyOutput = "", $iLast $isWin8 = BitAND(Int($aKeyBytes[66] / 6), 1) $aKeyBytes[66] = BitOR(BitAND($aKeyBytes[66], 0xF7), BitShift(BitAND($isWin8, 2), 2)) For $i = 24 To 0 Step -1 $iCurrent = 0 For $j = 14 To 0 Step -1 $iCurrent = $iCurrent * 256 $iCurrent = $iCurrent + $aKeyBytes[$j + $iKeyOffset] $aKeyBytes[$j + $iKeyOffset] = Floor($iCurrent / 24) $iCurrent = Mod($iCurrent, 24) Next If $i > 0 Then $sKeyOutput = StringMid($sMaps, $iCurrent + 1, 1) & $sKeyOutput $iLast = $iCurrent Next If $isWin8 = 1 Then Local $sKeyPart1 = StringMid($sKeyOutput, 1, $iLast) Local $sInsert = "N" $sKeyOutput = $sKeyPart1 & $sInsert & StringMid($sKeyOutput, $iLast + 1) EndIf Return StringMid($sKeyOutput, 1, 5) & "-" & _ StringMid($sKeyOutput, 6, 5) & "-" & _ StringMid($sKeyOutput, 11, 5) & "-" & _ StringMid($sKeyOutput, 16, 5) & "-" & _ StringMid($sKeyOutput, 21, 5) EndFunc Edited Wednesday at 11:05 PM by ioa747 argumentum 1 I know that I know nothing
argumentum Posted Wednesday at 11:40 PM Posted Wednesday at 11:40 PM 40 minutes ago, ioa747 said: If someone manages to do it, I'd be happy to see it. Spoiler expandcollapse popup;~ #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Debug.au3> Global $info = ShowKeyPlus() ConsoleWrite($info & @CRLF) Func ShowKeyPlus() Local $oShell, $sProductName, $sProductID, $sProductKey, $sProductData $oShell = ObjCreate("WScript.Shell") If @error Then MsgBox(16, "Error", "Could not create WScript.Shell object.") Exit EndIf $sProductName = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName") $sProductID = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId") ;~ Local $aDigitalID = $oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId") Local $aDigitalID = TrustMe_IKnowWhatAmDoing(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")) If Not IsArray($aDigitalID) Or UBound($aDigitalID) < 164 Then MsgBox(16, "Error", "Could not read the DigitalProductId from the registry.") Exit EndIf $sProductKey = ConvertToKey($aDigitalID) $sProductData = "Product Name: " & $sProductName & @CRLF & _ "Product ID: " & $sProductID & @CRLF & _ "Installed Key: " & $sProductKey Return $sProductData EndFunc Func TrustMe_IKnowWhatAmDoing($sStr) Local $n, $sRet = "", $aArray = StringSplit($sStr, "", 0) For $n = 4 To $aArray[0] Step 2 $sRet &= Int("0x" & $aArray[$n - 1] & $aArray[$n]) & "," Next Return StringSplit(StringTrimRight($sRet, 1), ",", 2) EndFunc Func ConvertToKey($aKeyBytes) Local Const $iKeyOffset = 52 Local Const $sMaps = "BCDFGHJKMPQRTVWXY2346789" Local $isWin8, $i, $j, $iCurrent, $sKeyOutput = "", $iLast $isWin8 = BitAND(Int($aKeyBytes[66] / 6), 1) $aKeyBytes[66] = BitOR(BitAND($aKeyBytes[66], 0xF7), BitShift(BitAND($isWin8, 2), 2)) For $i = 24 To 0 Step -1 $iCurrent = 0 For $j = 14 To 0 Step -1 $iCurrent = $iCurrent * 256 $iCurrent = $iCurrent + $aKeyBytes[$j + $iKeyOffset] $aKeyBytes[$j + $iKeyOffset] = Floor($iCurrent / 24) $iCurrent = Mod($iCurrent, 24) Next If $i > 0 Then $sKeyOutput = StringMid($sMaps, $iCurrent + 1, 1) & $sKeyOutput $iLast = $iCurrent Next If $isWin8 = 1 Then Local $sKeyPart1 = StringMid($sKeyOutput, 1, $iLast) Local $sInsert = "N" $sKeyOutput = $sKeyPart1 & $sInsert & StringMid($sKeyOutput, $iLast + 1) EndIf Return StringMid($sKeyOutput, 1, 5) & "-" & _ StringMid($sKeyOutput, 6, 5) & "-" & _ StringMid($sKeyOutput, 11, 5) & "-" & _ StringMid($sKeyOutput, 16, 5) & "-" & _ StringMid($sKeyOutput, 21, 5) EndFunc Here it is ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted yesterday at 12:37 AM Posted yesterday at 12:37 AM (edited) Thank you very much 🏆 argumentum for helping me get rid of the "WScript.Shell" Object here the code is clean now expandcollapse popup;~ #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $info = ShowKeyPlus() ConsoleWrite($info & @CRLF) Func ShowKeyPlus() Local $sProductName, $sProductID, $sProductKey, $sProductData, $sDigitalID, $aDigitalID $sProductName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName") $sProductID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId") $sDigitalID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId") Local $n, $sRet = "", $aArray = StringSplit($sDigitalID, "", 0) For $n = 4 To $aArray[0] Step 2 $sRet &= Int("0x" & $aArray[$n - 1] & $aArray[$n]) & "," Next $aDigitalID = StringSplit(StringTrimRight($sRet, 1), ",", 2) If Not IsArray($aDigitalID) Or UBound($aDigitalID) < 164 Then MsgBox(16, "Error", "Could not read the DigitalProductId from the registry.") Exit EndIf $sProductKey = ConvertToKey($aDigitalID) $sProductData = "Product Name: " & $sProductName & @CRLF & _ "Product ID: " & $sProductID & @CRLF & _ "Installed Key: " & $sProductKey Return $sProductData EndFunc Func ConvertToKey($aKeyBytes) Local Const $iKeyOffset = 52 Local Const $sMaps = "BCDFGHJKMPQRTVWXY2346789" Local $isWin8, $i, $j, $iCurrent, $sKeyOutput = "", $iLast $isWin8 = BitAND(Int($aKeyBytes[66] / 6), 1) $aKeyBytes[66] = BitOR(BitAND($aKeyBytes[66], 0xF7), BitShift(BitAND($isWin8, 2), 2)) For $i = 24 To 0 Step -1 $iCurrent = 0 For $j = 14 To 0 Step -1 $iCurrent = $iCurrent * 256 $iCurrent = $iCurrent + $aKeyBytes[$j + $iKeyOffset] $aKeyBytes[$j + $iKeyOffset] = Floor($iCurrent / 24) $iCurrent = Mod($iCurrent, 24) Next If $i > 0 Then $sKeyOutput = StringMid($sMaps, $iCurrent + 1, 1) & $sKeyOutput $iLast = $iCurrent Next If $isWin8 = 1 Then Local $sKeyPart1 = StringMid($sKeyOutput, 1, $iLast) Local $sInsert = "N" $sKeyOutput = $sKeyPart1 & $sInsert & StringMid($sKeyOutput, $iLast + 1) EndIf Return StringMid($sKeyOutput, 1, 5) & "-" & _ StringMid($sKeyOutput, 6, 5) & "-" & _ StringMid($sKeyOutput, 11, 5) & "-" & _ StringMid($sKeyOutput, 16, 5) & "-" & _ StringMid($sKeyOutput, 21, 5) EndFunc Edited yesterday at 02:13 AM by ioa747 argumentum 1 I know that I know nothing
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