WMI Queries

WMI scripting can be very useful creating filters to selectively apply Group Policies. It can also be used from the command line to get various bits of information about local or remote hosts.

For example, if you want to find out the version of MS Office installed on your PC, you can use the following:
wmic path Win32_Product WHERE (Caption like "%microsoft office%") get Name, Version

On a remote PC:
wmic /node:remote_pcname path Win32_Product WHERE (Caption like "%microsoft office%") get Name, Version

You can even use it to get information from the BIOS
WMIC BIOS Get Manufacturer,Name,Version

List, start, or stop processes.
wmic process get Name
wmic process call create "calc.exe"
wmic process where name="calc.exe" call terminate

Other useful queries:
Shows MAC Addressess of all network adaptors along with the processes controlling them.
wmic /node:PCNAME path Win32_NetworkAdapter get MACAddress, ProductName, ServiceName

This is only the beginning. Here are a few links for reference.
Windows Management Instrumentation Command
Gathering WMI Data without Writing a Single Line of Code
WMI queries from the command line
WMIC Samples
WMI Classess
Win32_BIOS Class
WMI Tasks for Scripts and Applications
Retrieving System Information
Writing WMI Scripts Using the Scriptomatic Utility

Changing your HOST file in Vista

With the new and annoying UAC feature in Vista, if you try to modify your hosts file, it will not let you save it. It tells you that you don’t have permission. To successfully modify the hosts file, run notepad.exe as an administrator, open the host file, edit and then save.

TIP: To open notepad as an administrator, type ‘notepad’ in the search field in the start menu and press ctrl+shift+enter

WebPage Redirection

There are a number of ways of doing this. The most commonly and easiest to use are meta refreshes and javascript redirects. a better method would be to use a server-side redirect (PHP, ASP, .Net). I will list examples of each and also some of the disadvantages each have.

Meta Refresh
Using this meta tag in your html page will Redirect the page after a given interval to to the address specified.

This code will redirect the page to ibnmasud.com after 5 seconds:
<meta http-equiv="refresh" content="5;url=http://ibnmasud.com" />
Setting the interval to 0 will redirect to ibnmasud.com immediately:
<meta http-equiv="refresh" content="0;url=http://ibnmasud.com" />
Disadvantages:

  • Using the back button will take you back to the redirect page which will then redirect you again. Firefox, Opera, and Safari ignore this behavior and IE users can double-click the back button. Also referred to as “brokeback buttons”.
  • Can easily be disabled on the client side. If disabled, the page will not redirect.

Javascript
Javascript gives you a lot more flexibility in redirecting pages.

Location.href Method
Including this script on a page will immediately redirect visitors to the URL entered. This method creates two items in the browsers history. One for the page including this script and one for the page that this page will redirect to.
<script type="text/javascript">
window.location.href="http://nsfw.ibnmasud.com/";
</script>

So it works the same way as a meta refresh in that it can lead you into a loop if you press the back button.

Location.replace Method
The Location.replace method solves the loop problem by replacing the content of the browsers history with the redirected page’s address, i.e, only one item is created in the browsers history.
<script type="text/javascript">
location.replace(\'http://www.example.com/');
</script>

Disadvantages:

  • Google will not index pages redirected using javascript.
  • Can easily be disabled on the client side. If disabled, the page will not redirect.

PHP
A basic permanent (301) redirect in PHP uses the code below:
<?PHP
// This header tells the client the HTTP status code of the page
header("HTTP/1.1 301 Moved Permanently");
// The client must then be informed where the URI is now located
header("Location: http://www.example.com/example");
?>

Using .htaccess for Redirection

When using the Apache web server, directory-specific .htaccess files (as well as apache’s main configuration files) can be used. For example, to redirect a single page:

Redirect 301 /oldpage.html http://www.example.com/newpage.html

To change domain names:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*oldwebsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.preferredwebsite.net/$1 [R=301,L]

Disadvantages:
Use of .htaccess for this purpose usually does not require administrative permissions, though it can be disabled.

Reset your lost Ubuntu Password

If you ever get locked out of your Ubuntu installation as I found myself to be tonight, you can reset your password quite easily using the following steps.

  1. Power up your computer.
  2. Press ESC at the grub menu.
  3. Press e for edit.
  4. Highlight the line that begins “Ubuntu, KERNEL ………” and press e.
  5. Go to the end of this line, add rw init=/bin/bash and press enter.
  6. Press b to boot your system.
  7. Your system will boot up to a passwordless root shell.
  8. Type in passwd username where username is the username you lost the password for.
  9. Set your password.
  10. Type in reboot.

That is it! you can now log in using your new password. You can even reset your root password here but cannot login with it at the login screen.

Alternate Shortcuts to cut-copy-paste

Did you know there are alternate shortcuts to the commonly used cut (ctrl+x), copy (ctrl+c) and paste (ctrl+v) shortcuts?

Action Shortcut Alternate Shortcut
Cut Ctrl+X Del+Shift
Copy Ctrl+C Insert+Ctrl
Paste Ctrl+V Insert+Shift

These are kind of confusing so I’m sticking to the Ctrl+ shortcuts. For those who use different keyboard layouts like Dvorák the X, C and V keys are placed far apart and awkward to use. In such cases the alternate shortcuts maybe easier to use.