473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Creating User Profiles on Windows XP

Hi all,
Please ignore the other post.. The cat jumped on the machine and sent it
before I could stop it!!
Was wondering if anybody has expericence this problem..
I am writting an application in C# using windows forms, to create windows
user profiles and then updating the registry information for the new
profiles.
I have managed to create the user successfully and thought that I was
writting the registry information correctly.

That was until I checked the 'C:\Documents and Settings' Directory, when I
noticed that the new users directories did not reflect their names. But
instead comprised of non printable characters!!!

Here is the code sample in C#

//////////////////////////////////////////
DirectoryEntry NewUser;
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + Environment.Mac hineName
+ ",computer" );

// delete user when existing
try
{
// this throws when no such user
NewUser = AD.Children.Fin d(strNodeName, "User");
MessageBox.Show ("User already exists!!");
return;
}// Catch not found exception
catch(COMExcept ion cex)
{
Console.WriteLi ne(cex.Message) ;
}
// Add user using the user schema
NewUser = AD.Children.Add (strNodeName, "user");
NewUser.Propert ies["descriptio n"].Add(this.txtFi rstName.Text + " " +
this.txtSurname .Text);

// NewUser.Propert ies["PasswordExpire d"].Add(1); // user must change
password at next login

// Set user flags sample here sets Account disabled, pwd can't change
// this flag is different for LDAP accounts
NewUser.Propert ies["userFlags"].Add( UF_NORMAL_ACCOU NT |
UF_DONT_EXPIRE_ PASSWD );
// invoke native method 'SetPassword' before commiting
// for AD domain accounts this must be done after commiting
NewUser.Invoke( "SetPasswor d", new Object[] { this.txtPasswor d.Text });
NewUser.CommitC hanges();
// Add user to guests alias
DirectoryEntry grp = AD.Children.Fin d("Guests", "group");
if(grp.Name != null)
{
grp.Invoke("Add ", new Object[] {NewUser.Path.T oString()});
}

MessageBox.Show ("Account Created Successfully");
AD.Close();
//////////////////////////////////////////
Then I proceed to update the users Registry information!!
At this point their is no Directory for the user in "C:\Documen ts and
Settings\" directory

//////////////////////////////////////////////////
NativeMethods._ PROFILEINFO profile;
IntPtr hToken = IntPtr.Zero;

hToken = NativeMethods.C reateLogonToken (UserAccount, UserDomain,
UserPassword);
if(hToken != IntPtr.Zero)
{
profile = new NativeMethods._ PROFILEINFO();
profile.dwSize = Marshal.SizeOf( profile);
profile.lpUserN ame = UserAccount;

// Directory Still Not Created at this Point!!
int ret = Win32.LoadUserP rofile(hToken, ref profile); // This function
Invokes
if(ret != 0)
{
// Use WMI to get the SID of the user (this requires W2K3 or XP)
using (ManagementObje ct account = new
ManagementObjec t("Win32_UserAc count.Domain='" + UserDomain +"',Name='" +
UserAccount + "'"))
{
account.Get();
// Get key wich is the root for the users hive loaded in HKU
UserSID = account["SID"].ToString();

if(UserSID.Leng th != 0)
{ // Now update the registry information for this user!!
UpdateRegistryI nformation();
}
}

ret = NativeMethods.U nloadUserProfil e(hToken, profile.hProfil e);
}
}

[DllImport("adva pi32", CharSet=CharSet .Auto, SetLastError=tr ue)]
static extern int LogonUser(strin g lpszUserName, string lpszDomain, string
lpszPassword, int dwLogonType, int dwLogonProvider , ref HANDLE hToken);

[DllImport("user env", CharSet=CharSet .Auto)]
internal static extern int LoadUserProfile (HANDLE hToken,ref _PROFILEINFO
lpProfileInfo);
public static HANDLE CreateLogonToke n(string name, string domain, string
passwd)
{
HANDLE ret = IntPtr.Zero;
HANDLE tok = IntPtr.Zero;
System.Manageme nt.ManagementOb ject mo = new
System.Manageme nt.ManagementOb ject(new ManagementPath( ));
mo.Scope.Option s.EnablePrivile ges = true;

int result = LogonUser(name, ".", passwd, LOGON32_LOGON_I NTERACTIVE,
LOGON32_PROVIDE R_DEFAULT, ref tok);
if (result != 0) // If success
{
ret = tok;
}
else
{
string temp = "LogonUser Error: ";
temp += Marshal.GetLast Win32Error().To String();
MessageBox.Show ( temp );
}

return ret;
}
///////////////////////////////

So I stopped writting to the registry information and then physically logged
in as the user via the windows login screen.
This then created the directory correctly!!

Any ideas?

Thanks

Wayne

Nov 16 '05 #1
0 1595

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

Similar topics

0
1816
by: Wayne Gibson | last post by:
Hi all, Please ignore the other post.. The cat jumped on the machine and sent it before I could stop it!! Was wondering if anybody has expericence this problem.. I am writting an application in C# using windows forms, to create windows user profiles and then updating the registry information for the new profiles. I have managed to create the user successfully and thought that I was
6
1717
by: Rajesh Kumar Mallah | last post by:
Hi, I face the following problem in transferring data from pgsql 7.3.4 to pgsql 7.4 RC1 . I am piping the output of pg_dumpall from 7.3 to 7.4 running on different port. The problem is there is a gist index on txtidx type on a non-public schema and when search_path does not include public the index cannot be created.
12
8502
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track, though it does happen often.
2
2855
by: Paul Lemke | last post by:
Hello, I currently have an application that uses authenticates users via NTLM. I would like to provide a user a directory listing of a folder. Everyone has read access to the folder, but the only folders that should show up are ones that allow them to modify sometime. I can list the directories/files just fine using directoryinfo/ fileinfo. But how can i tell if the current authenticated user has NTFS write/modify permissions on those...
0
1507
by: Rafa | last post by:
Hello, First, sorry because I am spanish and my english are not good. My problem is that i am trying to work with profiles in visual studio 2005, but i have an error. the error is that: "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that
9
2371
by: =?Utf-8?B?Sm9obiBBdXN0aW4=?= | last post by:
I have an app that prints entry tickets. If the printer driver is not set up exactly to detect the black mark on the back of the ticket, the tickets do not print correctly. Because of this, all users are logging on with the same user name to ensure they get a correctly configured printer driver. The application runs on a Terminal Server via the RDP client. In order to audit the actions of users, it is necessary to identify each user....
5
9002
by: =?Utf-8?B?cnZhbmdlbGRyb3A=?= | last post by:
Hello, I have a problem with our OnlineBackupService.exe. This is a Windows Service which is built in .Net 1.1 and basically grabs files from the file system and will try to upload them using WebServices. The service is installed by default using LocalSystem account. The exact problem is that sometimes this service is not allowed to resolve the target webservice. This results in the following exception:
6
4124
by: goraya | last post by:
This is design level discussion about web applications. How I design application that support 1 million concurrent requests??
3
1446
by: samirgulhane | last post by:
Hi, We have developed an application.We are using launcher(Full screen window) to open it(just to prevent a user to type any action in the url) Now i opened two session windows with two different User Profiles using launchers.Now when i login into the second window using 2nd user profile it ovverrides the session of the first user profile. The same work done on both sessions will cross over to the other...
1
4847
by: =?Utf-8?B?VGVycnk=?= | last post by:
I am using the My.Settings object to save user settings. During testing, I want to 'zero' out what has been saved to start with the defaults again. Where doies the framwork actually persist these user settings? TIA, -- Terry
0
9471
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,...
0
10136
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
10071
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
9925
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...
1
7478
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
6723
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
3
2867
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.