The Thinkvantage Power Manager COM object.

If you have IBM/Lenovo Thinkpad Laptop with Thinkvantage Power Manager installed you can use the PWRMGR object to check the battery status, charging progress, remaining time and also change the screen brightness.
This is undocumented method, probably you can't make any damage on your hardware, however use it at your own risk.
These examples were tested on Thinkpad T60 with windows 7.

First, let's get the list of avaliable objects:

gwmi win32_classiccomclasssetting | ? { $_.InprocServer32 -like '*PWRMGR*' } | select VersionIndependentProgId

We will work with PWRMGR.Slider and PWRMGR.Battery.
Next, let's create a new instances and check avaliable methods and properties:

$slider = new-object -com PWRMGR.Slider
$battery = new-object -com PWRMGR.Battery

$slider | gm
$battery | gm

and now the cool part, unplug the power cable from your laptop and execute following commands :


as you can see we have an informaiton about the remaining percentage and time (which are the same as on the taskbar), Plug back the power cable and run these commands:


this time we've got the charging time, also the ChargeStatus was changed, you can use this function to detect if your laptop is on battery or not.
It's important to execute Update() method to get the current values before you check any property.

And the last cool trick is changing the screen brightness, this time we'll use PerformBrightnessSimulation from PWRMGR.Slider object.

.. (step by 10)

Of course I didn't exhaust the subject, these was only few things that I found exploring that object.

If you prefer Python as your scripting language you can use pywin32 to work with the COM objects.

import win32com.client
battery = win32com.client.Dispatch("PWRMGR.Battery")

Powershell, Enabling/Disabling Network Card, two methods.

Yet another powershell script from my collection. This time it's a connection of two different methods of changing the state of the network card. I read on few forums that people are looking for a script that could disable or enable the network card, however some of them are using windows xp but the others Vista and higher. The problem is that on Vista and 7 we can use WMI to make this job quickly and clean but on Windows XP it's not that simple, we need to use the com object to do that.
The following script checks the operating system version and decides which method must be used.
If you are using windows xp, you will need to change highlighted variables depends on your os-language.

At the end of this post I've put few lines of code that will help you determine the values for variables.

Check values for your operating system (these depends on the system language):

$shell = New-object -com Shell.Application
(($shell.NameSpace(3).Items() | ? { $_.Path -like '*7007ACC7-3202-11D1-AAD2-00805FC1270E*'}).GetFolder.Items() | ? { $_.Name -eq 'change to your interface Name' }).Verbs() | Select Name

External MessageBox

I wrote External MessageBox about year ago for use in a batch scripts to control execution flow and communicate with a user.
The utility is very simple, as the name suggests it shows the dialog box with specified caption, message, icon and one or several buttons. If you look at the source code you'll see that it just a call of the system MessageBox function (more about it here).
One of the cool feature is that you can pin the MessageBox to another running application, and block it until the user click one of the buttons.
Here is an example:
  1. Run windows calculator (calc.exe),
  2. Open cmd shell and change directory to where you unzip the emsgbox.exe,
  3. run following command:

emsgbox.exe /n calc.exe /c Calculator Info /m 2+2=5 /t 48

The calulcator will be blocked until you click OK button.
The button number which user has clicked is placed in %errorlevel% environment variable (or $lasterrorcode - powershell), however this method works only if you write a batch script or in the cmd shell when you use emsgbox.exe as follow:

start /wait emsgbox.exe /n calc.exe /c Calculator Info /m 2+2=5 /t 48
echo %errorlevel%

(as I said if you use it in batch script you don't have to use "start /wait" statement)
Link to the project/download page:

Powershell, problem with the comma character.

I'm using powershell a lot, and I want to use it like a normal shell environment, but I can't.

Well, I give you example, try this in powershell:

nmap -sS -p80,22 -PN -n

The comma character is the reason. It is a some kind of special character in powershell so you can't use it like that. In that case lets try the same command with ps escape character (backward apostrophe (`))

nmap -sS -p80`,22 -PN -n

still not working, but the error is different.

So how to fix this?

Solution number one (add space between -p and 80):

nmap -sS -p 80`,22 -PN -n

or solution number two (specify a protocol):

nmap -sS -pT:80`,22 -PN -n

What is my external IP?

Sometimes, when I'm connected to the local network I have to check what is my external IP address. If I'm on an unknown network and have no access to the router or the server configuration I need external IP to check who is the ISP or what services are avaliable behind the NAT.
There are two ways to get the external IP. First, is to check the IP configuration on the NAT server or router, but this works only if:
  • the router is directly connected to the internet, not to the another router on the other lan network,
  • the static IP address is configured,
  • you have an access to the configuration

Second, and most easiest way is to open your browser, go to your favorite search engine, search for 'what is my ip' and click the first result from the top. If you are lucky, that address is your external IP. If you for some reasons have no luck, check the links at the end of this post.
The other thing could be the command line instruction that will return the IP address, so we can use it for other purposes, as a part of some other scripts. One of possible way is to write a script that fetch the website and get the IP address from its content. Most of the WHAT-IS-MY-IP pages are not script friendly since they are regular web pages full of html tags and it is hard to dermine where the IP address is placed and even if you find it you can never be sure that it is correct (you may find not just one). Anyway, if you want to search through the content of the page,
I recommend you to use Regular Expression:


Specially for this post, I searched for those websites that shows only IP addresses, no html tags and other content.
Here is the list:

And the script that has been ported to a different platforms:

(New-Object System.Net.WebClient).DownloadString('')

Python 3:
import urllib.request
page = urllib.request.urlopen('')
ip ="utf8");
print (ip)

Python 2:
import urllib
ip = urllib.urlopen('').read()
print ip

Linux (bash) using wget:
wget -qO -

Scanning for available WLAN networks with PowerShell

Everyone interested knows how great tool netsh is if it comes about network configuration on Windows, especially when you are command line geek. Personally, I am often using it for setting ip addresses or managing Windows firewall. Starting from Windows Vista Microsoft has changed few and add new contexts giving you more control over network configuration. One of my favorite is "wlan". If you use Windows as your Wireless connection manager and, as I mentioned you are command line person the netsh wlan context is just for you. Not every wlan settings are changeable, but those that are available are enough to control wireless configuration through command line.
Few days ago I wrote a script that transform the result from 'netsh wlan show networks' command into something that looks familiar to airodump-ng scan, I think table form is more readable.

Here is the script (oh, I forgot to mention, this is PowerShell script):

Usage example: