Sign in to follow this  
Followers 0
Diana (Cda)

Open a file type with a different program not set as default in Win?

9 posts in this topic

I've googled on AutoIt solutions and have found several posts in the forum re opening files, but nothing comes up that resolves the problem of getting a file, _any_ file, of a certain type to be opened by a program we designate. FileOpen comes up but it doesn't seem to handle file types, per se. It seems to be something you would use to open a very specific file since the filepath needs to be listed in the FileOpen script.

Specifically, I'm dealing with PDFs. Adobe Acrobat is set as my default PDF handler. I'd like to have an AU3 made into an executable take over the task of opening PDFs by a freeware reader instead but keeping the default PDF app as Acrobat via Windows file association. That way, Acrobat could continue to be used by my PDF creator when I create the files (which I do many, many times a week) - yet when I want to just access the PDFs to read, this would mean the quicker PDF reader of my choice could be used. The otherwise excellent freeware PDF creator doesn't have the option of determining which app is used to open the newly created PDFs.

If, however, I could have an AU3 workaround that would control how to open PDFs, then I could convert that script into an executable and associate the exe with PDFs instead of a particular app.

Anyone know how this type of thing can be done? And, if yes, what command could be used?

Thanks. :huh2:

Share this post


Link to post
Share on other sites



Have a look at and the Example to associate a filetype with your program. But, I'm sure the freeware PDF reader has an option to associate .PDF with that program e.g SumatraPDF can!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Does this PDF reader accept command line arguments? Even if it doesn't, it shouldn't be too hard to come up with AutoIt code to have it open the PDF file.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I tried this with FoxIt Reader (free) from my desktop.

$open = FileOpenDialog("Open A PDF", @DesktopDir, "PDF Files (*.pdf)", 1)
run (@DesktopDir & "\FoxitReaderPortable\FoxitReaderPortable.exe " & '"' & $open & '"')

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi,

Yeah, this one is a complicated one.

Guinness, the issue and solution do not involve associating a file type. On the contrary, this is exactly what I must avoid. The freeware PDF creator program is excellent but there is no option anywhere on determining a separate means of opening a file that does not involve what has been associated via Windows. That's the whole problem. So the ShellFile() option will not work for this situation.

somdcomputerguy, yes. That's what I am hoping for and is exactly what prompted this thread <g>.

The problem is that the creator relies on what is determined by Windows file association on which program to use when creating the PDFs. Acrobat is needed for this step without fail. However, once the file creation is done with, have to manually open all PDFs via right-click and choosing the PDF reader of choice. Acrobat is definitely not needed here. Over time, determined that leaving Acrobat instead of reader as default was best since if I associate the reader to PDF files instead it's tons more hassle. In the latter, I must then close all newly created files that come up in the reader, navigate all over the hdd to the destination folder and open again with Acrobat to finish creating/editing it.

I can't win.

If, however, Acrobat is set as default, but I "bypass" this by associating PDFs with an AutoIt exe with pertinent commands, Acrobat will _still _ be launched automatically after a file>print>pdf creation is done in Firefox, but AutoIt will allow me to open all PDFs on the hdd with the pdf reader of choice afterwards.

Thanks. :huh2:

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Gotacha... I tried this bit of code and registered a non-existent extension to the executable and it worked as you want. Thus, just associate PDFs to it and you are all set. In it you can create a Gui and launch the PDF with your choice of readers.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$pdfPath = $CmdLine[1]

$Form1 = GUICreate("Select", 121, 111, 192, 124)
$Button1 = GUICtrlCreateButton("Foxit", 16, 16, 91, 25)
$Button2 = GUICtrlCreateButton("Reader #2", 16, 56, 91, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            run (@DesktopDir & "\FoxitReaderPortable\FoxitReaderPortable.exe " & '"' & $pdfPath & '"')
        Case $Button2
            ; run program of your choice
    EndSwitch
WEnd

The line: "$pdfPath = $CmdLine[1]" is the key. It reads the path of the PDF that opened the executable.

Edited by sleepydvdr

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Gotacha... I tried this bit of code and registered a non-existent extension to the executable and it worked as you want. Thus, just associate PDFs to it and you are all set. In it you can create a Gui and launch the PDF with your choice of readers.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$pdfPath = $CmdLine[1]

$Form1 = GUICreate("Select", 121, 111, 192, 124)
$Button1 = GUICtrlCreateButton("Foxit", 16, 16, 91, 25)
$Button2 = GUICtrlCreateButton("Reader #2", 16, 56, 91, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            run (@DesktopDir & "\FoxitReaderPortable\FoxitReaderPortable.exe " & '"' & $pdfPath & '"')
        Case $Button2
            ; run program of your choice
    EndSwitch
WEnd

The line: "$pdfPath = $CmdLine[1]" is the key. It reads the path of the PDF that opened the executable.

Hi, thank you! I do sincerely apologize for the delay in responding. I tried this after you posted and it didn't work and then I got caught up with a new work contract. It's only till now that I've been able to return to this.

I hope the occasional Autoit installation woes I have aren't what is wrong here. I don't upgrade often; and when I do, I get the standalone version and just empty out the Autoit "install" folder and then dump the newer files in. It's just that Include scripts also sometimes get upgraded and I only overwrite these when absolutely necessary as blanket overwrites often knock out a lot of my older scripts, which is worse than having the occasional trouble with a new script, as this might potentially be <sigh>. So, the challenge here is trying to figure out if the error I'm getting is a version issue or a script boo-boo:

---------------------------
AutoIt Error
---------------------------
Line 13  (File "...Desktop\PDF open.au3"):

$pdfPath = $CmdLine[1]
$pdfPath = ^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
---------------------------
OK   
---------------------------

Does this seem like an error related to an old or conflicting file between versions or is this an actual array code boo-boo, anyone know? $CmdLine[1] seems to be tripping things up, at any rate.

Thanks! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi, thank you! I do sincerely apologize for the delay in responding. I tried this after you posted and it didn't work and then I got caught up with a new work contract. It's only till now that I've been able to return to this.

I hope the occasional Autoit installation woes I have aren't what is wrong here. I don't upgrade often; and when I do, I get the standalone version and just empty out the Autoit "install" folder and then dump the newer files in. It's just that Include scripts also sometimes get upgraded and I only overwrite these when absolutely necessary as blanket overwrites often knock out a lot of my older scripts, which is worse than having the occasional trouble with a new script, as this might potentially be <sigh>. So, the challenge here is trying to figure out if the error I'm getting is a version issue or a script boo-boo:

---------------------------
AutoIt Error
---------------------------
Line 13  (File "...Desktop\PDF open.au3"):

$pdfPath = $CmdLine[1]
$pdfPath = ^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
---------------------------
OK   
---------------------------

Does this seem like an error related to an old or conflicting file between versions or is this an actual array code boo-boo, anyone know? $CmdLine[1] seems to be tripping things up, at any rate.

Thanks! ;)

I can see from the error message that you are running the .au3 script without compiling. Therefore, you are calling autoit.exe instead of your actual script. To make it work, you must compile the script. Furthermore, it doesn't work by running the executable directly. You must associate .pdf with it and double click the pdf to start up the exe.

Hope this helps! :)

Edited by sleepydvdr

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The latest version of the Foxit PDF Reader (http://www.foxitsoftware.com, free, ver. 5.0) has command line support.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0