MikeK6MKF Posted March 9, 2015 Share Posted March 9, 2015 Thanks to all the great support I've had on this forum, I have my first AutoIt script working well. Now I would like to be able to free my script from its dependence on a hard-wired path to the Adobe Acrobat PDF reader. Currently, I have the path defined in a variable I use in subsequent Run statements. Local $AcrobatPath = '"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /A page=' Is there some sort of function that will allow me to query Windows with "AcroRd32.exe" and get the full pathname to that executable? I'd like to be able to distribute the script to my friends, but can't be sure their AcroRD32.exe will be installed in the same directory. Any guidance, advice or suggestions will be greatly appreciated. Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 9, 2015 Moderators Share Posted March 9, 2015 MikeK6MKF,You could search the disk for the file using _FileListToArrayRec but that could take a while. A better solution might well be to use ShellExecute which allows Windows to use the default application for the passed file type rather than Run - that way the location of that app is moot. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 9, 2015 Author Share Posted March 9, 2015 Thanks! I'll go try that! Link to comment Share on other sites More sharing options...
iamtheky Posted March 9, 2015 Share Posted March 9, 2015 $hFile = fileopendialog("select pdf" , @ScriptDir , "PDF (*.pdf)") $sExe = "AcroRd32.exe" $sPage = "3" $ExePath = FileGetShortName(regread('HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\' & $sExe , "")) $FilePath = FileGetShortName($hFile) run ($ExePath & " /A page=" & $sPage & " " & $FilePath) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Solution MikeK6MKF Posted March 10, 2015 Author Solution Share Posted March 10, 2015 OK, thanks for all the suggestions! I bounced this off a buddy who had done something similar before, and he donated a code snippet that I got to work in my script. expandcollapse popup; Code snippet to find AcroRD32.EXE on either a 32 bit installation of Windows ; or a 64 Bit installation. ; Local $ipid = Run(@ComSpec & ' /C DIR /b C:\Prog*', "C:\", @SW_HIDE, $STDOUT_CHILD); ProcessWaitClose($ipid) Local $progDirs = StdoutRead($iPid) Local $sPath = "C:\Program Files" ; _ArrayDisplay(StringSplit(StringStripCR($progDirs), @CRLF)) If StringInStr($progDirs, "Program Files (x86)") <> 0 Then ; We must be on a 64-bit OS as there is a Program Files (x86) ; AcroRd32 will be under this path as its a 32 bit app $sPath = "C:\Program Files (x86)" EndIf ; Run dir on $sPath and find ACRORD32.EXE $ipid = Run(@ComSpec & ' /C DIR /s/b "' & $sPath & '\*ACRORD32.EXE', "C:\", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($ipid) Local $hfta = StdoutRead($ipid) Local $aOutput = StringSplit(StringStripCR($hfta), @CRLF) ; _ArrayDisplay($aOutput) Local $i For $i=0 To UBound($aOutput) - 1 If StringInStr($aOutput[$i], "ACRORD32.EXE") <> 0 Then ExitLoop EndIf Next If $i = UBound($aOutput) Or $aOutput[$i] = '' Then MsgBox(0, "Error", $i & " Can't find ACRORD32 Installation directory under " & $sPath) Exit EndIf ; ; If you get here then $aOutput[$i] is the fully qualified file name of AcroRd32 including ; the path and the executable name. ; $AdobePath = $aOutput[$i] ; MsgBox(0,'',"The $AdobePath Path is: " & $AdobePath) I will study this closely so I can begin to understand just how this works. I think my script is done, so now off to the Tutorials! Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 You's be mad to use that over boththose suggestion. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Tripredacus Posted March 10, 2015 Share Posted March 10, 2015 Actually, neither are ideal resolutions and should only be used in an environment where the expected outcome is something required... Say in an enterprise setting.The reasons being:1. Boththose answer is presuming that Acrobat is the default PDF association. What if associations are broken, or another program is the default for .PDF files?2. Mike's answer is presuming that Acrobat is installed in a default location. What if it is installed onto another drive, or in a location that is not in Program Files?If neither of these scenarios concern the OP, then it isn't a problem. Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2015 Moderators Share Posted March 10, 2015 (edited) MikeK6MKF,Tripredacus' comments are exactly why I suggested ShellExecute - let Windows do the hard work for you. M23 Edited March 10, 2015 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2015 Share Posted March 10, 2015 Boththose answer is presuming that Acrobat is the default PDF association Where? It just assumes that AcroRd32.exe is installed on the system. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
iamtheky Posted March 10, 2015 Share Posted March 10, 2015 The arguments in the run command, kind of also require that you are using AcroRd32.exe ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 10, 2015 Author Share Posted March 10, 2015 Much good information has been given above, and has given me much to think about. This is a hobby script to be used by Amateur Radio ops to quickly reference HF propagation predictions, generated by an online service. It is a good point that not all will be using ArcoRd32.exe to open .pdf files. I have my script out for testing with a few friends and I will see what their experiences are. Most likely I will revisit this, as I would like to have my script as usable as possible over a variety of environments. As for being 'mad', well, I have heard that many times before! Link to comment Share on other sites More sharing options...
clicked Posted March 10, 2015 Share Posted March 10, 2015 Other options: If you are looking for a particular executable that is in your PATH, you can issue a "cmd /c where" to find it. If you are looking to open a document with the standard binding, "cmd /c start" will open it (although, it sometimes has trouble with spaces in the filename even if you quote it). Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 10, 2015 Author Share Posted March 10, 2015 Thank you for this insight. I've decided I'd best stick with my approach of resolving the path to AcroRD32.exe. I use Adobe opening parameters to get a specific page, and they are peculiar to AcroRD32.exe, so I'm sort of stuck with it. Link to comment Share on other sites More sharing options...
iamtheky Posted March 10, 2015 Share Posted March 10, 2015 what is #4 lacking? as described, it seems to meet the requirement with far less effort than #5. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jguinch Posted March 10, 2015 Share Posted March 10, 2015 #4 is the faster way to find the application location, but requires that the program has already been run once. Even if you probably have an answer, here are 2 other ways: $aAdobeReader = _UninstallList("DisplayName", "Adobe Reader", "InstallLocation") ; _UninstallList in my signature _ArrayDisplay($aAdobeReader and a registry way : Local $sAdobeReaderPath = _GetAdobeReaderPath() If @error Then MsgBox(16, "", "Adobe Reader not found") Else MsgBox(0, "", "Adobe Reader full path : " & @CRLF & $sAdobeReaderPath & "\AcroRD32.exe") EndIf Func _GetAdobeReaderPath() Local $sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader" Local $i = 1, $sApp, $sInstallPath While 1 $sApp = RegEnumKey($sKey, $i) If @error Then ExitLoop $sInstallPath = RegRead($sKey & "\" & $sApp & "\InstallPath", "") If NOT FileExists($sInstallPath & "\AcroRD32.exe") Then $sInstallPath = "" $i += 1 Wend If $sInstallPath = "" Then Return SetError(1, 0, 0) Return $sInstallPath EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
iamtheky Posted March 10, 2015 Share Posted March 10, 2015 but requires that the program has already been run once good find, that has been my go to for so long i never fully explored its edge cases. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 (edited) If you need path to default app for ,pdf, it's a different kettle of fish... $ext = ".pdf" $DefaultApp = RegRead("HKEY_CLASSES_ROOT64\" & $ext, "") $DefaultAppPath = RegRead("HKEY_CLASSES_ROOT64\" & $DefaultApp & "\shell\open\command", "") ConsoleWrite($DefaultAppPath & @LF) Edited March 11, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Tripredacus Posted March 11, 2015 Share Posted March 11, 2015 A better solution might well be to use ShellExecute which allows Windows to use the default application for the passed file type rather than Run - that way the location of that app is moot. My responses to this thread were purely based on the question as asked. Mike had not mentioned what this path was being used for, so I decided to look at his other threads. It seems the reason for acquiring the path to Acrord32 is because he needs to pass a parameter to it, /A page=... Can ShellExecute pass a parameter to the application that is launching the file? Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
iamtheky Posted March 11, 2015 Share Posted March 11, 2015 Can ShellExecute pass a parameter to the application that is launching the file? You would have to be able to determine which application shellexecute is going to use to launch the file and then determine if the argument is suitable for that exe, right? And if you have that info prior to shellexecute might as well just run it. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Tripredacus Posted March 12, 2015 Share Posted March 12, 2015 Ah ok, so in a round-about way, I see how your answer can be correct. If AcroRd32 is the default application for opening a PDF, you could use ShellExecute on the PDF and pass the parameter along with it. This way, the path to AcroRd32 is not needed by the script because you are relying on Windows to do that work for you. Twitter | MSFN | VGCollect 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