Jump to content

Opening a file with default application...


Recommended Posts

Like I'll have some files and a combo with those files listed.

Lets say I have an .ini, some .txt files, a .jpg..

How do I like open the .jpg with the program that user uses to open .jpgs, and the text editor he uses to open an .ini, etc..

Run only works with EXE, BAT, COM, or PIF executable files.

Thanks. :D

Link to comment
Share on other sites

  • Moderators

Like I'll have some files and a combo with those files listed.

Lets say I have an .ini, some .txt files, a .jpg..

How do I like open the .jpg with the program that user uses to open .jpgs, and the text editor he uses to open an .ini, etc..

Run only works with EXE, BAT, COM, or PIF executable files.

Thanks. :D

Run('"' & $LocationAndApplication2OpenWithEXE & '" "' & $ItemLocationAndNameToOpen & '"')

Edit:

Here's an example:

$ItemLocationAndNameToOpen = @ScriptDir & '\ExampleOpenText.txt'
FileWrite($ItemLocationAndNameToOpen, 'This is how it works')
$LocationAndApplication2OpenWithEXE = @SystemDir & '\Notepad.exe'

Run('"' & $LocationAndApplication2OpenWithEXE & '" "' & $ItemLocationAndNameToOpen & '"')
Sleep(5000)
If MsgBox(36, 'Keep Open?', 'Would you like to keep the text file open?') = 7 Then
    $OptWTMM = Opt('WinTitleMatchMode', 2)
    If WinExists('ExampleOpenText') Then WinKill('ExampleOpenText')
    FileDelete($ItemLocationAndNameToOpen)
EndIf
Edited by SmOke_N

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

  • Moderators

Ignore SmOke_N he is tired.

http://www.autoitscript.com/autoit3/docs/faq.htm#6

Run(@comspec & ' /c start ' & $s_yourfile)
I thought he wanted to open it up with any, your right... don't know how I got that from default.... but mine still works :D ... just have to know what they want to open it up with (could maybe have 2 options :wacko: ).

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

Ok. Thanks very much.

This works.

Func showfiles($file)
    switch $file
        Case "gamma_setting.jpg"
            If not WinExists ("Gamma Setting") Then
                $picgui = GUICreate("Gamma Setting", 520, 240,-1,-1,-1,-1,$gui)
                GUICtrlCreatePic ( "gamma_setting.jpg", 8, 8, 506, 189 )
                $okbut = GUICtrlCreateButton ("  Ok  ", 250, 210)
                GUISetState()
            EndIf
        Case Else
            If $file == "ddcodes_readme.txt" Then
                GUICtrlSetData ( $GUIbox1, $GUItext)
            Else
                GUICtrlSetData ( $GUIbox1, FileRead($file, FileGetSize ( $file )) )
;~              MsgBox ( 0, "Sorry!", "These aren't working right yet."&@crlf&"But you should find these files somewhere in this folder."&@crlf&"For now I'll put the contents in the textbox here.", 10 )
            EndIf
            Run(@comspec & ' /c start ' & $file)
    EndSwitch
EndFunc

It's a little wierd though, you see a command prompt window flashing before the file is open.

Let's try that other method then.. brb.

Link to comment
Share on other sites

Ok...

This works great.

I just usin a gui for the pic, and the ini and txts I can just do this:

Run('"' & @SystemDir & '\Notepad.exe" "' & @ScriptDir &'\'& $file & '"')
oÝ÷ Ø­]¶©ÞßtáÌ(®K½éÛzÛ^­«­¢+ÙIÕ¸¡½µÍÁµÀìÌäì½ÍÑÉÐÌäìµÀìÀÌØí¥±°ÌäìÌäì°M]}!%¤oÝ÷ Øìµæ¡û¬x'¢×©iØ­ºÇ¬)èµêZu©mz¹Ú¶+ÞÂ+}ö=§S +mjG¬i¸­àz»h¢§ÔájÝý²z)®åzka¢è! «¬zz0Áç붬~Ú)"Ú~)^!Ú'ßÛd"~+fjG¬j|÷Þ­éÜzÚ)ºÔ®*m*íêÞnëbßÙe¶¼­«m¢®¶­se'Vâ6ö×7V2fײb33²ö27F'Bb33²fײ67&DF"fײb33²b3#²b33²fײb33c¶fÆRÂb33²b33²Â5uôDR

Thanks! :D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...