Internet Explorer basic authentication automation

At work I tried setting a custom header (for example for basic authentication) when navigating the internet explorer activex component using OLE automation. I didn’t find much info on the web, so I post it here as a reminder.

Setting custom headers is in fact supported by the navigate method on the IWebBrowser2 interface as stated in the msdn: simply supply a 5th element. For example, in java it looks something like this:
invoke("Navigate", new Variant[]{
new Variant(url),
new Variant(),
new Variant(),
new Variant(),
new Variant("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")
});

Changing your password from within terminal server session

I always forget this one, so I thought I’d write it down 😉
It’s very easy once you know the alternative keyboard shortcuts available from within a terminal session.
You can simply use Ctrl+Alt+End instead Ctrl+Alt+Del and choose “Change password”.

Another useful one is Ctrl+Alt+Break which switches between Fullscreen and Windowed mode.

Disabling hibernation on windows 7 and why Dirt 2 shows no replay

Yesterday I made this awesome flying finish in Colin McRae Dirt 2 and wanted to view the replay only to realize: there is no replay? That sounded impossible and today, after missing another fine opportunity, I decided to go to the bottom of this. 🙂

Turned out Dirt 2 automatically disables the replay functionality behind your back when there is insufficient free space on your OS partition! That’s right:

  • I have Dirt 2 installed on a partition with 15 GB free space, but that doesn’t matter.
  • It requires 2GB to save a replay!
  • I does not inform the player when it gets turned off (it used to work in the beginning).
  • There is no visual indication whatsoever, that the replay functionality uberhaupt exists but is disabled! It is surgically removed from the gui instead of just a disabled button, for example.

IMO, this is just another example of why consolisation of excellent PC games like CMR is BAD. Anyway, don’t let me go there, let’s focus on hibernation in win 7. 🙂

So I have a 20GB partition for Wintendo 7, but with only 1GB free that does not seem to cut it. Turns out about 6.5GB is taken by the hibernation file (I have 8GB RAM) which I don’t use. So, how to disable that in windows 7? Open a command prompt as administrator and type:

powercfg.exe /hibernate off

That’s all.

Convert PDF to image files

Another entry in my PDF series. 🙂

At work I had to convert a few PDFs into jpeg files. The PDF files actually contain just images, so extracting the images would’ve been as good, but converting PDF pages to images is easier. 🙂 At least on windows. On linux you could use pdfimages, which should be available for your distro through some poppler util package.

A general approach is to use the versatile ImageMagick software. Using the convert command, it’s simply a matter of:

convert -density 200x200 -quality 85% inputfile.pdf outputfile%03d.jpg

to convert inputfile.pdf to a set of jpeg files. Of course you can choose any supported output format you like: png/bmp/gif/etc.. The density option is important as it specifies the output dpi which is only 72 by default. Imagemagick uses Ghostscript to do the pdf reading, so on windows you have to make sure that environment is set up correctly. In my case I had to add its bin directory to the path and set the working dir to the lib path as it didn’t find gs_init.ps otherwise (adding to the path didn’t help). If you know a better way, please let me know in the comments. I also specified the quality option to have a jpeg quality factor of 85, which is 75 by default.

Since I had to process a batch of them, I thought it would be nice to have a cool batch script to do them automatically. Here is what I came up with:

C:
set path=%path%;C:\programs\gs\gs8.54\bin
cd C:\programs\gs\gs8.54\lib
for %%C in (%*) do call :startconvert %%C
goto :eof

:startconvert
convert -density 200x200 -quality 85%% %1 %~dp1%~n1%%03d.jpg
goto :eof

Replace the paths as appropiate. To use the bat file, simply drag and drop one or more pdf file on the bat file. It will put jpeg files in the same directory as the pdf file and number them using 3 digits (%03d printf format). %~dp1 stands for the full path of the 1st argument file, %~n1 for the name only (without extension). Also note you have to escape all other %’s.

Repair grub after windows install

Last week I installed Windows 7 RC (which still works these days, btw) on my brother’s computer so he could practice Autodesk Inventor at home. Since Windows stubbornly still denies the existence of any other OS, it consequently wipes the MBR and installs its own boot loader. Bottom line, we need to reinstall the GRUB boot loader.

There are several ways to do that, but since my brother uses openSUSE, I will use the openSUSE install dvd:

  • Boot from the install dvd
  • Select “Rescue system”. This will give you a console. (I also tried the automatic repair option, but that somehow did not work..)
  • log in with root. no password is asked.

From here on, it is not openSUSE specific anymore:

  • Run “grub”. It starts scanning your disks and after some time you should get a grub> prompt.
  • (Optional) Find the partition where grub is installed:
    grub> find /boot/grub/stage1
  • Set grub’s root partition (example: first harddisk, first partition):
    grub> root (hd0,0)
  • Execute grub installation into MBR:
    grub> setup (hd0)
  • If you would have wanted to install into a specific partition instead of the MBR, simply specify the partition instead:
    grub> setup (hd0,0)

You can find all this info and more in the grub manual.

Flushing the dns cache

As we all know, under windows we can flush the DNS cache with

ipconfig /flushdns

But what is the linux equivalent command? It is so obvious, yet I somehow keep forgetting it. 🙂
Under linux, the standard way to have a daemon reload its configuration, is sending a SIGHUP signal. In case of the name service cache daemon (nscd), this implies flushing its cache!
So you could use the following command to flush the DNS cache if you’re using nscd:

pkill -1 nscd