I am developing a application using VB 6.0. My requirement is if the user log off the application using File->Exit the below action should perform
Action1 : The login status should get updated with 0 in the back end table called "Create_Login" so that next time if the user login the appl, it will allow the user else it will throw an error saying "The user already logged in"
Action2 : The process with the name "Daily Status" should get killed.
-> If the user Open 2 application window using 2 different user id, there will be 2 process running with same name called "Daily Status"
-> If he close anyone of the appl, then my code killing both process as both are same process name "Daily Status" and both windows are getting closed.
-> The only different is, one appl getting closed after change the status in the back end table as its closed properly but the another one is forced to close due to kill its respective process id so the back end table not getting updated. Hence the login status of second user id still remains '1' and unable to login to the application
How can i kill the appropriate process in which the user try to close the appl?
my code is below
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim MyConn As ADODB.Connection Dim MyRecSet1 As New ADODB.Recordset Set MyConn = New ADODB.Connection MyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=DIVAKAR-PC\LOCALHOST;Initial Catalog=Metrics;User Id=metrics;Password=Thinksoft" MyConn.Open C = MDIForm1.Caption SP = InStr(1, C, "(", 1) + 1 EP = ((InStr(1, C, ")", 1)) - (InStr(1, C, "(", 1))) - 1 EID = Mid$(C, SP, EP) Set MyRecSet1 = MyConn.Execute("Update Create_Login Set Login_Status = 0 Where Emp_Id = '" & EID & "'") MDIForm1.Hide Dim oWMI Dim ret Dim sService Dim oWMIServices Dim oWMIService Dim oServices Dim oService Dim servicename Set oWMI = GetObject("winmgmts:") Set oServices = oWMI.InstancesOf("win32_process") processName = "Daily_Status.exe" For Each oService In oServices servicename = LCase(Trim(CStr(oService.Name) & "")) If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then ret = oService.Terminate End If Next Set oServices = Nothing Set oWMI = Nothing End Sub
Edited 6 Years Ago by divakar.it: n/a