PDA

View Full Version : file-open-find-exe application



Lionheart008
02-12-2009, 23:32
hello, here a little example how to start an *.exe file with thinair.
perhaps somebody find this one useful.


' 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

Michael Hartlef
03-12-2009, 11:40
Thanks for sharing these nice little samples.

TomLebowski
03-12-2009, 14:01
wow, many thanks for these few but fantastic lines too, simply great! :)
tom

ErosOlmi
03-12-2009, 23:36
Just a note on OS_ShellExecute (http://www.thinbasic.com/public/products/thinBasic/help/html/os_shellexecute.htm) and OS_Shell (http://www.thinbasic.com/public/products/thinBasic/help/html/os_shell.htm)

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


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)

Lionheart008
04-12-2009, 00:20
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

ErosOlmi
04-12-2009, 00:45
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

Dim sApplicationName As String = "calc.exe"
Dim sApplication As String = OS_GetSpecialFolder(%CSIDL_SYSTEM) & sApplicationName

to this (changed appliucation name and spcial folder equate)

Dim sApplicationName As String = "regedit.exe"
Dim sApplication As String = OS_GetSpecialFolder(%CSIDL_WINDOWS) & sApplicationName
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 (http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?osequates.htm). 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

Michael Clease
04-12-2009, 01:32
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"

ErosOlmi
04-12-2009, 01:41
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

Lionheart008
19-12-2009, 19:55
good evening.

I would like to ask what results do you get with this little "starting application" example and if this one does work ? I only wanted to check if it's possible to start with these four lines microsofts "excel" application ? what happens with this ugly code ? I tried to make this example without path and folder specifications for wished application.


' Empty GUI script created on 12-19-2009 18:25:02 by frank (ThinAIR)
'-- test it!

Uses "ui", "os"

Dim startingApp As Long
OS_ShellExecute ( "open", "excel.exe", "", "", %OS_WNDSTYLE_NORMAL )
SendKeys ("{ENTER}1234567 898238 4422.58 8934 Diana Rigg{ENTER},12")
startingApp = WIN_GetActive

'-- alternative
'OS_ShellExecute ( "open", "winword.exe", "", "", %OS_WNDSTYLE_NORMAL )
'SendKeys ("{ENTER}1242678 898238 4422.58 8934 {ENTER},22")


for me on my notebook "excel" starts without any problems and send numbers to cell A 1. If I run this example by thinair I get this result (picture) and without using thinair for running script at another folder I get more values and numbers in cell A 1 and A 2.

take attention: look at your tb code after closing applications ! ;)

would be nice to get some feedback. I was looking for a maximal short way for this task and another way as you can see in my first post ;)

best regards, frank

Petr Schreiber
19-12-2009, 22:02
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.

Lionheart008
20-12-2009, 18:11
hello petr.

perhaps you can check this version, if it's more elegant ? ;)


' 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 :)

Petr Schreiber
20-12-2009, 23:42
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.



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 :):


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.

rossi
05-02-2019, 16:40
good evening.

I would like to ask what results do you get with this little "starting application" example and if this one does work ? I only wanted to check if it's possible to start with these four lines microsofts "excel" application ? what happens with this ugly code ? I tried to make this example without path and folder specifications for wished application.


' Empty GUI script created on 12-19-2009 18:25:02 by frank (ThinAIR)
'-- test it!

Uses "ui", "os"

Dim startingApp As Long
OS_ShellExecute ( "open", "excel.exe", "", "", %OS_WNDSTYLE_NORMAL )
SendKeys ("{ENTER}1234567 898238 4422.58 8934 Diana Rigg{ENTER},12")
startingApp = WIN_GetActive

'-- alternative
'OS_ShellExecute ( "open", "winword.exe", "", "", %OS_WNDSTYLE_NORMAL )
'SendKeys ("{ENTER}1242678 898238 4422.58 8934 {ENTER},22")


for me on my notebook "excel" starts without any problems and send numbers to cell A 1. If I run this example by thinair I get this result (picture) and without using thinair for running script at another folder I get more values and numbers in cell A 1 and A 2.

take attention: look at your tb code after closing applications ! ;)

would be nice to get some feedback. I was looking for a maximal short way for this task and another way as you can see in my first post Lucky Patcher (https://inro.in/lucky-patcher/) 9Apps (https://inro.in/9apps/) VidMate (https://inro.in/vidmate/) ;)

best regards, frank

i cant download the file zip

ErosOlmi
05-02-2019, 21:32
i cant download the file zip
There is no ZIP file attached in this thread.
Just source code.