Simon,
Try it like this:
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
static extern int NetWkstaUserEnum(
string servername,
int level,
out IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
ref int resume_handle);
[DllImport("netapi32.dll")]
static extern int NetApiBufferFree(
IntPtr Buffer);
// for use on Win NT/2000 only
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct WKSTA_USER_INFO_0
{
public string wkui0_username;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct WKSTA_USER_INFO_1
{
public string wkui1_username;
public string wkui1_logon_domain;
public string wkui1_oth_domains;
public string wkui1_logon_server;
}
// ...
IntPtr bufptr = IntPtr.Zero;
int dwEntriesread;
int dwTotalentries = 0;
int dwResumehandle = 0;
int nStatus;
Type tWui1 = typeof(WKSTA_USER_INFO_1);
int nStructSize = Marshal.SizeOf( tWui1 );
WKSTA_USER_INFO_1 wui1;
this.listView1.Items.Clear();
do
{
nStatus = NetWkstaUserEnum(
textBox1.Text,
1,
out bufptr,
MAX_PREFERRED_LENGTH,
out dwEntriesread,
out dwTotalentries,
ref dwResumehandle );
//
// If the call succeeds,
//
if ((nStatus == NERR_SUCCESS) | (nStatus == ERROR_MORE_DATA))
{
if (dwEntriesread > 0)
{
IntPtr pstruct = bufptr;
//
// Loop through the entries.
//
for (int i = 0; i < dwEntriesread; i++)
{
wui1 = (WKSTA_USER_INFO_1)Marshal.PtrToStructure( pstruct, tWui1 );
MessageBox.Show(wui1.wkui1_username);
pstruct = (IntPtr)((int)pstruct + nStructSize);
}
}
else
{
MessageBox.Show("A system error has occurred : " + nStatus);
}
}
if ( bufptr != IntPtr.Zero )
NetApiBufferFree( bufptr );
} while(nStatus == ERROR_MORE_DATA);
>If anyone can help or point me in the direction of a good book it would be
>much appreciated.
".NET and COM: The Complete Interoperability Guide" by Adam Nathan, ISDN
067232170X.
Mattias
===
Mattias Sj�gren
[EMAIL PROTECTED]
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.