Help - Search - Members - Calendar
Full Version: AutoIt Script Help
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Amerigo
Dear Sir or Ma'am,

Perhaps you can help with this script?
I want it to open WordWeb whether or not it is already in the system tray. I use Responding Heads to run AutoIt Scripts. If you can convert this to VB for RH to use without AutoIt, that would be even better.

Opt("WinTitleMatchMode",2)
If WinActive("WordWeb") Then ~~~(this probably won't work because its not active if in the system tray?)
Send("^%W") ~~~(cntl+alt+W)
Else run "C:\Program Files\WordWeb\wweb32.exe" ~~~(error here. Run command???)
Sleep(10000) ~~~(time it takes to load???)
Send("^%W")
End If

Thank you so much,
Amerigo
ReDucTor
http://www.autoitscript.com/autoit3/docs/f...ocessExists.htm

Try process exists instead

CODE
If ProcessExists ("wweb32.exe") == 0 Then
    run("C:\Program Files\WordWeb\wweb32.exe")
    sleep(100)
EndIf
Send("^!w")
MHz
You have a tray executable and a no tray executable and also window states to consider. I chose the cover all known scenarios.
CODE

; path to webword directory
$ww_path = @ProgramFilesDir & '\WordWeb'
; WordWeb NoTray executable
$exe_notray = 'wwnotray.exe'
; WordWeb Tray executable
$exe_tray = 'wweb32.exe'
; main window title
$title = '[CLASS:TTHeDi]'

Select
Case WinActive($title)
; nothing to do
Exit
Case ProcessExists($exe_notray) And Not WinActive($title)
; restore and activate the window
WinSetState($title, '', @SW_RESTORE)
WinActivate($title)
Case ProcessExists($exe_tray) And Not WinActive($title)
; run tray exe to activate the window
_RunWordWeb($exe_tray)
Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_tray)
EndSelect

Exit

Func _RunWordWeb($file)
; check to ensure the file to run is available, else return if not
If Not FileExists($ww_path & '\' & $file) Or $file = '' Then
Return SetError(1)
EndIf
Switch $file
Case $exe_notray
; run no tray exe to show window
Run('"' & $ww_path & '\' & $exe_notray & '"')
; wait for the window and then activate it
WinWait($title, '', 5)
WinActivate($title)
Case $exe_tray
; run instances of tray exe until the window is active
Do
Run('"' & $ww_path & '\' & $exe_tray & '"')
If Not ProcessExists($exe_tray) Then
; something is incorrect so return from this function
Return SetError(2)
Else
Sleep(250)
; activate the window
WinActivate($title)
EndIf
Until WinActive($title)
EndSwitch
EndFunc

Starting a 2nd instance of the tray process seems to bring up the window so I chose that idea rather then the hotkey idea.

Note that the keyword "Else" likes it's own line in AutoIt3 except for "Case Else" as to your code error. Also "End If" needs to be "EndIf".

smile.gif
Amerigo
Thanks to both of you.

MHz, I like the way you think. Covering all the bases.
However, there is a glitch somewhere. I tried it with WordWeb completely off, and it worked, and worked, and worked.....
It seems to have gotten caught in a loop where it tries to keep opening WordWeb.
MHz
QUOTE (Amerigo @ Aug 14 2008, 04:53 PM) *
It seems to have gotten caught in a loop where it tries to keep opening WordWeb.

Sorry. My results are different for some reason.

This will use the Ctrl+Alt+w hotkey
CODE

; path to webword directory
$ww_path = @ProgramFilesDir & '\WordWeb'
; WordWeb NoTray executable
$exe_notray = 'wwnotray.exe'
; WordWeb Tray executable
$exe_tray = 'wweb32.exe'
; main window title
$title = '[CLASS:TTHeDi]'

Select
Case WinActive($title)
; nothing to do
Exit
Case ProcessExists($exe_notray) And Not WinActive($title)
; restore and activate the window
WinSetState($title, '', @SW_RESTORE)
WinActivate($title)
Case ProcessExists($exe_tray) And Not WinActive($title)
; run tray exe to activate the window
_RunWordWeb($exe_tray)
Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_tray)
EndSelect

Exit

Func _RunWordWeb($file)
; check to ensure the file to run is available, else return if not
If Not FileExists($ww_path & '\' & $file) Or $file = '' Then
Return SetError(1)
EndIf
Switch $file
Case $exe_notray
; run no tray exe to show window
Run('"' & $ww_path & '\' & $exe_notray & '"')
If Not @error Then
; wait for the window and then activate it
WinWait($title, '', 5)
WinActivate($title)
EndIf
Case $exe_tray
; run tray exe
Run('"' & $ww_path & '\' & $exe_tray & '"')
If Not @error Then
; wait for hidden tray icon window
WinWait('WordWeb Tray Icon', '', 5)
Sleep(500)
; if the window is not active, then use the hotkey
If Not WinActive($title) Then
WinActivate($title)
Send('^!w')
EndIf
EndIf
EndSwitch
Sleep(500)
; another attempt to activate the window if needed
If Not WinActive($title) Then
WinActivate($title)
EndIf
EndFunc

If you wish, you can run the no tray executable instead by changing the parameter of _RunWordWeb() in the Case Else part which shows a window which behave like a normal window.

before:
CODE
    Case Else
    ; no process running so choose $exe_notray or $exe_tray to run
        _RunWordWeb($exe_tray)
EndSelect

after:
CODE
    Case Else
    ; no process running so choose $exe_notray or $exe_tray to run
        _RunWordWeb($exe_notray)
EndSelect
Amerigo
It works great now. Thanks a million!
Now about that intimacy program.... smile.gif
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.