|
-
Jan 25th, 2013, 12:09 AM
#1
Thread Starter
Addicted Member
program hangs
I have created this program that will check in the database the list of legitimate windows processes to run. if not included in the whitelist, the said process will be terminated.
how i am doing this by constantly connecting to the database every 2 seconds using a timer. Previously, I just let the recordset left open so there is no need to always close and reopen but I think this causes the program to hang so I remade it to constantly close and reopen for reconnection but still the program hangs. By hang it means, I can no longer see the gui face of the program nor click any buttons in the program.
what should I do to resolve this hang issue.
what i dont understand here more is that, on several computers, the program does not hang, but on some computers, the program hangs while all of the computers have identical specs.
-
Jan 25th, 2013, 12:26 AM
#2
Re: program hangs
Well there is not much there to go on, I would think that rather than leaving a recordset open or opening the database over and over that you may be better off using a list or array and loading the data into memory.
I would also consider keeping track of the programs that had already been validated and skip the part where it would check the list on those programs which should increase speed since the running list is likely to be much shorter than the allowed list.
If your program is hanging then I would suspect that it is either getting stuck in a loop or that there is some issue with the way you are trying to terminate the process
-
Jan 25th, 2013, 12:52 AM
#3
Thread Starter
Addicted Member
Re: program hangs
ok. I will try to check the looping. but do you have idea what could be stucking the loop?
I am mean what I do it go over one by one on each process and compared it to whats on the whitelist using select, if not in the whitelist, then terminate it. thats how it is loop and kill.
-
Jan 25th, 2013, 02:00 AM
#4
Re: program hangs
Well since I have not saw any code anything I would say would just be a wild guess so there is not much point.
-
Jan 25th, 2013, 03:56 AM
#5
Re: program hangs
Elaborate on why you need to check the DB so frequently.
The more detail you provide, the more likely you will receive a quick solution
-
Jan 25th, 2013, 04:11 AM
#6
New Member
Re: program hangs
 Originally Posted by ravemaster
I have created this program that will check in the database the list of legitimate windows processes to run. if not included in the whitelist, the said process will be terminated.
how i am doing this by constantly connecting to the database every 2 seconds using a timer. Previously, I just let the recordset left open so there is no need to always close and reopen but I think this causes the program to hang so I remade it to constantly close and reopen for reconnection but still the program hangs. By hang it means, I can no longer see the gui face of the program nor click any buttons in the program.
what should I do to resolve this hang issue.
what i dont understand here more is that, on several computers, the program does not hang, but on some computers, the program hangs while all of the computers have identical specs.
What happens if you set the timer to say 10 seconds?
And as has been stated before, why not use an array?
-
Jan 25th, 2013, 04:59 AM
#7
Thread Starter
Addicted Member
Re: program hangs
armandino, I am preventing so executable files not to be executed which the management do not allow to be installed or executed. I have not tried array and I am not familiar using array.
bobbles, i need to check on the db frequently for any changes in the whitelist or in the processes.
-
Jan 25th, 2013, 06:00 AM
#8
Re: program hangs
"bobbles, i need to check on the db frequently for any changes in the whitelist or in the processes. "
Which of those peeks into the DB requires it to be every 2 secs and why so frequent ?
What would you be peeking for in relation to processes.
Unless it is a trade secret, give us closer to 100 words instead of 10 in your reply.
I was a business/system analyst for 20 years, and you are giving me nothing to analyze.
You appear to be looking for a design solution (what is wrong with your code), when it may be a flaw in your analysis.
-
Jan 25th, 2013, 08:20 AM
#9
Thread Starter
Addicted Member
Re: program hangs
bobbles, I am comparing the list of process to the list of allowed processes that are in the db. if such running process is not in the db, then it will be killed.
it is frequent because it is possible that the list of processes running may be updated. thats just it.
i just dont know why it hangs in a certain computer but not on the other computer while, both computers have the same specs.
-
Jan 25th, 2013, 08:37 AM
#10
Re: program hangs
Just to aid communication, let us say there is an 'Allowed List' and a 'Currently Running' List
Are you looking up BOTH OF THOSE LISTS every 2 seconds ?
- - - - ALLOWED LIST
Why do you have to read that every 2 secs ?
Surely that list's contents does not change frequently ?
- - - CURRENTLY RUNNING LIST
Why is the list of processes that are currently running in the DB ?
Do you have some other program doing 'a scan' and it then lists them in the DB ?
Why not take the code that does the scan and put that in your program, so you do not need to look up the DB for that
Please provide longer more detailed answers.
-
Jan 25th, 2013, 12:09 PM
#11
Re: program hangs
Sounds like this is something that should be running as a service rather than an actual app... And since I don't think that the list of allowable apps to run is changing every 2 seconds... it should be loaded once when it starts... and then maybe refreshes once an hour tops...
it's probably hanging because you're hitting it from several computers every 2 seconds... one thing you don't mention is the DB platform (Access, SQL Server, Oracle, MySQL...) if one person is writing to the db at the sametime someone else tries to read from it... you're locked... especially if you're not closing the connections following the write...
-tg
-
Jan 25th, 2013, 12:16 PM
#12
Re: program hangs
I think I was the one who mentioned a currently running list and I was not referring to having it in a db.
I would pull the data from the db and store it in an array in memory
When I scan the running programs for the first time I would add the ones that are on the list to a second array or list or collection of validated running programs
After the initial scan I would compare any running programs to the list of running programs first and if the program is not in list then I would compare it to the larger list of allowed programs and if there add it to the list of running programs else terminate it.
The idea being that the running list should be a lot shorter and would likely increase overall speed though the second list may not be needed anyway.
As to the issue at hand I would suggest adding some logging to help pinpoint where the program is hanging. You could write to the log from places where you might suspect an issue inside the loops and such and I would add a time stamp to each entry. Since the problem may not happen or may not happen for quite a while I would probably over write the log file after say 30 hits on the timer to keep it down to a reasonable size with only the most recent data in it. This ime could be longer of course depending on what is needed to locate the issue.
-
Jan 25th, 2013, 06:43 PM
#13
Thread Starter
Addicted Member
Re: program hangs
techgnome, yes I the program is hitting from several computers in the network every 2 seconds but I dont think this is an issue because out of 50 computers only 2 to 4 computers only hangs. all of this 50 computers are identical in computer specs. Moreover, there is no need to write for me to lock out because the program only reading the db.
datamiser, I am not aware of doing array. can you tell me about this.
anyway, I am showing you below my code for reference:
Code:
Private Sub Timer2_Timer()
On Error GoTo Err_Handler
If rerun = False Then
rerun = True
If IsNetConnectionAlive = True Then
Call doShowProcessList
End If
End If
Exit_Sub:
Exit Sub
Err_Handler:
releasemymouse
Resume Exit_Sub
End Sub
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Long = 260
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Sub CloseHandle Lib "kernel32" _
(ByVal hPass As Long)
Public Sub doShowProcessList()
On Error GoTo Err_Handler
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim success As Long
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = -1 Then Exit Sub
uProcess.dwSize = Len(uProcess)
success = ProcessFirst(hSnapShot, uProcess)
If success = 1 Then
Do
Dim killtxtdb As String
DoEvents
killtxtdb = Trim(left$(uProcess.szExeFile, InStr(uProcess.szExeFile, Chr$(0)) - 1))
KillUnknownProcess killtxtdb
Loop While ProcessNext(hSnapShot, uProcess)
End If
Call CloseHandle(hSnapShot)
rerun = False
Exit_Sub:
Exit Sub
Err_Handler:
Resume Exit_Sub
End Sub
Public Function KillUnknownProcess(theprocessname As String)
On Error GoTo Err_Handler
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim con As New DLLConnectionFunction
Set con = New DLLConnectionFunction
If con.ConnectDBMsSQLOLEDB2005(cn, "server", "dbname", "sa", "pwdaccess") = True Then
Dim strsql As String
strsql = "select * from processlist where processname='" & theprocessname & "'"
If con.ConnectRS(cn, rs, strsql, rsadOpenStatic, rsadLockPessimistic) = True Then
If rs.EOF Then
KillProcessus theprocessname
End If
con.DisconnectRS rs
Else
con.DisconnectRS rs
End If
con.DisconnectCN cn
End If
Exit_Sub:
Exit Function
Err_Handler:
Resume Exit_Sub
End Function
Last edited by ravemaster; Jan 25th, 2013 at 06:47 PM.
-
Jan 25th, 2013, 07:12 PM
#14
Re: program hangs
Actually a list would be the simplest way, Simply query the db to get your recordset and then loop through the recordset adding the items to the list which will stay in memory and allow you to close the recordset but still be able to access the list. You can then test your running programs against the data in the list and not need to query a database over and over.
If the list is static then there is no need to query the db unless the program is stopped and restarted. If the list in the db is going to be changing then the list should be rebuilt periodically but certainly not every 2 seconds. Not only would this method improve performance of your program but the entire network as well since you will be removing quite a lot of network traffic in the process. It may or may not solve you hanging problem as well.
-
Jan 25th, 2013, 07:21 PM
#15
Thread Starter
Addicted Member
Re: program hangs
was there a misunderstanding here about that 2 seconds?
I would like to clarify that the 2 second interval was for querying the database and comparing the list in the db and list in the process but not to rebuild the list in the db.
-
Jan 25th, 2013, 07:31 PM
#16
Re: program hangs
No I think I understand what you are saying. I simply was pointing out that if you use the list then you would only need to query the database when the program first starts and would only need to query again if the list is likely to be changed while the program is running. Surely if this happens at all it would not be often so you may need to have it requery and rebuild your local list every hour or every day or you may even want to have a menu option or button to force a re query depending on the situation.
the point is to limit the calls to the database and the traffic on the network and the side effect may be to solve your issue but then your issue may be unrelated to the db calls.
-
Jan 25th, 2013, 11:02 PM
#17
Re: program hangs
Instead of giving us tiny portions of information (and some guessing by us), describe fully what you are doing.
It is the last time I will ask.
-
Jan 26th, 2013, 04:55 AM
#18
PowerPoster
Re: program hangs
IT sort of reminds me on an old project from 2008. I had put the list of "bad" processes in a textfile, and then had the computer load them to a listbox, then loop through the listbox with a Sub that checks for the "Bad" processes and shuts them down.
I think the user wants to do it frequently, as the processes are updated/opened/closed as the user opens and closes programs and such.
I think.......
-
Jan 26th, 2013, 09:17 AM
#19
Re: program hangs
I think the best solution would to set up security policies on the machine instead of trying to do this programmatically. That being said, if you are really set on monitoring the processes then I would create an ActiveX EXE that does the monitoring and have it raises an event and passes the list of processes when the list changes. While an ActiveX EXE will be a little slower than an ActiveX DLL, the ActiveX EXE has the advantage of running in it's own memory space so if it hangs or errors, it will not bring down the application using it.
-
Jan 26th, 2013, 10:20 AM
#20
Re: program hangs
woah... I'm looking at that code.... oh dear...
if I'm reading it right, you're getting the list of processes.... opening the data base, checking to see if it's there, killing it, closing the db... then going on to the next process where you open, check, kill, close....
You should be getting your list.... open the DB, get the list from there, CLOSE the connection... then loop through your list and check against the Recordset... (hint, use the .Filter method on it and check the .RecordCount)
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|