Tuesday, July 17, 2007

The Code is Killing Me

And now I want it to kill you... Okay I don't want it to kill you.

This is a neat bit of code, I had to create a new local user in Windows XP. Then I had to change two things, I had to add it to the administrator's group and flag it so that the user's password never expires. As you may or may not know the local users and computers on Windows XP is very similar to Active Directory (I still owe you the Authenticate through AD post). However, there are enough differences that all the AD code I found was just the vaguest of hints as to what I needed to do.

You obviously have to use this in Windows form mode. I'll post a screen shot of the form and then the code.


Sorry I've forgotten all the sites and searches I did.



Now for the Code


The formatting (I hope) will be okay. However I don't think you'll be getting colours. If anyone reads this and knows of a program I can use to convert code to html with formatting and colours I would love an e-mail.

Form



Code Behind

namespace AddLocalUser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void BtnOK_Click(object sender, EventArgs e)
{
if (TxtUserName.Text.Length > 0 && TxtPassword.Text.Length > 0)
{
if (TxtPassword.Text.Equals(TxtConfirmPassword.Text))
{
try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName +_ ",computer");
DirectoryEntry NewUser = AD.Children.Add(TxtUserName.Text, "user");
NewUser.Invoke("SetPassword", new object[] { TxtPassword.Text });
NewUser.Invoke("Put", new object[] { "Description", "Computer owner" });

//Insert the User.
NewUser.CommitChanges();
//Now change the "UserFlags" so that the password never expires
int iUserAccountControl = (int)ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
NewUser.Properties["UserFlags"].Value = iUserAccountControl;
NewUser.CommitChanges();
DirectoryEntry grp;

grp = AD.Children.Find("Administrators", "group");
if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }

}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
else
{
LblMessage.Visible = true;
LblMessage.Text = "The Password fields must match";
LblMessage.ForeColor = System.Drawing.Color.Red;
}
}
else
{
LblMessage.Visible = true;
LblMessage.Text = "All fields must be filled out";
LblMessage.ForeColor = System.Drawing.Color.Red;
}
}


(BAH Sorry about the formatting I tried really hard..okay sorta hard)


Explanation


This is an easy bit of code to write. I'll go through it real quick.
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName +_ ",computer");
DirectoryEntry NewUser = AD.Children.Add(TxtUserName.Text, "user");
NewUser.Invoke("SetPassword", new object[] { TxtPassword.Text });
NewUser.Invoke("Put", new object[] { "Description", "Computer owner" });

//Insert the User.
NewUser.CommitChanges();
This bit is pretty similar (If I'm not mistaken) to the AD version of adding a user. The big difference is using "Environment.MachineName" instead of using your AD server address.

Two DirectoryEntries are used, one for the Directory on your computer. One for the user that you are adding. The CommitChanges() slaps it into the local directory.

//Now change the "UserFlags" so that the password never expires
int iUserAccountControl = (int)ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
NewUser.Properties["UserFlags"].Value = iUserAccountControl;
NewUser.CommitChanges();
DirectoryEntry grp;

grp = AD.Children.Find("Administrators", "group");
if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
This is the more interesting part. This changes the user options that we wanted to change. The ADS_USER_FLAG is obtained by referencing ActiveDS, and then of course adding "using ActiveDs;" to the top of your form code.

Your NewUser Directory entry is used again here. Change the .Property["UserFlags"] to the UserControl int you declare above. Here is a big change from AD code, in Active Directory you would use NewUser.Properties[attribute name]. Here we are changing the UserFlags instead.

After that we create a new Directory entry that will represent the group we want to add the user to. "Find" the group we are looking for (Administrators) and then check to see if that group came back to our object correctly. If it did, simply invoke the add function from AD and point it at the path of our NewUser DirectoryEntry.


WOW I hope that made sense, I did not enjoy writing that i must say. I will try to edit it before I post but my brain may liquefy before I finish that.

Have fun Everyone

This comes in in all sizes

Monday, April 02, 2007

Wow

Look at the prices that apple charges for WWDC07. I would have gone on my own dime but it's just too expensive, too bad we aren't a mac shop I could have talked my boss into paying for me.



Music



I just "obtained" a copy of Less than Jake's album "In with the out crowd". There are only horns in 3 songs... this is not the band that wrote "Johnny Quest thinks we're sellouts". Oh well pretty good album, they are planning on touring with Reel Big Fish and Streetlight Manifesto this summer. I'm excited to say the least.



Beer



I went to Brewsters here in Edmonton. I had the Bow Valley Brown Ale (good) and Greg had the River City Raspberry Ale (not my taste just okay). They have a barely wine I want to try one day. I might just buy two bottles try one that day and save one for another day.




I have a little work to do before going to buy OS X for Sirina's old computer

I dream about puzzle quest

Thursday, March 29, 2007

Beer School



Well I was listening again to my podcasts (instead of working?) and I thought I'd do the homework for "Beer School: What's in Nico's Fridge?". I bought myself 4 cans of Kilkenny, (9.$$ at Superstore Liquor store). Carried them home (not very gently) I opened the can and tried very hard to ignore the fact that it sounded like a mouse had just died in it (Thanks Motor). After I cleaned up the mess it made on my counter, I poured myself the glass you see to the left.

I had accidently left the beer on the counter for an hour therefore it was at room temperature. I thought, "What the hell. Isn't that the way it's supposed to be served?". So I sat down with dinner and drank it up.

I thought it tasted awesome, totally nice aftertaste, very creamy, all around excellent. This morning when I went looking to see where the stuff was brewed (Ireland) I noticed that on the can it says: "Serve Ice Cold". I'm going to try one tonight and see what it tastes like, but I don't believe that it will be as good as it was at room temp.

Anyway...



..back to the homework. I donned my safety glasses (not really) my protective gloves (wouldn't even know where to find them) and grabbed my certified scissors (from the stationary isle at Wal-Mart) and cut into the can to get my widget. After washing the head off of the can and widget I took the picture to the right.

It was a very simple round white plastic ball. There is a small hole in either end and it's glued together in the middle like a cheap plastic toy might be. Not nearly as cool as I thought it would be.. oh well. I tried to take some close up pictures of it but it just was too white and they came out really bad. Maybe I'll play in photoshop and see if I can't get them looking a little better.

Thanks Beer School, for giving me a whole evening of entertainment.


PS. John left a comment on the site which I thought was awesome, thanks John for taking the time to respond I await your next show with baited (not really) breath.

The can left no marks

Wednesday, March 14, 2007

Ahhhhhhh!

It has been crazy at work, today the exchange server broke (no one's fault just bad luck) and consequently broke my Events application. Events app in and of itself was hurried and did not go as well as I would have liked. Oh well live and learn, I will do better next time and manage my time better and manage the expectations better.

I've been listening to a podcast called Beer School. As a good Canadian this is a topic that is near and dear too my heart. I've enjoyed the show for the most part however the show with the bartender in it was annoying...

I am looking seriously into a Mac pro I think I will get one in the next month or so. I'm kinda waiting for dual quad core processors. But I think it will be better for me than building a machine of my own.

Anyway I sould go back to work. Enjoy your day.

The twitter it consumes all!

Wednesday, March 07, 2007

I'm back

All 0 of you must be excited I'm making another post. This one will talk about gadgets and macs and podcasts.


Gadgets


I've had my Sennheiser HD 280 pro headphones for a while. These are some amazing headphones, I'm no Alex Lindsay(sp?) so I wouldn't know good sound from fart noise, but these give some amazing sound quality. They sound good with everything I listen to, Rock, punk, Johnny Cash, everything. The only complaint I could see people having is when I listen to what little rap I have, I need to turn up the volume very loud to get any hits from the bass.

I love them, I would buy them again if this set broke, and for the price I can't say that it would break me.

I have to go now as I timed this post poorly but I will try to get back tomorrow and finish up.

Have a nice day you bastard!

Tuesday, January 30, 2007

Again with the Errors

I'm still stupid, I still need to learn the order in which ASP.net renders a page. Always! I mean always! Make sure that if you are assigning data to something (anything) that you check that it is NOT a postback. You can not only get strange thing happening with data containers you just get annoyed and frustrated.

Anyway I'm off

Everything in Moderation

Tuesday, January 16, 2007

Maybe I'm Behind the Times...

... or maybe I'm just lazy but I've gotten into podcasting of late. I see it as an excellent way to deliver opinions and comments via the web. I also see it as a breeding ground for stupidity and I hope that Apple is keeping tabs on what makes it onto their iTunes store.

I've enjoyed a podcast called "Macbreak Weekly" (do a iTunes search) . I find the people on the cast are interesting and have a lot of useful things to pass onto the users. Leo and Alex are excellent hosts and I think that although it is a long podcast it's something I can listen to and work at the same time.

Another one that Scott Kurtz suggested is: 43Folders it's short and gives good hints on how to do work and get things done (something I need).

My favorite podcast (one that is woefully out of date) is Penny Arcade's "Downloadable Content". It is explicit so watch the volume at work or around children but it gives you an excellent insight on how the two guys work together and make one of the funniest (arguable) comics on the web.

Try some of these out you may even like them.




I installed Office 2007 on my work machine yesterday. Other than some initial hiccups (PocketPC related) it has made a very positive impression on me. I love the new look for the TODO list in Outlook. Things seem to be easier to find and they have done away with most of the menus in favor of a tabbed environment. I'm going to work with it a bit more but I think Microsoft has won me over.

Now all they need to do is release it for the mac and I'll be a happy camper.




Two posts in one week, don't you feel special.

That is all number one!

Monday, January 15, 2007

Long Time No Speak

Hello Everyone, again it has been too long since I've posted here. I thought I would do a quick rundown of things that I have obtained in the past few months and give you all my impressions.



XBOX 360 vs. Nintendo Wii


I have rarely been on the "NEXT GENERATION" bandwagon, I can remember working for my dad for 2 weeks during the a teacher's strike in Grade 12 to save up for the PS2, and that was basically the last time I've bought a gaming system (the DS doesn't count everyone should own one). So when Greg (my Friend) bought me a XBOX 360 for my housewarming gift and Sirina bought me a Nintendo Wii for Christmas I was able to finally compare two next gen systems on my own.

The Wii is certainly novel, Wii sports and Zelda: The Twilight Princess, are the only games I own but both have provided me with all sorts of excitment. I must admit I sometimes imagine looking at myself as I play a round of golf or win a fight in Boxing and think "I look like a moron" but the system is interactive and fun. The xbox on the other hand, has little to no interaction (moving left with your car doesn't help you go around the corner, I promise) but is still quite fun. The wireless controllers on both systems make me very happy and the fact I can turn on the systems without getting up makes me even happier.

I think that right now as we speak the XBOX is the better system in regards to games. I love that I can download game demos and try before I buy on the XBOX. I haven't looked that hard on the Wii but I'm pretty sure I can do that for that system as well.

Another difference is that to set the wii up on the internet all I had to do was enter my key for my internet connection and I was done. The XBOX needs attachments (it does come with a 5ft CAT5 cable) which would be less of a problem for me if my router wasn't 100ft away. My peev about the Wii was the fact that it did not come with component cables, instead I have to convince my TV ever 30 mins or so to goto full screen (I know it's my Tv's fault not the Wii), other than that both systems are simple to set up and take up a minimal amount of space on the TV stand.

Both menus are pretty intuitive (for me) and I've had little to no trouble figuring things out. The cost of XBOX live ticks me off but seems to be a necessary evil. Again I haven't explored as much with the Wii but I assume there is some sort of price associated with playing online.

I'll keep playing both systems, take for instance last night: I played NHL 07 for a couple games and then played Zelda until I cleared the Faron woods of twilight. I think the wii will bore me first it seems more of a novelty than anything. However if Nintendo and Co. can turn out good titles for the Wii I should have no problem enjoying the system. However, the XBOX will hold my attention more because Greg has one and we will be playing Co-Op and Multi quite a bit.

Anyway that's my spiel about that.




I think I'll leave it at that I'm supposed to be working after all.

The twilight scares me.