473,394 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,394 software developers and data experts.

Query regarding NetShareEnum

hello

I am trying to enumerate the shared folders on a server using the
NetShareEnum function.
Now, when the server has a password set to access the shared folders,
the function returns system error code 5 (access denied).

However, if I know the password to access the shares, how can I specify
that in my program?

The basic skeleton of my prog is as follows:

StructLayout( LayoutKind.Sequential )]
public struct SHARE_INFO_0
{
[MarshalAs( UnmanagedType.LPWStr )] public String shi0_netname;
}
[DllImport("Netapi32.dll")]
public static extern int NetShareEnum([MarshalAs(UnmanagedType.LPWStr)]

string servername,
Int32 level,
out IntPtr bufptr,
Int32 prefmaxlen,
[MarshalAs(UnmanagedType.LPArray)] Int32[] entriesread,
[MarshalAs(UnmanagedType.LPArray)] Int32[] totalentries,
[MarshalAs(UnmanagedType.LPArray)] Int32[] resume_handle
);

[DllImport("Netapi32.dll")]
public static extern int NetApiBufferFree(long lpBuffer);

public static string[] GetShares(string server)
{
IntPtr buf = new IntPtr(0);
Int32[] dwEntriesRead = new Int32[1];
dwEntriesRead[0] = 0;
Int32[] dwTotalEntries = new Int32[1];
dwTotalEntries[0] = 0;
Int32[] dwResumeHandle = new Int32[1];
dwResumeHandle[0] = 0;
Int32 success = 0;
string[] shares = new string[0];
success = NetShareEnum(server, 0, out buf, -1, dwEntriesRead,
dwTotalEntries, dwResumeHandle);

if(dwEntriesRead[0] > 0)
{
SHARE_INFO_0[] s0 = new SHARE_INFO_0[dwEntriesRead[0]];
shares = new string[dwEntriesRead[0]];
for(int i = 0; i < dwEntriesRead[0]; i++)
{

s0[i] = (SHARE_INFO_0) Marshal.PtrToStructure(buf,
typeof(SHARE_INFO_0));
shares[i] = s0[i].shi0_netname;
buf = (IntPtr)((long) buf + Marshal.SizeOf(s0[0]));
}
NetApiBufferFree((long) buf);
}
return shares;
}

Nov 16 '05 #1
1 2538
"Siddharth Jain" <si**************@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
PLEASE be patient when posting, this is the third time you post the same
question.
Check your first posting for an answer.

Willy.
Nov 16 '05 #2

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

Similar topics

0
by: siddharth_jain_1 | last post by:
Hello I am using NetShareEnum to enumerate all the shared folders of a server. If there is password set on the server, I get system error code 5 (access denied) as the return value of...
1
by: Siddharth Jain | last post by:
hello I am trying to enumerate the shared folders on a server using the NetShareEnum function. Now, when the server has a password set to access the shared folders, the function returns system...
0
by: Siddharth Jain | last post by:
hello I am trying to enumerate the shared folders on a server using the NetShareEnum function. Now, when the server has a password set to access the shared folders, the function returns system...
1
by: Jean-Marc St-Hilaire | last post by:
I need to access Windows API NetShareEnum. It is working fine in the post Win98 version but the Win98 function is returning me error number 87 (Invalid parameters) Whats I am doing wrong ? ...
7
by: stig | last post by:
hi. coming from postgresql, i am used to textual references to most of the things i do with the database. i feel a little lost with all the graphical. i have few questions regarding MS SQL 2000...
3
by: tcveltma | last post by:
Hi Everyone, I know there's been a lot of questions regarding the same kind of issue but I haven't been able to find an answer to my specific problem. Basically I have two tables, one table...
4
by: bfoo75 | last post by:
Hi there, I'm new to this forum, but I've come here quite a bit to find solutions to problems other people have encountered... I'm currently trying to query a database up to 5000 times as fast as...
1
by: silpa | last post by:
Hi, I have an SQL query like this select distinct t1.prodID from Table1 t1 left join Table2 t2 on t2.prodID = t1.prodID left join Table3 t3 on t3.serialno = t2.Id and t3.Qty = 0 ...
4
by: taghi | last post by:
I want to call NetShareEnum, a function from netapi32.dll NetShareEnum has this definition: NET_API_STATUS NetShareEnum( __in LPWSTR servername, __in DWORD level, __out LPBYTE...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.