473,441 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

How to tell if a file is in use?

Is this the best way to see if a DOS executable is running? I tried
getting process window titles but it takes longer and the window title
could be any number of different names. I'm a little worried about my
program corrupting the executable using the code below. Or should I not
worry? The DOS app is operation critical.

'Make sure that PTE isn't running before we continue.
Dim PTE As String = "d:\apps\pte\ptec.exe"
Try
Dim fi As New FileInfo(PTE)
Dim sr As Stream = fi.Open(FileMode.Open, _
FileAccess.Read, FileShare.None)
sr.Close()
Catch ex As Exception
Console.WriteLine(vbCrLf & _
"PTE is currently running. You must close PTE before using this
program." & _
vbCrLf)
Exit Sub
End Try

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
1 2601
Hi Terry,

i do not know another good way ( reliable ) to determine if a dos proggy is
running

but :
Instead of asuming that the program is running , and that this is the
reasson that the file could not be accessed and thus the exception is raised
i would go for the aproach of catching the exception type .( the file locked
exception should be the only one to catch in this situation for your
assumption )

what if the file isn`t there for instance ?

"Terry Olsen" <to******@hotmail.com> schreef in bericht
news:eC**************@TK2MSFTNGP15.phx.gbl...
Is this the best way to see if a DOS executable is running? I tried
getting process window titles but it takes longer and the window title
could be any number of different names. I'm a little worried about my
program corrupting the executable using the code below. Or should I not
worry? The DOS app is operation critical.

'Make sure that PTE isn't running before we continue.
Dim PTE As String = "d:\apps\pte\ptec.exe"
Try
Dim fi As New FileInfo(PTE)
Dim sr As Stream = fi.Open(FileMode.Open, _
FileAccess.Read, FileShare.None)
sr.Close()
Catch ex As Exception
Console.WriteLine(vbCrLf & _
"PTE is currently running. You must close PTE before using this
program." & _
vbCrLf)
Exit Sub
End Try

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Peter Abel | last post by:
Hi all, I'm working under W2k with Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 I have a file *test_data.txt* with the following content: 0123456789 0123456789 abcdefghi...
3
by: Pernell Williams | last post by:
Hi all: I am new to Python, and this is my first post (and it won't be my last!), so HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an inner loop in conjunction with...
2
by: Chris McAvoy | last post by:
Is this a bug? (file is an open text file): >>> for i in range(0,5): .... var = file.next() .... file.tell() .... 1675L 1675L 1675L 1675L
0
by: Prabhu Ramachandran | last post by:
Hi, I noticed peculiar behavior under Python-2.3.4 under Win32. When I run something like this: f = open('t.txt', 'wb') f.write('1\012'+'2\012'+'3\012') f.close() f = open('t.txt', 'r')...
3
by: N. Volbers | last post by:
Hello everyone, I noticed that when you open a zipped tarball using 'tarfile' and if you then get the pseudo-file descriptor fd for a file via 'extractfile', then fd.tell() is broken in the...
2
by: j.b.messina | last post by:
This has not yet been published by Microsoft. It will be published within the next few weeks, mainly because I asked them to. I felt this was information badly needed, and I think this is the...
3
by: DJTN | last post by:
I have created 2 vb.net applications in VS 2002, a server and a client using the .net.sockets namespace. I can connect and receive data fine but the client cannot tell when it has recived all the...
9
by: Ian Richardson | last post by:
If I follow the steps on http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=11 to add .js files to a document on demand, let's say by <body onload="blah();">, how can I reliably tell that it...
1
by: orion30 | last post by:
I used the read function in order to read a big file. I read the file by 1024 blocks in a WHILE statement. During the read statement there is a problem. Indeed, the read function return 1023 and...
3
by: Magdoll | last post by:
I was trying to map various locations in a file to a dictionary. At first I read through the file using a for-loop, but tell() gave back weird results, so I switched to while, then it worked. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.