|
What have you tried so far?
Sounds an easy enough task, but if you are stuck getting the code to work, post a relevant code snippet describing the problem and I'm sure we can help you out.
|
|
|
|
|
Hi all...
I am creating a project to monitor files of USB disk each time when it is inserted.
When a USB disk is inserted, a thread starts and checks all executable files in usb disk. when user run any executable in usb disk then thread immediately stops its execution. The code is working properly but it slow down the system.
The code is below :
Private Sub StartMonitoring()
Dim MonitorList As New List(Of String)
For Each drive As DriveInfo In System.IO.DriveInfo.GetDrives
If drive.DriveType = DriveType.Removable And drive.Name <> "A:\" Then
DriveName = drive
End If
Next
For Each file As String In My.Computer.FileSystem.GetFiles(DriveName.Name,FileIO.SearchOption.SearchAllSubDirectories)
If IO.Path.GetExtension(File) = ".exe" Then
MonitorList.Add(File)
End If
Next
Do While Not memThd Is Nothing 'memThd is thread which is started to monitor.
Try
For Each prcName As String In MonitorList
For Each prc As Process In Process.GetProcesses
If IO.Path.GetFileName(prcName) = prc.ProcessName & ".exe" Then
prc.Kill()
catch ex as exception
msgbox(ex.message)
End Try
Loop
End Sub
The code is working perfectly but it slow down the system.
Suggest me some way to maintain system speed while running this thread or some other way to write the above code.
Thanks
Gagan
|
|
|
|
|
I must say that if drive is A your code will not work, as you don't set DriveName but use the variable.
Also... what's the purpose of this? Kill any process started from the pen-drive? Are you trying to avoid viruses this way?
But, about the fact it is slow, any non-stopping code makes the computer slow. You can try to set the thread priority to Idle... this could help.
|
|
|
|
|
Paulo Zemek wrote: I must say that if drive is A your code will not work
I have already checked if drv.DriveName<>"A:" then starting the thread.
Paulo Zemek wrote: You can try to set the thread priority to Idle...
I set the prority of threat to 0 (i.e. lowest priority) but it has no effect.
Suggest me some other ways.
Thanks.
Gagan
|
|
|
|
|
It slows down the entire system because your code is horribly inefficient.
Did you notice that you're calling Process.GetProcesses (kind of expensive) each and every time you look at a new item in the MonitorList ?
You're also consuming 100% of the CPU since your loops doesn't yield at all.
You also have the problem of killing off a legit process running off the hard drive with the same name as one stored on the stick.
Killing off a process rather abruptly opens the system up for data corruption and system instability if the app doesn't get the chance to close gracefully.
Your have two "fixes" for the performance problem. First, switch your loops so your only getting the Process list once per pass. Second, put in a Thread.Sleep (with an appropriate value) to put this thread to sleep for a second or two before it goes for another pass.
Look, you really can't stop someone from running applications off of a USB stick like this. There is a group policy that can stop this without you constantly killing the CPU to do it. It's also quite easy to kill off your process and launch an app anyway.
|
|
|
|
|
Dave Kreskowiak wrote: Your have two "fixes" for the performance problem. First, switch your loops so your only getting the Process list once per pass.
I created a list of all running processes and stored it in ProcessList.
Now I am comparing the executable file stored in MonitorList with process name stored in Process List.
Dave Kreskowiak wrote: Second, put in a Thread.Sleep (with an appropriate value) to put this thread to sleep for a second or two before it goes for another pass.
I put this thread to sleep for 1 second as memThd.sleep(1000) after one iteration.
But it does not speeds up my system.
Suggest me some other ways.
Thanks.
Gagan
|
|
|
|
|
I have no idea what you're app is doing to tie up the CPU so badly. If you rewrote the code, properly, the way I suggested, this wouldn't be a problem anymore. Of course, without seeing the modified code, it's impossible for me to tell you what's going wrong.
|
|
|
|
|
hi all
i create a setup file with vb.net2008 in win app
in setup class i have a function that install msde with process.start instruction.i copied the msde2000 folder in bin folder in my application and use this code for setup class:
Dim fsOutput As New FileStream(Application.StartupPath.ToString & "\MSDE2000\setup.ini", FileMode.Create, FileAccess.Write)
my function is true but when i run setup.exe file, this error is shown:
could not find a part of the path "c:\windows\system32\MSDE2000\setup.ini"
my program is in drive f. but why is it looking under "c:\windows\system32"
please help me M.Alizadeh
modified on Tuesday, March 2, 2010 4:00 AM
|
|
|
|
|
try this
Imports System.IO
Imports System.Reflection
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End FunctionBest Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
thanks but now this error appears :
could not find a part of the path "d:\installer.exe\MSDE2000\setup.ini"
d: is the path that i want to install my setup file M.Alizadeh
|
|
|
|
|
Good day,
I have created a webservice in visual web developer express.
"http://localhost:50198/ScanShip.asmx"
It has a function:
"http://localhost:50198/ScanShip.asmx?op=CheckSerial"
How would I now consume this webservice from Visual Basic .net.
You cannot create a webservice in visual basic 2008 express and all the documentation explains how to set up the webserivce and then consume it in the same project.
I only want vb.net to consume an existing web service.
Any help would be appreciated.
|
|
|
|
|
You need to add a reference to it from your VB.NET project.
Right-Click the Project in the Solution Explorer and select Add Service Reference.Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thanks. Just what I needed.
|
|
|
|
|
I am developing an assessment in vb.net and on the last page, I want to be able to add a signature. Does anyone know how to add or attach a signature in vb.net? Any advice would help. Thanks.
|
|
|
|
|
Well, if the signature is saved as an image, a picturebox would do nicely...
|
|
|
|
|
But when the program is running I want to be able to attach the signature and submit it to a database. A picture box is just used to display an image correct?
|
|
|
|
|
You didn't say this in your original post.
What constitutes a "signature"? Is someone signing a creditcard pad? Is there an existing image in a file somewhere? Is it a digital signature key? What??
But, in any case, you'd have to get the image and data and write it to the database, just like anyn other binary blob object.
I can't give any details because you haven't given any about the problem
|
|
|
|
|
Yes there is an existing image in a file somewhere. The program I am writing is an assessment which is simply filling out the forms and writing to the database and the last page requires a signature.
|
|
|
|
|
OK. You're obviously not the first person to want to store an image in a database. So, Google for "insert image <insert database="" engine="" here=""> database vb.net". There's tons of examples.
|
|
|
|
|
I have an interesting problem. I store my program settings in an XML file. When the program first starts I check to make sure it exist using
If Not File.Exists(m_SettingsPath) then
Throw New FileNotFoundException(m_SettingsPath & " could not be found.")
End If
Every time I run the program it throws an exception. The file absolutely exist in the correct directory, and I even confirmed this by enumerating all the file in the directory and it was found. In addition, in the following lines of code the XmlDocument object can open the file without any errors. So I can not figure out why the File.Exists method can not find the file. Any ideas?
|
|
|
|
|
What does m_SettingsPath contain at the point of checking the file exists?Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
When I step through the code it contains:
"file:\C:\Documents and Settings\dmarciano\Desktop\Programming\JBX2JBN Suite\JBX2JBN IV\JBX2JBN IV\JBX2JBN IV\bin\Debug\Settings.xml"
It obtains this value by:
m_SettingsPath = App_Path() & "\Settings.xml"
Where:
Public Function App_Path() As String
Return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
End Function
|
|
|
|
|
The documentation on File.Exists() clearly states:
"The Exists method should not be used for path validation, this method merely checks if the file specified in path exists. Passing an invalid path to Existsl returns false."
Do you really think your string literal is a valid file spec?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I've always used the File.Exists() to check if a file exist before I try and open it. Is there a better way to do it?
|
|
|
|
|
DisIsHoody wrote: I've always used the File.Exists() to check if a file exist
that is good, provided you give it a VALID file path, which you didn't.
DisIsHoody wrote: I've always used the File.Exists() to check if a file exist before I try and open it
That does not make much sense as there are other reasons why opening a file may fail, e.g. file being in use.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|