Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Run 1

Status
Not open for further replies.

ChrisWhite123

Technical User
Sep 30, 2007
6
0
0
GB
I have an application which has to run at 05:00 every morning.

At present I leave the PC on, with Attachmate Extra open, sending key (<ENTER>) every 15 seconds to keep it open until the clock says "05:".

This is not very green and requires users to go into the workplace on Saturdays and Sundays.

Can I get Attachmate to open itself? and close itself?
 
Code:
Set oExtra = CreateObject("Extra.System")
Set oSess = oExtra.Session.Open("C:\Path\Session")
Set oScr = oSess.Screen
 
To close, go to Options -> Global Preferences and turn off "Prompt for disconnection." You can use the following code or use SendKeys ("%{F4}").

Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function End_Task (TargetHwnd as long) As Integer
Declare Sub Close_Program (Window_Title as String)

GLOBAL Const GWL_STYLE = (-16)
GLOBAL Const WS_DISABLED = &H8000000
GLOBAL Const WM_CLOSE = &H10
GLOBAL Const WM_CANCELMODE = &H1F

Sub Main()
   Call Close_Program("EXTRA! X-treme")
End Sub

Sub Close_Program(WinTitle As String)
    Dim lret As Long
    
    lret = FindWindow(0, WinTitle)

    If lret <> 0 Then
       lret = End_Task(lret)
    End If
End Sub

Function End_Task(TargetHwnd As Long) As Integer
   If IsWindow(TargetHwnd) Then
      If Not (GetWindowLong(TargetHwnd, GWL_STYLE) And WS_DISABLED) Then
         PostMessage TargetHwnd, WM_CANCELMODE, 0, 0
         PostMessage TargetHwnd, WM_CLOSE, 0, 0
         EndTask = 1
      End If
   End If
End Function
 
Cheers,

Going to take me a time to work through it. I am only a user afer all.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top