473,791 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specifying password while using 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.Sequ ential )]
public struct SHARE_INFO_0
{
[MarshalAs( UnmanagedType.L PWStr )] public String shi0_netname;
}
[DllImport("Neta pi32.dll")]
public static extern int NetShareEnum([MarshalAs(Unman agedType.LPWStr )]

string servername,
Int32 level,
out IntPtr bufptr,
Int32 prefmaxlen,
[MarshalAs(Unman agedType.LPArra y)] Int32[] entriesread,
[MarshalAs(Unman agedType.LPArra y)] Int32[] totalentries,
[MarshalAs(Unman agedType.LPArra y)] Int32[] resume_handle
);

[DllImport("Neta pi32.dll")]
public static extern int NetApiBufferFre e(long lpBuffer);

public static string[] GetShares(strin g 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(se rver, 0, out buf, -1, dwEntriesRead,
dwTotalEntries, dwResumeHandle) ;

if(dwEntriesRea d[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.PtrToSt ructure(buf,
typeof(SHARE_IN FO_0));
shares[i] = s0[i].shi0_netname;
buf = (IntPtr)((long) buf + Marshal.SizeOf( s0[0]));
}
NetApiBufferFre e((long) buf);
}
return shares;
}

Nov 16 '05 #1
0 1099

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

Similar topics

0
1508
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 NetShareEnum, as expected. However, if I know the password required to access the shares on the server, how do I specify that in my code?
1
7269
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 error code 5 (access denied). However, if I know the password to access the shares, how can I specify that in my program?
1
168
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 *bufptr, __in DWORD prefmaxlen, __out LPDWORD entriesread, __out LPDWORD totalentries,
4
3165
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 *bufptr, __in DWORD prefmaxlen, __out LPDWORD entriesread, __out LPDWORD totalentries,
0
10207
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...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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
6776
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
5431
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...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.