|
I goofed... I was using notepad over and over to try and replicate the file being accessed. I found that notepad doesn't cause the file to show as open. When I tried Excel, right before doing my post, I goofed and opened my output file instead of my input file.
I still need to do some testing when the financial system is writing a file to make sure it works the same way or if I need to take your suggestion and look at the file handle.
Thanks!
Lost in the vast sea of .NET
|
|
|
|
|
I just did testing with the financial system and the code worked without having to go to the file handles.
Thanks again for your reply!
Lost in the vast sea of .NET
|
|
|
|
|
Hi all,
Please ignore my post. I was using notepad over and over to try and replicate the file being accessed. I found that notepad doesn't cause the file to show as open. When I tried Excel, right before doing my post, I goofed and opened my output file instead of my input file.
Code works... Thanks to anyone that started researching this issue...
Lost in the vast sea of .NET
|
|
|
|
|
That's because Notepad does not keep the file open as you are editing it. It opens the file, reads the contents, closes the file, then shows you the contents in the window.
Same thing with Excel and reading text files. Excel WILL however, keep a workbook file open for the life of the working session.
modified 14-Nov-12 7:53am.
|
|
|
|
|
KreativeKai wrote: Any ideas?
A file being reported as "in use" may even vary on the file-system being used; there is no real way of testing, but trying and recovering if things go wrong.
For reading, that means simply putting up a message that the file is locked by another application which needs to be closed first. For writing, it means (in the ideal case) that one offers a SaveFileDialog to save the file under a new name.
"Testing and opening" is not an option, since it creates a race-condition; the file could be opened between the moment you checked it's status and the moment you're going to lock it.
|
|
|
|
|
I agree with everything you said in your reply because each situation you're trying to code for can vary.
In the situation I have however I won't need to worry about the file being re-locked. Basically the financial system writes a report file in text format and the code I posted in the original thread works to check if the file is currently open. Once the financial system has completed the output it will never be opened again except by my application that is picking it up and converting the report to PDF and then deleting the original text file.
My application is executed by a service I wrote that checks if a text file shows up in a certain directory. The service checks every minute. If it sees a text file it executes. My app then goes through the directory and starts reading files for conversion. I don't want to start this process if the financial system has not completed the output, so I'll basically skip if opened and catch it the next time the app executes (1 minute later).
My biggest mistake was assuming notepad would hold the file open for testing....
Lost in the vast sea of .NET
|
|
|
|
|
I had a similar problem and solved it using
Public Function FileInUse(ByVal sFile As String) As Boolean
If System.IO.File.Exists(sFile) Then
Try
Dim F As Short = FreeFile()
FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(F)
Catch
Return True
End Try
End If
End Function
usage
Do While FileInUse(sSourcePath & "\" & sFileName & "." & sExtension)
System.Threading.Thread.Sleep(1000)
sTimeOut += 1
If sTimeOut = 15 Then
WriteLogLog("File " & sFile & " in use.")
Exit Sub
End If
Loop
Im testing each second if the file can be opened, if it can't then it is because it is in use. When the loop ends I know my file is no longer in use.
best regards
modified 19-Nov-12 10:20am.
|
|
|
|
|
HI All,
I am an non IT guy who does no know much about VBScript. I wanted to try out something new . I want to code VB Script to automatically turning off the monitor when it is idle for a minute. Please let me know how the code would work and the code using VB Script....
|
|
|
|
|
You're not going to get any code to do this as VBScritp can't do the things required to pull this off.
But, you can always use this[^].
|
|
|
|
|
I'd rather opt for a Group Policy which could be distributed in your domain (assuming that you want your setting to be used on all computers of your company).
|
|
|
|
|
Is there a way to determine the SQL Server configuration from vb.net?
I would like to be able to determine what the memory allocation is weather its an express or full version and what version it is.
Any information on this would be great,
|
|
|
|
|
|
Thanks for the reply, I will need to read about that stuff before i can attempt it but its a good starting point thank you
|
|
|
|
|
Log in as 'sa' and execute this command:
SELECT
(Physical_memory_in_bytes/1024.0)/1024.0 AS Physical_memory_in_Mb
FROM
sys.dm_os_sys_info
No special privileges for this command:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
Please remember to vote if you find this helpful.
|
|
|
|
|
Thanks for your help, this has pointed me in the right direction once I develop the complete solution i will post.
|
|
|
|
|
How to write source code for Add, Delete, Update, Save, view in crystal report in VB.Net 2008
|
|
|
|
|
By coming up with a GOOD set of requirements (hint: FAR more than what you have in your post), designing a solution that fits those requirements and writing code to implement the solution.
|
|
|
|
|
I am trying to monitor network bandwidth usage on a per user basis and am new to vb.net. I have a list of users with their IP addresses already if that helps.
Basically trying to mimic the remote desktop service manager.
I am lost when it comes to this so any information about how to accomplish this would be greatly appreciated.
Is this even possible?
modified 13-Nov-12 11:54am.
|
|
|
|
|
DinoRondelly wrote: Is this even possible?
Hard to answer; when I use "Fiddler" to monitor the traffic, I can see what's going on in detail. There's probably examples on using the same "winpcap" from .NET here on CodeProject.
Still, I think "time" is more frequently (and easier) used to limit the users' access.
|
|
|
|
|
Hello All -
I have seen on this site Article 42852 / Reading-Barcodes-from-an-Image-III, however, this appears to only read the first page of a multipage tiff. I need to find something that can read all the pages (could be a 500 page tiff) for barcodes. Also, does anyone know of a sample project on this site (or any other site) with source code to do this and scan a folder of tiff images instead one at a time.
Thanks in advanced.
|
|
|
|
|
daveofgv wrote: I have seen on this site Article 42852 / Reading-Barcodes-from-an-Image-III, however, this appears to only read the first page of a multipage tiff. I need to find something that can read all the pages (could be a 500 page tiff) for barcodes
If you need to find it, good luck.
To create it;
- Isolate the trick from the article to a minimal console-app
- Try fetch total number of pages on a given TIFF file
- Try fetch specific page of a given TIFF file
- do trick N times, while showing progress bar
daveofgv wrote: Also, does anyone know of a sample project on this site (or any other site) with source code to do this and scan a folder of tiff images instead one at a time.
It'll be quite expensive to do them "all at once", it there's over a hundred. Doing above trick for each file in a directory, is explained here[^]
|
|
|
|
|
I am trying to get all logged on users and their IPAddresses and display them in a data grid veiw in a windows form using VB.net I have tried the below code and it appears to get the users on a windows 7 machine but not on servers. Any information on this would be greatly appreciated.
Public Shared Function GetUsers() As List(Of Users)
Dim UserList As New List(Of Users)
Try
Using searcher = New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_LogonSession WHERE LogOnType = 2")
For Each queryObj As ManagementObject In searcher.Get()
Dim qry As String = "Associators of " _
& "{Win32_LogonSession.LogonId=" & queryObj.GetPropertyValue("LogonId") & "} " _
& "Where AssocClass=Win32_LoggedOnUser Role=Dependent"
Using iSearch = New ManagementObjectSearcher(qry)
For Each res As ManagementObject In iSearch.Get()
Dim ret As New Users(res.GetPropertyValue("Name"), _
"", "")
UserList.Add(ret)
Next
End Using
Next
End Using
Return UserList
Catch err As ManagementException
MessageBox.Show(err.Message)
Return UserList
End Try
End Function
|
|
|
|
|
Unless the users are logged in on Remote Desktop (or Terminal Services) to the server, this code won't show you anything on the server.
LogOnType = 2 is Interactive logons only. Remove the WHERE clause and see what you get.
|
|
|
|
|
Thanks so much for the reply
What I am trying to do is determine all users logged on to a server and then get their IPAdresses and any other information I can get on them.
I did what you suggested but for some reason this also included Local Services,Network Services and others in the list of users. Also every user in the list was triplicated.
This is the first project I have done in VB.net so forgive me if i come off as a novice.
Any information or code samples would be greatly appreciated.
|
|
|
|
|
and what were their LogOnTypes??
I have no idea what kind of user you're looking for! "Logged on users" can mean anything depending on HOW they are logged on. Are they remote desktop sessions? HTTP Sessions? Mapped drives?? Each of these is a different logon type and needs to be handled differently.
|
|
|
|