Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: file-open-find-exe application

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    file-open-find-exe application

    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
    Attached Images Attached Images
    Last edited by ErosOlmi; 05-02-2019 at 21:28.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2

    Re: file-open-find-exe application

    Thanks for sharing these nice little samples.

  3. #3

    Re: file-open-find-exe application

    wow, many thanks for these few but fantastic lines too, simply great!
    tom

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    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

    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)
    
    Last edited by ErosOlmi; 05-02-2019 at 21:29.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    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
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    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"
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: start excel :)

    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
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by ErosOlmi; 05-02-2019 at 21:29.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    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.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 2 12 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •