473,703 Members | 3,315 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\pt ec.exe"
Try
Dim fi As New FileInfo(PTE)
Dim sr As Stream = fi.Open(FileMod e.Open, _
FileAccess.Read , FileShare.None)
sr.Close()
Catch ex As Exception
Console.WriteLi ne(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 2612
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******@hotma il.com> schreef in bericht
news:eC******** ******@TK2MSFTN GP15.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\pt ec.exe"
Try
Dim fi As New FileInfo(PTE)
Dim sr As Stream = fi.Open(FileMod e.Open, _
FileAccess.Read , FileShare.None)
sr.Close()
Catch ex As Exception
Console.WriteLi ne(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
3019
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 ABCDEFGHIJKLMNOPQ
3
4604
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 "file.tell() and file.seek() in order to navigate through a file in order to print specific lines (for example, every 5th line). Allow me to illustrate by example:
2
6451
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
1740
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') f.readline()
3
1873
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 following way: - before reading anything from fd, fd.tell() will return 0 (that's still ok) - after reading a line via fd.readline(), fd.tell() will return a value different from 0 (still ok, I guess)
2
630
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 best group to share this information. A co-worker and I were able to determine how to tell exactly what version of .NET Framework is installed. We had to do this because we had to manually deploy the MS05-004 Security Bulletin to thousands of...
3
399
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 data from the server and close the file. I'm sending multiple request for data and I do not want to close the connecting everytime the entire file has been sent from the server and then reconnect. I'm sending binary data, is there anyway to tell...
9
9371
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 has been loaded? BTW, I'm doing this for several .js files (and I don't always know how many I'll be loading), so I need to check them all. If I code for IE, I can check all the document.scripts.readyState values (not being "uninitialized" or...
1
2426
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 the difference before and after the call of this function if I used tell function is 1024. Apparently the seek is 1024 but the read is 1023 (it's not the end of the file at this step)
3
2904
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. The for-loop version was something like: d = {} for line in f: if line.startswith('>'): d = f.tell() And the while version was:
0
8750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9112
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4425
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4680
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.