Solved

File being used by the system in vb 6

Posted on 2009-05-11
8
154 Views
Last Modified: 2013-12-26
is there a way that i can know if a file is being used by the systems, in this case i want to know if a printer is using a file
0
Comment
Question by:cano63
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24355996

If you get FileMon from Sysinternals.com, and then print, it will show you every file that is touched by any process.  You can filter it by filename or process.
0
 
LVL 1

Author Comment

by:cano63
ID: 24356500
? can you give an example is in vb 6.0
0
 
LVL 1

Author Comment

by:cano63
ID: 24356531
ok but i need to make it with code  in Vb 6.0
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24356773
OK, I don't understand what you are trying to do then.  What file are you interested in?  When you said "if a file is being used by the systems" I thought you meant a system file that perhaps you wanted to delete or at least identify if it was required.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:cano63
ID: 24359920
i want to know by code if a file is being used by the system. i have to delete a file after he's been printed, but i need to know if the systems have cotrol over it or if it is free to delete it
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24363772
You could simply try to delete it and see if you get an error.  
You could try to create it exclusively and see if you get an error, see http://www.eggheadcafe.com/conversation.aspx?messageid=30057905&threadid=30031602
(code below)
You can get info about files, but it is a lot of work, see
http://msdn.microsoft.com/en-us/library/aa364949(VS.85).aspx

'-----------------------------------------------------------

' FUNCTION: FileInUse

' Determines whether the specified file is currently in use

'

' IN: [strPathName] - file to check for

'

' Returns: True if file exists and is in use, False otherwise

'-----------------------------------------------------------

'

Public Function FileInUse(ByVal strPathName As String) As Boolean

    Dim hFile As Long

    

    On Error Resume Next

    '

    ' If the string is quoted, remove the quotes.

    '

    strPathName = strUnQuoteString(strPathName)

    '

    'Remove any trailing directory separator character

    '

    If Right$(strPathName, 1) = gstrSEP_DIR Then

        strPathName = Left$(strPathName, Len(strPathName) - 1)

    End If
 

    hFile = CreateFile(strPathName, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_WRITE_THROUGH, 0)

    

    If hFile = INVALID_HANDLE_VALUE Then

        FileInUse = Err.LastDllError = ERROR_SHARING_VIOLATION

    Else

        CloseHandle hFile

    End If

    Err.Clear

End Function

Open in new window

0
 
LVL 1

Author Comment

by:cano63
ID: 24467417
Does this code is for vb6.0,  is not working, do i have to call any special lybrary.
0
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 125 total points
ID: 24492386
>>do i have to call any special lybrary

Yes.  If you follow the link I posted, it is an article about how to use the  FileInUse function.  In that article, you would see that the code is from the vb setup project installed with visual studio 6.0.  Look for setup1.vbp in C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1 and you can copy what code you need.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now