P
piotrek
Hi all.
I'am forced to ask you for help.Why the code is not working the way it
should.
I wanna fill USER_INFO_1 struct. to obrain information about user windows
account.
Everything seems to work ok exepts password and directory fields. They
remain null;
The code explains the rest:
////CODE
....
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_INFO_1
{
public string usri1_name;
public string usri1_password;
public int usri1_password_age;
public int usri1_priv;
public string usri1_home_dir;
public string comment;
public int usri1_flags;
public string usri1_script_path;
}
[DllImport("Netapi32.dll")]
extern static int
NetUserGetInfo([MarshalAs(UnmanagedType.LPWStr)]
string servername, [MarshalAs(UnmanagedType.LPWStr)] string
username, int level, out IntPtr bufptr);
[DllImport("Netapi32.dll")]
extern static int
NetUserSetInfo([MarshalAs(UnmanagedType.LPWStr)]
string servername, [MarshalAs(UnmanagedType.LPWStr)] string
username, int level, ref USER_INFO_1 buf, int error);
.....
public void test()
{
IntPtr bufPtr;
USER_INFO_1 User = new USER_INFO_1();
if (NetUserGetInfo(null, "test", 1, out bufPtr) != 0)
{
MessageBox.Show("Error Getting User Info", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
User = (USER_INFO_1)Marshal.PtrToStructure(bufPtr,
typeof(USER_INFO_1));
MessageBox.Show("Users Name: " + User.usri1_name + " Users
Comments: " + User.comment + " Dir: " + User.usri1_home_dir );
}
/// END OF CODE
Thanks for any suggestions.
Piotr Kolodziej
I'am forced to ask you for help.Why the code is not working the way it
should.
I wanna fill USER_INFO_1 struct. to obrain information about user windows
account.
Everything seems to work ok exepts password and directory fields. They
remain null;
The code explains the rest:
////CODE
....
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_INFO_1
{
public string usri1_name;
public string usri1_password;
public int usri1_password_age;
public int usri1_priv;
public string usri1_home_dir;
public string comment;
public int usri1_flags;
public string usri1_script_path;
}
[DllImport("Netapi32.dll")]
extern static int
NetUserGetInfo([MarshalAs(UnmanagedType.LPWStr)]
string servername, [MarshalAs(UnmanagedType.LPWStr)] string
username, int level, out IntPtr bufptr);
[DllImport("Netapi32.dll")]
extern static int
NetUserSetInfo([MarshalAs(UnmanagedType.LPWStr)]
string servername, [MarshalAs(UnmanagedType.LPWStr)] string
username, int level, ref USER_INFO_1 buf, int error);
.....
public void test()
{
IntPtr bufPtr;
USER_INFO_1 User = new USER_INFO_1();
if (NetUserGetInfo(null, "test", 1, out bufPtr) != 0)
{
MessageBox.Show("Error Getting User Info", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
User = (USER_INFO_1)Marshal.PtrToStructure(bufPtr,
typeof(USER_INFO_1));
MessageBox.Show("Users Name: " + User.usri1_name + " Users
Comments: " + User.comment + " Dir: " + User.usri1_home_dir );
}
/// END OF CODE
Thanks for any suggestions.
Piotr Kolodziej