473,473 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

NetUserGetInfo - problem with filling dir. path

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
Nov 17 '05 #1
8 3693
First you can't retrieve the password of a user account in Windows(check the
docs. for NetUserGetInfo), and if the home_dir is null, I guess it's because
there is no explicit homedir defined for this account.
Second, why are you calling low level C API's when managed classes in
System.DirectoryServices are available to achieve the same results?

Willy.

"piotrek" <pi*************@gmail.com> wrote in message
news:88*************************@news.chello.pl...
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

Nov 17 '05 #2

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
First you can't retrieve the password of a user account in Windows(check
the docs. for NetUserGetInfo), and if the home_dir is null, I guess it's
because there is no explicit homedir defined for this account.
Second, why are you calling low level C API's when managed classes in
System.DirectoryServices are available to achieve the same results?

Willy.


Its easy to say for MVP :]
Could you give me a tip whitch class should i apply to get infos, about user
and his rights?
i'd appreciate it
Nov 17 '05 #3

"piotrek" <pi*************@gmail.com> wrote in message
news:c7**************************@news.chello.pl.. .

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
First you can't retrieve the password of a user account in Windows(check
the docs. for NetUserGetInfo), and if the home_dir is null, I guess it's
because there is no explicit homedir defined for this account.
Second, why are you calling low level C API's when managed classes in
System.DirectoryServices are available to achieve the same results?

Willy.


Its easy to say for MVP :]
Could you give me a tip whitch class should i apply to get infos, about
user and his rights?
i'd appreciate it


There are two namespaces that can be used to get user account info,
System.Management and System.Directory services, the first wraps WMI while
the latter wraps ADSI.

To retrieve user properties using DirectoryServices you need to create an
instance of the DirectoryEntry class specifying "WinNT" as ADSI provider and
the machine name to bind to.
Following sample retrieves all properties for administrator on machine
"piotr", some properties are array types so you will have to convert them to
their natural representation depending on the property type.
For more info search the ADSI docs. and the FCL on MSDN.
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
class App {
public static void Main() {
ListUserProperties("Administrator");
}
private static void ListUserProperties(string UserName) {
using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://piotr/" +
UserName))
{
PropertyCollection pcoll = groupEntry.Properties;
foreach(string sc in pcoll.PropertyNames)
{
Console.WriteLine(sc + "\t\t" + pcoll[sc].Value);
}
}
}
}

Willy.

Nov 17 '05 #4
Thank you so much.
PK
Nov 17 '05 #5
WMI failed when you disable the WMI Service,

But NetUserGetInfo will still done it's work.

Nov 17 '05 #6
Same goes for lsass service if you disable it NetUserGetInfo will fail also.
WMI is a system service it shouldn't be disabled, there are more things that
will fail when you disable the WMI service,

Willy.

<lu********@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
WMI failed when you disable the WMI Service,

But NetUserGetInfo will still done it's work.

Nov 17 '05 #7
I have been trying both NetUserGetInfo (in .NET) and now I've tried the .NET
approach that you have outlined here.

In both cases, the fullname property comes back with my username. I tried
the NetUserGetInfo function in a simple VS 6 Win32 console app and the full
name comes back with my full name and not my username.

In the case of the former, I figure that I was just marshalling something
wrong by misdeclaring the USER_INFO structure, but now I see that the
System.Directory library isn't even working.

Do you think I might still be missing something?

"Willy Denoyette [MVP]" wrote:

"piotrek" <pi*************@gmail.com> wrote in message
news:c7**************************@news.chello.pl.. .

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
First you can't retrieve the password of a user account in Windows(check
the docs. for NetUserGetInfo), and if the home_dir is null, I guess it's
because there is no explicit homedir defined for this account.
Second, why are you calling low level C API's when managed classes in
System.DirectoryServices are available to achieve the same results?

Willy.


Its easy to say for MVP :]
Could you give me a tip whitch class should i apply to get infos, about
user and his rights?
i'd appreciate it


There are two namespaces that can be used to get user account info,
System.Management and System.Directory services, the first wraps WMI while
the latter wraps ADSI.

To retrieve user properties using DirectoryServices you need to create an
instance of the DirectoryEntry class specifying "WinNT" as ADSI provider and
the machine name to bind to.
Following sample retrieves all properties for administrator on machine
"piotr", some properties are array types so you will have to convert them to
their natural representation depending on the property type.
For more info search the ADSI docs. and the FCL on MSDN.
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
class App {
public static void Main() {
ListUserProperties("Administrator");
}
private static void ListUserProperties(string UserName) {
using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://piotr/" +
UserName))
{
PropertyCollection pcoll = groupEntry.Properties;
foreach(string sc in pcoll.PropertyNames)
{
Console.WriteLine(sc + "\t\t" + pcoll[sc].Value);
}
}
}
}

Willy.

Dec 8 '05 #8
Nevermind..

The DirectoryServices technique does seem to be working. I think I wasn't
entering domain and account information properly.

Thank you for the original post. It was very helpful.

"Alfetta159" wrote:
I have been trying both NetUserGetInfo (in .NET) and now I've tried the .NET
approach that you have outlined here.

In both cases, the fullname property comes back with my username. I tried
the NetUserGetInfo function in a simple VS 6 Win32 console app and the full
name comes back with my full name and not my username.

In the case of the former, I figure that I was just marshalling something
wrong by misdeclaring the USER_INFO structure, but now I see that the
System.Directory library isn't even working.

Do you think I might still be missing something?

"Willy Denoyette [MVP]" wrote:

"piotrek" <pi*************@gmail.com> wrote in message
news:c7**************************@news.chello.pl.. .

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
> First you can't retrieve the password of a user account in Windows(check
> the docs. for NetUserGetInfo), and if the home_dir is null, I guess it's
> because there is no explicit homedir defined for this account.
> Second, why are you calling low level C API's when managed classes in
> System.DirectoryServices are available to achieve the same results?
>
> Willy.
>

Its easy to say for MVP :]
Could you give me a tip whitch class should i apply to get infos, about
user and his rights?
i'd appreciate it


There are two namespaces that can be used to get user account info,
System.Management and System.Directory services, the first wraps WMI while
the latter wraps ADSI.

To retrieve user properties using DirectoryServices you need to create an
instance of the DirectoryEntry class specifying "WinNT" as ADSI provider and
the machine name to bind to.
Following sample retrieves all properties for administrator on machine
"piotr", some properties are array types so you will have to convert them to
their natural representation depending on the property type.
For more info search the ADSI docs. and the FCL on MSDN.
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
class App {
public static void Main() {
ListUserProperties("Administrator");
}
private static void ListUserProperties(string UserName) {
using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://piotr/" +
UserName))
{
PropertyCollection pcoll = groupEntry.Properties;
foreach(string sc in pcoll.PropertyNames)
{
Console.WriteLine(sc + "\t\t" + pcoll[sc].Value);
}
}
}
}

Willy.

Dec 8 '05 #9

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

Similar topics

0
by: zelnaga | last post by:
i'm connecting to the internet via a proxy, and am having problems filling out forms... below is the code i have, and below that is the http request i am trying to make it look like. they look...
7
by: Michael Beumers | last post by:
Hello NG I've defined a cursor like the following in my COBOL Programm: DECLARE testc CURSOR FOR SELECT ... FROM ... WHERE field1 LIKE :hostvariable1 field2 LIKE :hostvariable2
6
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run...
2
by: ramesh | last post by:
hi, I am using Com+ in my application. It will have InsertRecords,selectRecords,updateRecords function. In the Web Form i have Drop-down list. I want to select records from SQL and add it to this...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
3
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three...
2
by: Petter L | last post by:
I have set up a test program on how to use colletions saved and loaded from a file. It was a part of a other program until this happends. The saving process working fine but it looks like something...
1
by: sean | last post by:
Hi, I am a complete novice but would liket to have a PHP script which will upload a file which is pre-defined, without the need for the user to 'Browse' for a file path. For example, the...
2
by: Ryan | last post by:
Hi all, I'm loading a datagridview from an Excel file using a dataadapter.fill() method. A few questions: 1) Is there any way to control the column datatypes? The columns are defined by the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.