1 Attachment(s)
file-open-find-exe application
hello, here a little example how to start an *.exe file with thinair.
perhaps somebody find this one useful.
Code:
' Empty GUI script created on 12-02-2009 21:26:20 by (ThinAIR)
Uses "console", "OS", "FILE"
Function GetWinHandle (ByVal hInstance As Long) As Long
Local hwndTemp As Long
Local idProc As Long
Local GetParent As Long
If hwndTemp = FILE_Open("", "") Then
Function = hwndTemp
End If
End Function
Function TBMAIN() As Long
Local hInst As Long
Local hwndApp As Long
Local szCaption As ASCIIZ * 256
hInst = OS_ShellExecute("open","winword", "","D:\Programme2\Microsoft Office\Office\winword.exe", 4)
hInst = OS_ShellExecute("open", "calc", "", "c:\windows\system32\calc.exe",4)
SLEEP 1000
hWndApp = GetWinHandle(hInst)
If hwndApp <> %NULL Then
GetWindowText(hwndApp, szCaption, SIZEOF(szCaption))
End If
End Function
this example starts for my desktop-pc: word (winword.exe) and calculator (calc.exe) without any problems and works fine for me. you only have to choose and name your directory for wished starting application. I have forgotten this little example I have built some month before and didn't find it anymore ;)
best regards, frank
Re: file-open-find-exe application
Thanks for sharing these nice little samples.
Re: file-open-find-exe application
wow, many thanks for these few but fantastic lines too, simply great! :)
tom
Re: file-open-find-exe application
Just a note on OS_ShellExecute and OS_Shell
OS_shellExecute main intent is to open files with specific commands like "open" or "print". Imagine for example you want to open a PDF file or just want to print a PDF maybe without having Acrobat on screen. OS_ShellExecute mimic more or less the commands you can see on a file while you right click on it.
OS_Shell main intent is to execute applications or operating system commands (like DIR in command prompt)
Here below an OS_Shell example that opens calc.exe from its native windows directory (it can vary from computer to computer so it is better to use OS_GetSpecialFolder to identify it if it is a special operating system folder), gets the process id of the executed application and waits for a key press. Process will be forced to be killed after that.
Ciao
Eros
Code:
Dim someArray(10) As Long
PrintL SIZEOF(someArray)
Dim sApplicationName As String = "calc.exe"
Dim sApplication As String = OS_GetSpecialFolder(%CSIDL_SYSTEM) & sApplicationName
Dim pID As Long
'---Execute application in async way
pID = OS_Shell(sApplication, %OS_WNDSTYLE_NORMAL, %OS_SHELL_ASYNC)
PrintL sApplicationName & " has been executed. Its Program ID is " & pID
PrintL "---Press a key to kill " & sApplicationName & "---"
WaitKey
'---Now kill the process using its process id
OS_ProcessKillById(pID)
Re: file-open-find-exe application
hi eros, thank you for these infos and your example!
do me a favour please with your last sending example ? try to use
a) "winword.exe"
b) "regedit.exe"
what result will you get ?
I cannot run neither winword nor regedit to start with your example.
frank
Re: file-open-find-exe application
Well, it depends on what directory that applications are installed ;)
For example RegEdit.exe is not in system directory but in windows directory so in the above example just change
from this
[code=thinbasic]Dim sApplicationName As String = "calc.exe"
Dim sApplication As String = OS_GetSpecialFolder(%CSIDL_SYSTEM) & sApplicationName[/code]
to this (changed appliucation name and spcial folder equate)
[code=thinbasic]Dim sApplicationName As String = "regedit.exe"
Dim sApplication As String = OS_GetSpecialFolder(%CSIDL_WINDOWS) & sApplicationName[/code]
and all will work
On Winword.exe you have to do the same but remember that the Programs folder is not the same for all computers but it can vary for location and for operating system language. Equate for Programs folder is "%CSIDL_PROGRAMS"
See equates in help please. It is not something invented by thinBasic but just Microsoft standard documentation:
http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb762203(VS.85).aspx
So always use OS_GetSpecialFolder ad you will be sure to get correct operating system special folder otherwise your script will work in a computer but (maybe) not when used into another computer.
Eros
Re: file-open-find-exe application
Eros I think Franks problem is he isn't installing software in the special folders as you would normally.
"D:\Programme2\Microsoft Office\Office\winword.exe"
Re: file-open-find-exe application
In that case he has to enter full path manually exactly like he did in his example.
I just wanted to show another way to execute process.
Ciao
Eros
Re: file-open-find-exe application
Hi Frank,
you could do this way, but you always must make sure the Excel is visible!
Otherwise you will send keys to other window which is very dangerous.
You could for example use WIN_FindByTitle in WHILE loop to wait for Excel to appear, then use WIN_SetForeground, and after this try to pass the keys.
Re: file-open-find-exe application
hello petr.
perhaps you can check this version, if it's more elegant ? ;)
Code:
' Empty GUI script created on 12-19-2009 18:25:02 by frank (ThinAIR)
'-- test it!
Uses "ui", "os", "console"
Dim startingApp,f As Long
OS_ShellExecute ( "open", "excel.exe", "", "", %OS_WNDSTYLE_NORMAL )
startingApp = WIN_GetActive
WIN_SetForeground(startingApp)
Do While startingApp = %TRUE
WIN_FindByTitle("Excel", %WIN_FINDTITLESTART) 'f=
Loop
PrintL,"excel found! " + Str$(startingApp)
SendKeys ("{ENTER}1234567 898238 4422.58 8934 Angelina Jolie{ENTER},12")
WaitKey
'-- you can try to use alternative --------------------------------------
'OS_ShellExecute ( "open", "winword.exe", "", "", %OS_WNDSTYLE_NORMAL )
'SendKeys ("1242678 898238 4422.58 8934 {ENTER},22")
'------------------------------------------------------------------------
nice day, thanks, frank lion"ice"head :)
Re: file-open-find-exe application
Hi Frank,
no :unguee:
Seriously - just simply read the documentation please. WIN_GETACTIVE returns windows handle, 32 bit number. So the probability it will ever equal %TRUE is 1:4294967295.
Then I said you should wait for the window, while you tried to get the handle immediately after sending execute command.
The while loop gets ignored by script, because handle will mostly not equal to %TRUE.
Code:
WIN_FindByTitle("Excel", %WIN_FINDTITLESTART)
Even on your screenshot the window starts "Microsoft Excel", so code above would never find excel window.
Huuu, I am evil Petr, am I not :diablo:
Here is something closer to what you probably want to achieve :):
Code:
Uses "ui", "os", "console"
Dim excelHandle As DWord
OS_ShellExecute ( "open", "excel.exe", "", "", %OS_WNDSTYLE_NORMAL )
Do
excelHandle = WIN_FindByTitle("Excel", %WIN_FINDTITLECONTAIN)
Loop Until excelHandle <> 0
WIN_SetForeground(excelHandle)
' -- Give excel time to setup spread sheet
SLEEP 2000
PrintL,"excel found! " + Str$(excelHandle)
SendKeys ("{ENTER}1234567 898238 4422.58 8934 Angelina Jolie{ENTER},12")
WaitKey
Do you plan to write any particular program for the library maybe? Then COM should be safer way comparing to simulating clicks.