VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Register when a program is runned Posted by QuesadaR on 15 Oct 2003 at 7:26 AM
I need to register when internet explorer is loaded and when it is closed in a .txt file from Visual basic.
Report
Re: Register when a program is runned Posted by PavlinII on 29 Oct 2003 at 1:16 PM
: I need to register when internet explorer is loaded and when it is closed in a .txt file from Visual basic.
:
Hi, there exist at least two ways..
1)Your app will catch every executed exe file and if it recognized IE (or anything), will make log entry:
Add your app to registry:
HKEY_CLASSES_ROOT\exefile\Shell\Open\Command
There exist value "%1" %* and you have to replace it with "C:\myPath\myApp.exe" "%1" %*
But you should more replace subkeys lnkfile; (comfile;) batfile and piffile if enyone run it from these files..
And in your App will be enoug module with one Main() sub and storing sub
Public Sub Main()
Dim iFile As Integer
  'Command gives you arguments - represented by "%1" %* in reg
  'If executed program is IE (or any)[/gray]
  If Instr(Command, "\Internet Explorer\IExplore.exe")=0 Then
    iFile = FreeFile()
    Open "C:\myPath\IElog.txt" For Append as #iFile
    Print #iFile, CStr(Now) & vbTab & Command & vbTab & "IE Started"
    Close #iFile        
    Shell Command, vbNormalFocus    'Start app
    WaitForIEClose                  'I'll describe this in part 2
  Else
    Shell Command, vbNormalFocus    'Start app
    End                             'I do not care about other apps
  End If

You should prevent running your app several times (on severals IE windows) by finding your app in task - I'll show in part2
2) Your app will strat at windows startup and run still... and run and don't do anything till IE will be found...
Private Const ieNAME = "IdoNOTuseIT-iDOnotKNOW"

Public Sub Main()
Dim bRunning As Boolean
Do
  If FindWindow(vbNullString, ieNAME) <> 0 Then
    'IE is running
    If bRunning = False Then
      bRunning = True
      Open "C:\myPath\IElog.txt" For Append as #iFile
      Print #iFile, CStr(Now) & vbTab & "IE Started"
      Close #iFile        
    End If
  Else
    If bRunning = True Then
      bRunning = False
      Open "C:\myPath\IElog.txt" For Append as #iFile
      Print #iFile, CStr(Now) & vbTab & "IE Closed"
      Close #iFile        
    End If
  End If
  DoEvents
Loop
End Sub

In this case, you'll not know about more running windows of IE but FindWindow return hwnd of windows and if you make list of them... you will.

Hope this will help you

PavlinII

Report
Re: Register when a program is runned Posted by QuesadaR on 11 Nov 2003 at 8:08 AM
: : I need to register when internet explorer is loaded and when it is closed in a .txt file from Visual basic.
: :
: Hi, there exist at least two ways..
: 1)Your app will catch every executed exe file and if it recognized IE (or anything), will make log entry:
: Add your app to registry:
: HKEY_CLASSES_ROOT\exefile\Shell\Open\Command
: There exist value "%1" %* and you have to replace it with "C:\myPath\myApp.exe" "%1" %*
: But you should more replace subkeys lnkfile; (comfile;) batfile and piffile if enyone run it from these files..
: And in your App will be enoug module with one Main() sub and storing sub
:
Public Sub Main()
: Dim iFile As Integer
:   'Command gives you arguments - represented by "%1" %* in reg
:   'If executed program is IE (or any)[/gray]
:   If Instr(Command, "\Internet Explorer\IExplore.exe")=0 Then
:     iFile = FreeFile()
:     Open "C:\myPath\IElog.txt" For Append as #iFile
:     Print #iFile, CStr(Now) & vbTab & Command & vbTab & "IE Started"
:     Close #iFile        
:     Shell Command, vbNormalFocus    'Start app
:     WaitForIEClose                  'I'll describe this in part 2
:   Else
:     Shell Command, vbNormalFocus    'Start app
:     End                             'I do not care about other apps
:   End If

: You should prevent running your app several times (on severals IE windows) by finding your app in task - I'll show in part2
: 2) Your app will strat at windows startup and run still... and run and don't do anything till IE will be found...
:
Private Const ieNAME = "IdoNOTuseIT-iDOnotKNOW"
: 
: Public Sub Main()
: Dim bRunning As Boolean
: Do
:   If FindWindow(vbNullString, ieNAME) <> 0 Then
:     'IE is running
:     If bRunning = False Then
:       bRunning = True
:       Open "C:\myPath\IElog.txt" For Append as #iFile
:       Print #iFile, CStr(Now) & vbTab & "IE Started"
:       Close #iFile        
:     End If
:   Else
:     If bRunning = True Then
:       bRunning = False
:       Open "C:\myPath\IElog.txt" For Append as #iFile
:       Print #iFile, CStr(Now) & vbTab & "IE Closed"
:       Close #iFile        
:     End If
:   End If
:   DoEvents
: Loop
: End Sub

: In this case, you'll not know about more running windows of IE but FindWindow return hwnd of windows and if you make list of them... you will.
:
: Hope this will help you
:
: PavlinII
:
:
Thanks a bunch for your help. I have used your code but i'm having several problems. First of all you wrote 2 Mains sub or 2nd one is other sub???.

==>> 1st Main sub doubts
On the first one on line [ If InStr(Command, .... ] command is returning nothing, due to this [ Shell Command ... ] makes fall the system.
Regarding [ WaitForIEClose... ] there is nothing on 2nd part.

==>> 2nd Main sub doubts
Is ieName the variable for the program to search for???
FindWindow is a function you wrote? because It doesn't work for me


Thanks again for all your help... I'll be waiting your comments.

Report
Re: Register when a program is runned Posted by PavlinII on 11 Nov 2003 at 12:43 PM
: : : I need to register when internet explorer is loaded and when it is closed in a .txt file from Visual basic.
: : :
: : Hi, there exist at least two ways..
: : 1)Your app will catch every executed exe file and if it recognized IE (or anything), will make log entry:
: : Add your app to registry:
: : HKEY_CLASSES_ROOT\exefile\Shell\Open\Command
: : There exist value "%1" %* and you have to replace it with "C:\myPath\myApp.exe" "%1" %*
: : But you should more replace subkeys lnkfile; (comfile;) batfile and piffile if enyone run it from these files..
: : And in your App will be enoug module with one Main() sub and storing sub
: :
Public Sub Main()
: : Dim iFile As Integer
: :   'Command gives you arguments - represented by "%1" %* in reg
: :   'If executed program is IE (or any)[/gray]
: :   If Instr(Command, "\Internet Explorer\IExplore.exe")=0 Then
: :     iFile = FreeFile()
: :     Open "C:\myPath\IElog.txt" For Append as #iFile
: :     Print #iFile, CStr(Now) & vbTab & Command & vbTab & "IE Started"
: :     Close #iFile        
: :     Shell Command, vbNormalFocus    'Start app
: :     WaitForIEClose                  'I'll describe this in part 2
: :   Else
: :     Shell Command, vbNormalFocus    'Start app
: :     End                             'I do not care about other apps
: :   End If

: : You should prevent running your app several times (on severals IE windows) by finding your app in task - I'll show in part2
: : 2) Your app will strat at windows startup and run still... and run and don't do anything till IE will be found...
: :
Private Const ieNAME = "IdoNOTuseIT-iDOnotKNOW"
: : 
: : Public Sub Main()
: : Dim bRunning As Boolean
: : Do
: :   If FindWindow(vbNullString, ieNAME) <> 0 Then
: :     'IE is running
: :     If bRunning = False Then
: :       bRunning = True
: :       Open "C:\myPath\IElog.txt" For Append as #iFile
: :       Print #iFile, CStr(Now) & vbTab & "IE Started"
: :       Close #iFile        
: :     End If
: :   Else
: :     If bRunning = True Then
: :       bRunning = False
: :       Open "C:\myPath\IElog.txt" For Append as #iFile
: :       Print #iFile, CStr(Now) & vbTab & "IE Closed"
: :       Close #iFile        
: :     End If
: :   End If
: :   DoEvents
: : Loop
: : End Sub

: : In this case, you'll not know about more running windows of IE but FindWindow return hwnd of windows and if you make list of them... you will.
: :
: : Hope this will help you
: :
: : PavlinII
: :
: :
: Thanks a bunch for your help. I have used your code but i'm having several problems. First of all you wrote 2 Mains sub or 2nd one is other sub???.
:
: ==>> 1st Main sub doubts
: On the first one on line [ If InStr(Command, .... ] command is returning nothing, due to this [ Shell Command ... ] makes fall the system.
: Regarding [ WaitForIEClose... ] there is nothing on 2nd part.
:
: ==>> 2nd Main sub doubts
: Is ieName the variable for the program to search for???
: FindWindow is a function you wrote? because It doesn't work for me
:
:
: Thanks again for all your help... I'll be waiting your comments.
:
:
OK, step by step...
Yes, I wrote 2 Main... 2 different each other independent (two projects).. It were 2 different ways how to get simillar result..

If InStr(Command, "\Internet Explorer\IExplore.exe")<>0 Then
(Sorry, my mistake - I exchanged returns from InStr and StrComp in my mind )

Shell: Inside variable Command are given parameters. (%1, %* passes parameters to your app and you can find them in Command)... Make sure, that there is correct information... Try to run "myApp.exe pArAm1 param2 -testParam3" and look if
MsgBox Command
in the beginning of your app will show you "pArAm1 param2 -testParam3"... It should do so... And then try to run any app (ie) and check if you'll see something like "C:\Program Files\ie\iexplorer.exe".. If you'll not, there is mistake somewhere in registry...

Now about WaitForIEClose:
It's nearly the same like second Main... Just let out some unneccesary lines... (I described the way how to manage it.. never mind)
Private Const ieNAME = "IdoNOTuseIT-iDOnotKNOW"
Public Sub WaitForIEClose()
Do
  If Not FindWindow(vbNullString, ieNAME) <> 0 Then
'You can omit this
'    'IE is running
'    If bRunning = False Then
'      bRunning = True
'      Open "C:\myPath\IElog.txt" For Append as #iFile
'      Print #iFile, CStr(Now) & vbTab & "IE Started"
'     Close #iFile        
'    End If
'  Else
'    If bRunning = True Then
'      bRunning = False
      Open "C:\myPath\IElog.txt" For Append as #iFile
      Print #iFile, CStr(Now) & vbTab & "IE Closed"
      Close #iFile        
      Exit Do    'You don't need to wait anymore
    End If
  End If
  DoEvents    'Let the system do what it needs
Loop
End Sub


Yes, you're finding window by title.. And here it's ieName... My Windows calculator has Kalkula&#269;ka... I don't know what has ie...

FindWindow is a standard API function...
Check Menu/Add-Ins/Add-In Manager.../VB 6 API Viewer (and Load On StartUp)
Run Menu/Add-Ins/ApiViewer and there are declarations of ALL API function, constants and datatypes.. (I don't remeber if that list is loaded on first run but I suggest you to do this: File/Load text file... and choose ..\MS Visual Studio\Common\Tools\WinApi32.txt... and then File/Convert Text to database... (It'll start much faster)... And at last check View/Load Last File)
If there exists any reason why thiw will not work to you, write this somewhere at the beginning of module...
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


If you have more questions, ask..

PavlinII
Report
Re: Register when a program is runned Posted by QuesadaR on 12 Nov 2003 at 12:41 PM
Thanks a lot !!!

I adjust your code and it is doing exactly what i was trying.

Thanks again.

Roy Q>



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.