About Mikazo Tech Blog

My name is Mike, and this blog is my way of saving people time. If someone has a specific problem that I've encountered before, hopefully these posts will save them the extraneous Googling I had to go through to solve the same problem. Also, when I have something to say about technology today, I will post my thoughts here. If this blog has helped you out, even a little bit, vote on the poll below, or let me know by sending me an email. I'm always open to exchanging links with other blogs or websites that share a similar interest.

Thursday, March 19, 2009

How To Upload Files with Perl and CGI

I took me quite a while of sifting through the internet looking how to do this. I played with different CGI.pm functions, and so on, but eventually sort of improvised my own script based on what I've seen. This script takes a method="get" parameter of the form "c:\folder1\folder2\file.txt". It does not do any string sanitation or error checking, it just uploads the file. I had to edit the stupid HTML brackets because Blogger doesn't like me typing it there. You'll have to replace the (less/greater than sign) with the actual symbol. Feel free to use if you want.

Code:

use CGI;

$query = new CGI;
print $query->header;
print $query->start_html('Upload file');

$form = $ENV{'QUERY_STRING'};
@args = split('=', $form);
$args[1] =~ s/%3A/:/g;
$args[1] =~ s/%5C/\\/g;
@pieces = split('\\\\', $args[1]);
$length = @pieces;
$localpath = "";
for ($i=0; $i<=$length-2; $i++) {
$localpath .= "$pieces[$i]\\";
}
$localname = $pieces[$length-1];
print "Uploading $localpath$localname";
$serverfile = $ENV{'DOCUMENT_ROOT'} . "/assgn3/cont/$localname";

open(FILEIN, "<$localpath$localname");
open(FILEOUT, ">$serverfile");
while ($line =
(less than sign)FILEIN(greater than sign)) {
print FILEOUT $line;
}
close FILEIN;
close FILEOUT;

print "Upload successful, redirecting to main.pl";
print "(less than sign)meta http-equiv='Refresh' content='4; url=main.pl'(greater than sign)";
print "
(less than sign)/body(greater than sign)(less than sign)/html(greater than sign)";


Friday, March 13, 2009

Printing Unicode C-Style Strings with Variables in C++ MessageBox

This drove me nuts for hours. The MessageBox function wants wide-character strings and I wanted to put variables in my strings, not just L"" constant strings. I had already been using the Unicode character set and didn't want to change a million other things in my code, so after much toiling, I've found the following code snippet to work:


int random = 42;
char message[128];
sprintf(message, "My random number: %d\n", random);
wchar_t mess[128];
mbstowcs(mess, message, 512);
MessageBox(hWnd, mess, L"Information", MB_OK);


The 512 value in mbstowcs() should be WCHAR_MAX_LENGTH but I was too lazy to find which header contains that, so I Googled and found a random value. It seems to work for me.

HP Battery Health Check in Vista

If you own an HP laptop and would like to check your battery health status, you can download a little tool at HP's website. The only problem is that it's meant for Windows XP and if you try to run it in Windows Vista, it will give an error message asking for the file HPQNT.dll

The solution to this is to right click on the sp41862.exe file and choose the Compatibility tab, then run in compatibility mode for Windows XP Service Pack 2. Then when you go to run the exe, right click on it again and choose Run as administrator. Once the program extracts all the files to the directory you choose, do the same thing for the setup.exe file. It should then install the HP Battery Check Tool without any problems. Run the tool from the new shortcut in the start menu and it should let you know how your battery is doing.

Thursday, March 12, 2009

How To Make Your Own Custom Vista Installation Media

Ok if you are the proud owner of any recent brand name computer, it most likely has a recovery partition that holds an image of your hard drive and a bunch of bloatware and crap. If you recover to factory default settings, you might have to spend hours removing the garbage, installing Windows updates, tweaking settings, and so on.

The way I see it, it's much easier to have a clean install of Windows Vista with no bloatware or unneeded software, with all the updates and drivers already in place. How do you do that? Follow the instructions below.

First, you need to obtain a copy of a Windows Vista [version] Service Pack 1 OEM install DVD. In my case, I'll be using Vista Home Premium. Where do you get such a disc? You should already know the answer to that. As long as you use the product key on the bottom of your laptop, or the side of your desktop, you're good to go.

Once you have that, download and install vLite. vLite won't start until you first install the Windows Automated Installation Kit. I hope you have lots of hard drive space, because you're going to need it for this project. You might need DAEMON Tools to mount the Windwos AIK .iso

What else do you need? Updates. Head to RyanVM's message board and grab Vista Post-SP1 Update Pack and Vista Post-SP1 .NET Pack. Extract them to a folder somewhere on your hard drive.

Now for your drivers. There is a nice little tool called Double Driver that will make a copy of all the drivers on your current system for you and put them in a folder. Select the ones you want, and hit the Backup button. Make sure you get the essentials, network and wireless adapters, video card, sound, webcam, so on. Make note of where your driver folder is.

Now you're ready to start up vLite. Mount the Windows Vista install DVD iso with DAEMON Tools, and point vLite there for the installation files. Make a new folder for custom files when it asks you to. Then when you get to the Hotfixes page, include everything in the RyanVM update pack folders. Under Drivers, include everything in your Double Driver backup folder. You can go through all the other tweaks and settings as you please. I took the time to disable any services I won't need using Black Viper's guide.

In the seciton for entering your product key, type the legal product key on the sticker that's affixed to your laptop/desktop.

Once everything's done, let it integrate and create the ISO for you. Now you can burn the ISO and have your very own clean fully-up-to-date fully-customized driver-injected Windows Vista Service Pack 1 installation media.

Enjoy.

EDIT: If you're trying to make your own Vista install disc from the files on a recovery partition, I suggest you look elsewhere because to my knowledge, it is very difficult/sometimes impossible to do.

Donate to Mikazo Tech Blog