Trainee Myki programmer – “test the website for 100 or more logins”

alokSo where did the Transport Ticketing Authority have the programming for the Mymyki.com.au done?

In Australia, you might think, as we don’t want people’s financial details to be going offshore, particularly with a project being paid for the Victorian Government.

Well you be wrong, try Bangalore.  Say hello to “aloknathlight

10th November 2009, Perl Beginners Mailing List

Hi,
I think I can post the  issue related to ‘mechanize’ here.
I am using www::mechanize to login and logout to a particular page.
When I submit the credential(i.e username and password) and try to
view the content, I don’t see anything.
When I view the source, I see it has jscript code in it. Is the
problem because www::mechanize doesn’t supports jscript ?
Is there any work around for the above issue or can Iuse some other
module ?

Fyi, my objective is to test the website for 100 or more logins.

Please find the snippet of my script and the source for the page.
Any help will be greatly appreciated.

Fyi, my objective is to test the website for 100 or more logins”.  The user base of the Myki system is supposed to be 1 million people, and he only wants to scale the website for 100 logons?  And before you ask, how do we know it’s the MyMyki system?

(more…)

Reading the end of a log file with PowerShell

PowerShell logo I needed to read the last line of a log file.  PowerShell made it very, very, easy.

All you need to do is Get-Content the file, and then pipe it to Select-Object with the –last parameter set to 1.

Here is the code snippet which does that:

$failure_reason = (Get-Content $file_txt | Select-Object -last 1)

And here is a (simple) version of the PowerShell script I wrote to read though a list of computers, and dump the last line to the screen:

$windows2000_PCs = (Get-Content c:\temp\pc-list.txt)
foreach ($computer in $windows2000_PCs)
        {
            $file_txt = "\\"+ $computer + "\c$\log\install.txt"
            $install_result = (Get-Content $file_txt | Select-Object -last 1)
            Write-Host $computer has install result of: $install_result
        }
Write-Host Done!

Which outputs:

BROOMFONDLE has install result of: Program installed successfully on 21 DEC 2010 – 1000hrs
MAGICTHIGHS1 has install result of: Program failed to install – Error code 1603 on 11 DEC 2010 - 1321hrs
Done!

Things to note:

  • c:\temp\pc-list.txt contains the list of computer names you wish to scan.
  • the script is not idiot-proofed error-trapped.
    ie. in a production version of this you would check that the computer being scanned is online, the install.txt file exists, and so on.

 Bookmark and Share

The Windows PowerShell syntax was deliberately chosen

PowerShell logo The Windows PowerShell syntax was deliberately chosen to facilitate ease of use and ease of learning.  Corporate enterprise Windows administrators are the target audience.

- Windows PowerShell Scripting Guide by Ed Wilson, Microsoft Press.

I’m teaching myself PowerShell at the moment, because:

  1. it’s the future of Windows scripting.
  2. I had 1400+ computers I needed to check for a particular file, and it looked easier with PowerShell.

Future of Windows scripting.

Back in the dark ol’ days, if you needed a script created on DOS and Windows, your choices were DOS Batch, and DOS Batch.  This changed in 1991 with KiXtart.  KiXtart was created by a Microsoft employee, to provide corporate IT types with more robust logon scripting.

Like the 9 headed Hydra, KiXtart blossomed.  And got into places where it shouldn’t have gone.  I know of one 4000+ desktop company using it for software deployments.  Erkkkk!  Imagine how much spaghetti code there would have been in that.

Then VBscript.  VBscript was trumpeted by Microsoft in 1998 as the better/new way forward.  One Windows IT Pro writer said in 2001:

VBScript, one of the most powerful and underused features in the Windows environment, provides the same powerful programming tools (e.g., variable support, structured program control, the ability to leverage COM objects) that you’ll find in full-featured development languages.

It was that very powerfulness which caused some security problems with VBscript (mis)use.  So Microsoft threw the baby out with the bath water and created PowerShell to address those security issues.  Sure there are some other advantages to PowerShell, such as speed, and that it’s going to be how you script/interact with new Microsoft products.

Those 1400+ computers?

The script worked well.  Here is the cut down version:

$windows_PCs = (Get-Content c:\temp\pc-list.txt)
foreach ($computer in $windows_PCs)
{
$file_exist_path = "\\"+ $computer + "\c$\data\fred.txt"
$file_exist_OK = (Test-Path $file_exist_path)
if ($file_exist_OK)
{
write-host $computer has the fred file
}
else
{
write-host $computer is missing the fred file
}
#endif - PowerShell does not use EndIf statements, so I put this here as a boundary.
}
#next - PowerShell doesn't have a next statement either.

Output:
CATBERT has the fred file

Bookmark and Share

Duplicate files and hashing in Visual Basic.

Duplicate file detection is fairly easy to do, as it turns out, and it goes like this.

  1. Read first file.
  2. Calculate a unique fingerprint, and store the fingerprint.
  3. Read second file.
  4. Calculate a unique fingerprint, and compare the fingerprint to the first files’ fingerprint.
  5. If they equal, the two files are duplicate files.

One way of doing this fingerprinting is to use a hashing algorithm, such as MD5 or SHA-1.  A hashing algorithm should give you a unique fingerprint for each file.  The snippet of code to do that, which I borrowed from the Visual Basic Knowledgebase is below the fold.

Now there are applications, such as DiskState, which scan your hard disk for duplicates by using MD5 hashing.  But they do this:

  1. Read first file.
  2. Do While we have a file to read
       Calculate a MD5 Hash, and store that value in a list, alone with the filename and location
  3. If we have another file, go back to 2.
  4. At this point, we’ve checked all the files on hard disk. 
       Now search though the list, and do we have any hashes that are the same?
  5. If we do, we have duplicate files.

Why do I need to know how to detect duplicate files?

Well I was updating the Lotus Notes Mail Exporter program the other day, and decided to implement some duplicate attachment file checking.  I’m not sure if I’m that happy with how I’ve implemented it, time will tell.  It does give me an idea for some other programs …


(more…)

“Man invented fire here”

I’ve done a bit of programming over the years, and I’m currently working with a Visual Basic 6 (VB6) code base.  I’ve found the following quotation so true:

visual basic 6 logo It is a weird thing though if you’ve noticed that for very old applications, you know, I feel like for some of them you often have multiple ways of doing things, they just end up co-existing.

It’s kind of like you look around and you can say, oh, man invented fire here, and it’s like, oh, man discovered wheel here and you’re finding the entire history of 15 years of software development stuck in one codebase…

Michael Feathers, speaking with Scott Hanselman, on Hanselminutes podcast 165.

Bookmark and Share

VBscript to uninstall a Microsoft security patch

This is a small script I wrote many years ago to uninstall security patches.  I customise it when I need it.

In this example, I’ve customised it for MS09-032, but the principles apply to most patches.

Note that I don’t check for admin rights, I’m assuming that I’ll be using a desktop software deployment tool to run it on the user’s desktop.

' VBscript to roll back a security patch, in this case MS09-032.
‘ Dale Robinson – 2006 –> 2009

Option Explicit
On Error Resume Next

Dim bUninstallFileExists, OSSystemRoot, objWSHShell, objEnv, sMS09032Installed, sPatchCmd,sUninstallExe

Set objWSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = objWSHShell.Environment("Process")

' MS09-032 sets this registry key if it's installed.

(more…)

APIs new to Windows 7, and other Microsoft operating systems

The list of APIs new to Windows 7, and all the other (previously released) API functions can be found right here:

Functions by Release (MSDN Library)

The PowerSetRequest / PowerRequestAwayModeRequired mode looks particularly interesting.  It seems to be a new power saving mode:

The system enters away mode instead of sleep in response to explicit action by the user. In away mode, the system continues to run but turns off audio and video to give the appearance of sleep.

Bookmark and Share

“Developing For Office – Options and Trade-Offs”

microsoft-office-logo According to Bruno Terkaly, you have three main choices:

  1. Traditional Visual Basic for Applications (VBA)
    Dates back to all the way to the early nineties.
  2. Visual Studio Tools for Office.
    Really hit its stride and office 2007. It probably represents the best option moving forward today. It tries to be all things to all people.
  3. The COM Add-In is probably the most powerful, yet the most difficult option of the three.

I’ve borrowed the above words from Bruno.  You can read all about those options in his blog post.

Bookmark and Share

Sew me a Thread or three.

Threading, simply put, is a way for your program to do multiple things at once.

Sort of like driving and talking on the cell/mobile phone at the same time.

Yes you can do both, but they can cause bad things to happens.  Like driving through red lights, or having your computer freeze on you.

Coincidently, I use threading in my Lotus Notes Mail Exporter (LNME) program.
Lotus-Notes-Mail_exporter-4

The part which does the actual mail message exporting, runs in it’s own thread.

I needed to use threading as I wanted the program screen to update in real time.  Before I implemented a BackGroundWorker thread, the program wasn’t able to update the Status section (highlighted above).  Using threading, it was simple.

But it was difficult to implement, because most programming examples for threading don’t explain the WHY of using a particular thread techique.
So I made a guess to use a BackGroundWorker Thread.

Which turned out ok.

Though, had I seen Joseph Albahari’s website, and the section on Threading in C#, I might have done it differently.

Why?

Well Joseph has written a guide to Threading in C# which forms THE reference to threading.  It’s packed full of information, and I wish I had it when I was starting to write LNME.

Go there, and have a read.

Bookmark and Share

“Is there any way to schedule a task based on a system event?”

… such as an event written to the System Log, or a laptop losing mains power?

Windows Vista, or later?
Yes, indeedy.  Task Scheduler has this functionally built right in.

Windows 2000/XP?
No.
But you could write a program to do that.

Something like this little Visual Basic 2005 program, for the “laptop losing mains power” example:
Power-Status

“Power Status” demonstrates two techniques:

  1. How to get the state of the installed battery, without resorting to calling an API such as GetSystemPowerStatus.
    We do this by using the PowerStatus class which first appeared in .Net v2.0
  2. How to detect a change from Battery power to Mains power, by capturing the PBT_APMPOWERSTATUSCHANGE event.
    By overriding the default WindowProc function, so we can check the Windows Events being sent to us by the operating system.
    When we see the PBT_APMPOWERSTATUSCHANGE event, we update the PowerStatus values and then refresh the screen.

Overriding the default WindowsProc seems very difficult to do, though it’s not.  But it only took 10 minutes of coding.  And it worked first time.

Finding the PowerStatus class, and processing the values, wasted about four hours of code experimentation.
And it still needs work.

Particularly BatteryChargeStatus.

BatteryChargeStatus is returning “undocumented” values in the 9 –> 127 range.
What I suspect is that the battery charger has two modes, Fast charge and Trickle charge.  Which is being reported.  As it’s not documented by Microsoft, I’m not sure.

The sample program is here.
The source code is here.

Bookmark and Share

Page 1 of 41234»

Calendar

March 2010
S M T W T F S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031