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

Home Posts Topics Members FAQ

specifying password while using NetShareEnum

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?

the following is the basic skeleton of my code:

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 1508

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

Similar topics

1
3329
by: Marc | last post by:
Hello, Newbie here..... Searching and working this for a week now. We too are having the same problems. Using MySql 4.0.14 and there are "no problems" at all.
10
9892
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
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?
0
1099
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
3058
by: David Crawford | last post by:
I have an application that needs to copy a file to a server which my user may or may not have rights to. In the case where the user does NOT have rights, I want to map a drive to the specified location as well as pass a default user ID and password. Does anyone know how to do this in VB .NET?
9
1623
by: KSC | last post by:
Hello, I have been looking through the docs on System.IO and cannot find a way to return a share name on a mapped drive. I have done this using FileSystemObject.Drive.ShareName, but I don't want to have to reference the Scripting.dll just to get a drive's sharename while using System.IO for everything else. Thanks in advance. I appreciate your help.
1
1808
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 ? Following is my code Thanks
6
7788
by: hotani | last post by:
I am attempting to pull info from an LDAP server (Active Directory), but cannot specify an OU. In other words, I need to search users in all OU's, not a specific one. Here is what works: con = ldap.initialize("ldap://server.local") con.simple_bind_s('user@domain', pass) result = con.search_ext_s( 'OU=some office, DC=server, DC=local',
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,
0
9515
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,...
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
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...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.