473,326 Members | 2,113 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,326 software developers and data experts.

NetFileEnum

I am using NetFileEnum like this but the pathname doesn't actually give
me the filename - how do I get the actual filename?
:

[DllImport("netapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
static extern int NetFileEnum(
string servername,
string basepath,
string username,
int level,
ref IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
IntPtr resume_handle
);
[DllImport("Netapi32.dll", SetLastError=true)]
static extern int NetApiBufferFree(IntPtr Buffer);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=4)]
struct FILE_INFO_3
{
public int fi3_id;
public int fi3_permission;
public int fi3_num_locks;
public string fi3_pathname;
public string fi3_username;
}

int dwStatus = NetFileEnum(servername, null, null, 3, ref pBuffer, -1,
out dwReadEntries, out dwTotalEntries, IntPtr.Zero );
int dwReadEntries;
int dwTotalEntries;
IntPtr pBuffer = IntPtr.Zero ;
FILE_INFO_3 pCurrent = new FILE_INFO_3();
if (dwStatus == 0)
{
for (int dwIndex=0; dwIndex < dwReadEntries; dwIndex++)
{
IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (dwIndex *
Marshal.SizeOf(pCurrent)));
pCurrent = (FILE_INFO_3) Marshal.PtrToStructure(iPtr,
typeof(FILE_INFO_3));
Console.WriteLine("dwIndex={0}", dwIndex);
Console.WriteLine(" id={0}", pCurrent.fi3_id );
Console.WriteLine(" pathname={0}", pCurrent.fi3_pathname);
Console.WriteLine(" username={0}", pCurrent.fi3_username);
}
NetApiBufferFree(pBuffer);
}
thanks
Phil

Nov 17 '05 #1
2 4071
ok, it was because, although I had opened it, Visual Studio did not
keep it open but simply made a copy of it. When I opened the same file
in Word, it appeared!

Now, how do I close it using NetFileClose?

Nov 17 '05 #2
no, done that now but it doesn't really do the job.

For instance, if someone leaves a document open in Word overnight, I
want to automatically kick them off (release the locks) and then copy
over a new document to replace the old one. Although NetFileClose seems
to work (and indeed, on the next run of NetFileEnum, the file is no
longer seen as "open"), the lock in fact remains and the document
cannot be overwritten.

So how do I close the lock/connection completely?

TIA

Nov 17 '05 #3

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

Similar topics

2
by: martijn | last post by:
Hi There, my vb app can open files. Well, actually my vb app launches word or excell to open them. These files are shared in a network. If somebody else has allready opened that file, you...
0
by: Frank Moses | last post by:
Hi. NetFileEnum lists files accessed on a machine over a network and the user accessing them. I was wondering if anybody knew why this function returns the path and filename if the file being...
2
by: James | last post by:
At times due to 3rd party software limitation, passwords are stored in some text or ini files. i want to know what are the classes or methods to use to "prove" that file is OPEN, not necessary...
11
by: fniles | last post by:
One of our application uses VB6 and Access97 database. Another application uses VB.NET 2005. This morning for about 15 seconds when the application tries to read either a query or a table from the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.