Craig Box's journeys, stories and notes...


Posts Tagged ‘programming’

Windows Administrator Challenge: Temporary password changes

Monday, August 21st, 2006

I've yet to post something so sensational (or trollworthy, or just "noticed by Digg") to build up a loyal readership of thousands. I'm sure it'll come eventually. I need to do a couple of things: pimp myself to various Planets, and decide exactly what it is I write about. Generally, it's "things related to what I'm working on", which may or may not be of interest.

My last plea for help didn't turn anyone up. Here's another one that hopefully Google will one day turn up for someone who is bored and has the knowledge and skill to do this, or I'll get bored myself, and acquire the knowledge and skill to do it. Perhaps when it's cricket season again..

I want a simple add-on for the Active Directory Users & Computers MMC utility that does the following things:

  • Allows you to change a password for a user, and more importantly
  • Saves the original password, so you can reset it later.

No more will you have to ask a user for a password to log into their machine and fix something wrong with their specific profile or operating environment, or change their password and tell them to change it back when you're finished. The script will copy the crypted password to an unused LDAP attribute on the account, and then copy it back when finished - without ever having to know what the password is. By standard means, it's not possible to read the password hash out of AD, so I'm currently seeking help from the newsgroups.

Daniel Petri's help pages have examples on how to extend AD to add options to the context menu for a user, to run VB scripts.

BASIC liability insurance

Thursday, August 17th, 2006

As those of you who know me personally will know that I am, quite vocally, not someone who enjoys programming. My main problem is that I write code so infrequently that whenever I sit down I've forgotten either the syntax of language or the parameters of the API, and find more time is taken with reading the docs or finding suitable examples than actually writing or thinking.

I visited my parents yesterday to help my 16 year old brother study for a test, and he also asked for some help with a programming assignment. Due either to a recent loss of computing equipment, or general difficulty in deciding on a language for teaching programming, they're using QBasic. Last time I used QBasic, I hadn't gone through a university degree and learnt half a dozen programming languages, so I found it all a bit easier this time. The problem was that I had no idea if half of the things I wanted to do had syntax in QB: you can't specify an array using numbers[4] = {1, 3, 6, 8}, so an example on the web (the only time I had to go outside of the help) pointed out that you use READ and a DATA statement. I remember seeing DATA statements in Commodore 64 code printouts in magazines, and not having any idea how the stuff quite how they worked. Surely it's easier to specify your data inline, rather than in a DATA statement? Isn't BASIC supposed to be, well, basic?

Anyway, below the fold is what I wrote. The goal was to teach my brother, and his brief was "write a roulette game". I insisted there would be no GOTOs, and no functions/subroutines, as he hadn't covered them at school. Generally the code had to make sense so he could read it and figure out how it all worked.

We finished it, and then, like the bastard I am, I deleted the bit that tests for odd and even and made him rewrite that. I suspect he'll find this post before actually rewriting it himself. Maybe not enjoying programming runs in the family.

(more…)

Left out in the .NET cold

Tuesday, July 18th, 2006

Hey, if Juha's blog is a NZ .NET blog, then dammit, I ought to be one too. Vote for me! I have a Smartphone, and wrote a program in C# once!

On that note, did you hear I wrote a program in C# once? Mostly while watching one-day cricket last summer, in fact. It progressed really well, and seemed like it would fill a need - it does profile management for Windows 2000/XP machines. I learnt a lot on the go, and got it to the point where I didn't think that I would be able to go much further without peer review.

So, I released it, and posted about it to some newsgroups. And got no feedback. Not one. Not a sausage.

Since then, I've actually gone to run it once, and found that it didn't actually work on .NET 1.1 - even though I'd deliberately eschewed nice new 2.0-only classes and done things The Hard Way for maximum compatibility, because I'd used Visual Studio Express 2005, it used 2.0 by default. I found out how to fix that, but by that time, it was quicker to fix the profiles manually.

I don't really enjoy programming the way that my programmer friends do. If I had a Windows programmer buddy to help me with the details and motivate me, then the Windows sysadmins of this world could end up with a pretty cool tool. So, 1. I think this post must make my blog the best .NET blog in NZ (cough cough) and 2. if anyone out there wants to help out with a useful C# project for Windows sysadmins, please comment below.

Windows tips: Starting WinVNC automatically if not running

Monday, July 17th, 2006

A long time ago I built an installer for WinVNC so that IT Partners' clients can connect back to us and we can fix their problems remotely.

A problem I have always had with it was that you have to launch WinVNC seperately from a connection shortcut; if you tried to run it every time, it would say "Another instance of WinVNC is already running", and if you go to connect when there isn't a running WinVNC, you get "No existing instance of WinVNC could be contacted". Therefore, users need to perform two distinct steps - a "launch", which does -kill -run, and a "start session", which does a -connect.

Here is a nice batch file to get around it, using SysInternals' PSList utility. If you know your users are on Windows XP or greater, you could use the built in tasklist command instead.

Code:

@echo off
pslist winvnc > nul
if %ERRORLEVEL% EQU 0 goto connect
start winvnc -run

Code:

:connect
if [%1] NEQ [] start winvnc %1 %2 %3 %4 %5

Code:

:end