erix Posted November 9, 2007 Share Posted November 9, 2007 Hello How can i open a file with a specified exe. For example i'd like to have a button who open config.txt with notepad and an other button who open config.txt with word (for example) I try with shellexecute but i don't find where to put the exe file and the txt file in the command Thanks Eric Link to comment Share on other sites More sharing options...
Monamo Posted November 9, 2007 Share Posted November 9, 2007 (edited) HelloHow can i open a file with a specified exe.For example i'd like to have a button who open config.txt with notepad and an other button who open config.txt with word (for example)I try with shellexecute but i don't find where to put the exe file and the txt file in the commandThanksEricEdit accordingly based upon the path to your Word executable:CODE#include <GUIConstants.au3>$file = "C:\Config.txt"GUICreate("Open With...",400,200)$buttonNotepad = GUICtrlCreateButton("Open with Notepad",10,10,150,20)$buttonWord = GUICtrlCreateButton("Open with Word",10,40,150,20)GUISetState (@SW_SHOW)While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $buttonNotepad Run("C:\WINDOWS\NOTEPAD.EXE " &$file) Case $msg = $buttonWord Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE " &$file) ; edit path based upon your version of Word EndSelectWendEdit: grammar Edited November 9, 2007 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
erix Posted November 9, 2007 Author Share Posted November 9, 2007 Thank you Monamo It works But if for example Word is not on the same path on different machine. I have an other button for choose the path of the WinWord.exe The path is saved after. In this case the path is not like this : Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE " &$file) But like this Run($path & $file) But Autoit doesn't accept Run($path & $file) Thanks Link to comment Share on other sites More sharing options...
Jonniemac315 Posted November 9, 2007 Share Posted November 9, 2007 Thank you MonamoIt worksBut if for example Word is not on the same path on different machine.I have an other button for choose the path of the WinWord.exeThe path is saved after.In this case the path is not like this :Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE " &$file)But like thisRun($path & $file)But Autoit doesn't accept Run($path & $file)ThanksTry Run ("" & $path & $file) Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 9, 2007 Share Posted November 9, 2007 How about: $sFile = "C:\Temp\DingleBerries.doc" ShellExecute($sFile, "", "", "Open") If the file type has an application association already, that should be all you need to get it opened. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 9, 2007 Moderators Share Posted November 9, 2007 Try Run ("" & $path & $file)Not quite ...Run('"' & $sPathToExe & '" "' & $sFileToRun & '"') Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
erix Posted November 9, 2007 Author Share Posted November 9, 2007 Try Run ("" & $path & $file)Thanks but it doesn't workIf the file type has an application association already, that should be all you need to get it opened.Yes of course but here i want to choose the application.Run('"' & $sPathToExe & '" "' & $sFileToRun & '"')Thanks too but it doesn't work Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 9, 2007 Share Posted November 9, 2007 Run('"' & $sPathToExe & '" "' & $sFileToRun & '"') This should work as long as $sPathToExe doesn't contain any double quotes around it already. Link to comment Share on other sites More sharing options...
Monamo Posted November 9, 2007 Share Posted November 9, 2007 (edited) Thank you Monamo It works But if for example Word is not on the same path on different machine. I have an other button for choose the path of the WinWord.exe The path is saved after. In this case the path is not like this : Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE " &$file) But like this Run($path & $file) But Autoit doesn't accept Run($path & $file) Thanks OK, here ya go. This variation should open the file in Word no matter which computer you run it on, assuming that SOME version of word is on it (as best I can tell ). It queries the registry for the default Word document handler and uses that for the "Word" button. CODE#include <GUIConstants.au3> GUICreate("Open With...",400,200) $file = "C:\Config.txt" $sNotepadPath = @WindowsDir &"\notepad.exe" $buttonNotepad = GUICtrlCreateButton("Open with Notepad",10,10,150,20) $buttonWord = GUICtrlCreateButton("Open with Word",10,40,150,20) $sWordPath = _GetWordPath() GUISetState (@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $buttonNotepad Run($sNotepadPath & " " &$file) Case $msg = $buttonWord Run($sWordPath & " " &$file) EndSelect Wend Func _GetWordPath() $classRoot = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document\CurVer","") $installedPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\" & $classRoot & "\shell\Open\command","") $wordPathParsing = StringSplit($installedPath,'"') For $i= 1 To $wordPathParsing[0] If FileExists($wordPathParsing[$i]) Then $installedPath = $wordPathParsing[$i] ExitLoop EndIf Next If FileExists($installedPath) Then Return $installedPath Else MsgBox(48,"Error:","Unable to determine path to Microsoft Word executable on this system.") GUICtrlSetState($buttonWord,$GUI_DISABLE) EndIf EndFunc Edit: Code correction to parse out parameters passed at the end of the registry entry for word path Edited November 9, 2007 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
erix Posted November 9, 2007 Author Share Posted November 9, 2007 (edited) That's works with notepad.exe but with winword.exe i have an error message after the launch who said :(Sorry it's a french-english translation.)Impossible to open the documentTry this operation* In the file menu, click open for open the document* Verify than the document have a .doc extension(c:\Documents)Of course in the example i have a txt file but i try with a doc file too.Thanks Edited November 9, 2007 by erix Link to comment Share on other sites More sharing options...
Monamo Posted November 9, 2007 Share Posted November 9, 2007 (edited) That's works with notepad.exe but with winword.exe i have an error message after the launch who said : (Sorry it's a french-english translation.) Impossible to open the document Try this operation * In the file menu, click open for open the document * Verify than the document have a .doc extension (c:\Documents) Of course in the example i have a txt file but i try with a doc file too. ThanksTwo things:I posted a correction to my code in the post above to handle extra parameters stored in the "command" path in the registry for opening Word docsThe error you mention sounds like an issue with spaces in the file path. Try the code below when defining your text file path (insert the "real" path accordingly). Rather than deal with all the confusion resulting from trying to make the quotation marks (") part of the path, this will force a set of quotes at the beginning and end of the path, hopefully taking care of your problem.$file = Chr(34) &"C:\Documents and Settings\User\Desktop\config.txt" &Chr(34) Edited November 9, 2007 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 9, 2007 Share Posted November 9, 2007 This opens a PowerPoint presentation in OpenOffice.org 2.2, even if the file type is registered to MS PowerPoint, and regardless of where OOo was installed: ; Read path from the registry $sOOoReg = "HKEY_CLASSES_ROOT\Applications\OpenOffice.org 2.2\shell\edit\command" $sOOoOpen = RegRead($sOOoReg, "") ; Trim out just the path $sOOoOpen = StringReplace(StringLeft($sOOoOpen, StringInStr($sOOoOpen, "-o") - 1), '"', '') $sFile = '"' & @ScriptDir & '\Test.ppt"' ; Run it ShellExecute($sOOoOpen, $sFile, @WorkingDir, "Open") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
erix Posted November 12, 2007 Author Share Posted November 12, 2007 This opens a PowerPoint presentation in OpenOffice.org 2.2, even if the file type is registered to MS PowerPoint, and regardless of where OOo was installed: ; Read path from the registry $sOOoReg = "HKEY_CLASSES_ROOT\Applications\OpenOffice.org 2.2\shell\edit\command" $sOOoOpen = RegRead($sOOoReg, "") ; Trim out just the path $sOOoOpen = StringReplace(StringLeft($sOOoOpen, StringInStr($sOOoOpen, "-o") - 1), '"', '') $sFile = '"' & @ScriptDir & '\Test.ppt"' ; Run it ShellExecute($sOOoOpen, $sFile, @WorkingDir, "Open") Thank you PsaltyDS and Monamo for this code. 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