The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Kill Origin Instance
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 03/30/2004 :  08:42:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
HI,

I'm running Origin 7.5 from Excel via COM and I'd like to be able to check if any instances of Origin are already open and then provide the option of killing these prior to launching a new instance of Origin.

Any assist would be appreciated here..

Thanks,

Cheers,

Pete

ML

USA
63 Posts

Posted - 03/30/2004 :  12:54:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is little VBA code that could be used. The string code inside the callback EnumWindows_CallBack() looks for a match of window title which starts with the string "Origin".


 
'---------------------------------------------------------------

Declarations

Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long

Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Dim bFound As Boolean



Public Sub Main()

bFound = False
bb = EnumWindows(AddressOf EnumWindows_CallBack, 0)

If bFound Then
MsgBox "Origin found"
Else
MsgBox "Origin not found"
End If


End Sub



' This function is called from the EnumWindows API
Private Function EnumWindows_CallBack(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim wndName As String
Length = GetWindowTextLength(hwnd)
wndName = Space$(Length + 1)
Length = GetWindowText(hwnd, wndName, Length + 1)
If InStr(wndName, "Origin") = 1 Then
EnumWindows_CallBack = 0
bFound = True
Exit Function
End If

EnumWindows_CallBack = 1
End Function
'---------------------------------------------------------------


Go to Top of Page

peter.cook

UK
356 Posts

Posted - 03/31/2004 :  06:00:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

Thanks Marko!

This is really helpful and I wouldn't have known where to start.

I had wondered about trying to kill the application but now think I might have to get user to do it manually.

Cheers,

Pete

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000