How to Remotely Change a Computer from a Static IP to DHCP

Posted in Blog on January 19th, 2011 by Matt – 2 Comments

We're currently migrating many computers from static IP assignments over to DHCP IP leases. Rather than walking from each computer to the next and manually changing the adapter settings I've been looking for a remote solution that I could either apply to computers one at a time or push out via group policy. Thanks to a VBScript originally written by MatthewBeattie and posted on the technet forums I now have a solution.

 

Changing an adapter to DHCP remotely

 

First you'll need the VBScript file. Copy and paste the following into Notepad. Assuming you want this to execute on both Windows 7 and Windows XP clients, the only line you need to edit is line 31, "subnets = Array("192.168.1.0")" and change the 192.168.1.0 to the network that you'd like this file to execute on.

'----------------------------------------------------------------------------------------------------------------------------
'Script Name : EnableDHCP.vbs
'Author   : Matthew Beattie
'Created   : 29/12/10
'Description : This script enables DHCP for systems on specified subnets.
'----------------------------------------------------------------------------------------------------------------------------
'Initialization Section  
'----------------------------------------------------------------------------------------------------------------------------
Option Explicit  
Dim objFSO, wshShell, wshNetwork, hostName
On Error Resume Next
 Set objFSO   = CreateObject("Scripting.FileSystemObject")   
 Set wshNetwork = Wscript.CreateObject("Wscript.Network")  
 Set wshShell  = CreateObject("Wscript.Shell")  
 hostName    = wshNetwork.ComputerName
 ProcessScript
 If Err.Number <> 0 Then
 Wscript.Quit  
 End If
On Error Goto 0
'----------------------------------------------------------------------------------------------------------------------------
'Name    : ProcessScript -> Primary Function that controls all other script processing.  
'Parameters : None     ->  
'Return   : None     ->  
'----------------------------------------------------------------------------------------------------------------------------
Function ProcessScript
 Dim ipAddress, macAddress, product, systems, system
 Dim subnets, subnet, network, continue
 product = ReadRegistry("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProductName")
 systems = Array("Windows XP","Windows 7")
 subnets = Array("192.168.1.0")
 '-------------------------------------------------------------------------------------------------------------------------
 'Ensure this script only applies to client operating systems. (Don't configure servers with DHCP!)
 '-------------------------------------------------------------------------------------------------------------------------
 Continue = False
 For Each system In systems
 If InStr(1, product, system, vbTextCompare) <> 0 Then
 continue = True
 Exit For
 End If
 Next
 If Not continue Then
 Exit Function
 End If
 '-------------------------------------------------------------------------------------------------------------------------
 'Enumerate the IP and MAC Addresses from the local system.
 '-------------------------------------------------------------------------------------------------------------------------
 If Not GetIPConfig(hostName, ipAddress, macAddress) Then
 Exit Function
 End If
 '-------------------------------------------------------------------------------------------------------------------------
 'Ensure the script continues processing only if the systems IP address is within the specified subnets.
 '-------------------------------------------------------------------------------------------------------------------------
 network = Left(ipAddress, InStrRev(ipAddress, ".")) & "0"
 continue = False
 For Each subnet In subnets
 If StrComp(subnet, network, vbTextCompare) = 0 Then
 continue = True
 Exit For
 End If
 Next
 '-------------------------------------------------------------------------------------------------------------------------
 'Ensure the script only continues processing if the systems IP address is within the specified subnets.
 '-------------------------------------------------------------------------------------------------------------------------
 If Not continue Then
 Exit Function
 End If
 '-------------------------------------------------------------------------------------------------------------------------
 'The system is within one of the specified subnets. Enable DHCP on all enabled interfaces that have static IP Addresses.
 '-------------------------------------------------------------------------------------------------------------------------
 If Not EnableDHCP Then
 Exit Function
 End If
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name    : ReadRegistry -> Read the value of a registry key or value.
'Parameters : key     -> Name of the key (ending in "\") or value to read.
'Return   : ReadRegistry -> Value of key or value read from the local registry (blank is not found).
'----------------------------------------------------------------------------------------------------------------------------
Function ReadRegistry(ByVal key)
 Dim result
 If StrComp (Left (key, 4), "HKU\", vbTextCompare) = 0 Then
 Key = "HKEY_USERS" & Mid (key, 4)
 End If
 On Error Resume Next
 ReadRegistry = WshShell.RegRead (key)
 If Err.Number <> 0 Then
 ReadRegistry = ""
 End If
 On Error Goto 0
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name    : GetIPConfig -> Enumerates the IP & MAC Address of the system via WMI
'Parameters : hostName  -> String containing the hostname of the computer to enumerate the IP configuration for.
'      : ipAddress  -> Input/Output : Variable assigned to the IP Address of the system.
'Parameters : macAddress -> Input/Output : Variable assigned to the MAC Address of the system.
'Return   : GetIPConfig -> Returns True and the systems IP & MAC Address if successful otherwise returns False.
'----------------------------------------------------------------------------------------------------------------------------
Function GetIPConfig(hostName, ipAddress, macAddress)
 Dim wmi, ipConfig, query
 GetIPConfig = False
 ipAddress  = ""
 macAddress = ""
 query    = "select * from Win32_NetworkAdapterConfiguration where IPEnabled = True"
 On Error Resume Next
 Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & hostName & "\root\cimv2")
 If Err.Number <> 0 Then
 Exit Function
 End If
 For Each ipConfig in wmi.ExecQuery(query)
 If Err.Number <> 0 Then
 Exit Function
 End If
 ipAddress = ipConfig.IPAddress(0)
 macAddress = ipConfig.MACAddress(0)
 If ipAddress <> "" And ipAddress <> "0.0.0.0" And MACAddress <> "" Then
 Exit For
 End If
 Next
 On Error Goto 0
 GetIPConfig = True
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name    : EnableDHCP -> enables DHCP on all interfaces that have static IP Addresses.
'Parameters : hostName  -> String containing the hostname of the system to enable DHCP on.
'Return   : EnableDHCP -> Returns True if DHCP was enabled otherwise False.
'----------------------------------------------------------------------------------------------------------------------------
Function EnableDHCP
 Dim query, wmi, adapter, adapters, result
 EnableDHCP = False
 query   = "Select * From Win32_NetworkAdapterConfiguration Where DHCPEnabled = False And IPEnabled = True"
 On Error Resume Next
 Set wmi   = GetObject("winmgmts:\\" & hostName & "\root\cimv2")
 Set adapters = wmi.ExecQuery(query)
 For Each adapter In adapters
 result = adapter.EnableDHCP()
 Next
 If Err.Number <> 0 Then
 Exit Function
 End If
 On Error Goto 0
 EnableDHCP = True
End Function
'----------------------------------------------------------------------------------------------------------------------------

Executing Manually on Remote Machines

For simplicity, place the previous EnableDHCP.vbs file either in your root C:\ or on a file share.

Download and install PsTools available here. Once installed launch a command prompt. Change to the PsTools directory with the following command:
cd \pstools

The following assumes your account has administrative privlidges on both the local and remote machine and you've saved the vbs file locally to C:\

Execute the file on the remote machine with the following command:
psexec \\<RemoteComputerNameOrIP> cscript \\<LocalComputerName>\C$\EnableDHCP.vbs

If you need to specify a remote administrator user use the following command:
psexec \\<RemoteComputerNameOrIP> -u <RemoteAdmin> cscript \\<LocalComputerName>\C$\EnableDHCP.vbs

The command will not execute cleanly because (obviously) your computer is going to lose its network connection to the other computer while it changes to DHCP.

You must invoke cscript to execute the command as by default .vbs files will not execute remotely.

Executing via Group Policy

(I'm not responsible if you screw up your domain)

Save the EnableDHCP.vbs to a file share location that allows everyone to read.

If you don't already have your computers segregated into Organizational Units, create a new OU and Create and link a new Group Policy to it.
Right click your domain > click New Organizational Unit > right click the OU you just created> click Create a GPO in this Domain, and Link it here. > name it something useful like "Enable DHCP" > Drag computers into the new OU

The best time to run this script, in my opinion, is going to be during computer startup. Edit the Group Policy you previously created to launch the script.
Right click the previously created Policy > Edit > expand Computer Configuration > Windows Settings > Scripts > double click Startup > click Add > click Browse > find the script > click OK a couple of times

That should do it!

Personally, because of the way we have some things set to start, I'm using a combination of psLoggedon to find computers that noone is logged into, then executing the script on those computers. Please always test on a non production computer before you start making big changes like this.

Thinning down FireFox 4's Tab Bar

Posted in Blog on January 19th, 2011 by Matt – 2 Comments

FireFox4 Beta 9 is out and they've made great improvements toward efficient vertical space use. Now when you maximize the main window the tabs move into the title bar! Here's how to set the tabs to always be in the Title Bar of the window even when not maximized.

 

Setting FF4's Tabs to Always be in the Title Bar

 

We need to add a couple of lines to your userChrome.css file. The userChrome.css file is located in the following locations:

XP: C:\Documents and Settings\<user>\Application Data\Mozilla\Firefox\Profiles\<profile>\chrome\
Vista\7: C:\Users\<user>\AppData\Roaming\Mozilla\Firefox\Profiles\<profile>\chrome\

Open that file in Notepad or another text editor and add the following lines to it:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

#main-window[sizemode=normal][tabsontop="true"] #toolbar-menubar[autohide="true"] {
margin-top:-20px;
margin-left:80px;
}
#main-window[sizemode=normal] #navigator-toolbox[tabsontop="true"] > #toolbar-menubar[autohide="true"] ~ #TabsToolbar {
-moz-padding-start:80px!important;
-moz-padding-end:110px!important;
}
#appmenu-button{
padding-left: 8px !important;
padding-right: 8px !important;
height: 22px !important;
}

You'll also need to set FireFox to always display the tab bar (Options > Tabs > Always show the tab bar) so as not to cause issues when only a single tab is open.

Most credit for this version goes to sdrocking with this post as UserStyles.org

Redirecting Lotus Notes Data to a Network Share

Posted in Blog, Tutorial on January 11th, 2011 by Matt – 3 Comments

I currently redirect users' Lotus Notes data folder (the folder that contains their ID files as well as other personal files) to network shares. This allows for users to roam from computer to computer in our office and always have their data available. As far as IBM is concerned this is an unsupported configuration, they will not help you if you have issues. We're currently using the 8.5.1 client with FixPack 4 installed.

Preparing Users Data for the Network

The first step is to copy a users Data folder onto a network share. The location of the share should be the same for all users. For example; each of our users has a "home" drive mapped to H: where they store their personal documents. Under this drive we have a folder titled "lotus" that we place a copy of the contents of their Data folder.

After you've copied the contents to the network share, you'll need to edit the users notes.ini file thats located within that share. The line you'll need to change in that file is "Directory=C:\..." change it to the location where you've copied their data. In my situation I change that line to "Directory=H:\lotus"

Redirecting Lotus to Look in the Network Share

Now that we have our user data in a network location, we need to tell lotus to look there and not in the usual Data folder location. There are a couple of methods to do this. First is using a registry entry and the second is actually editing the shortcuts. In my experience the shortcut method has been much more reliable.

Registry method:
For each user add the following registry entry (maybe as part of a log on script)
[HKEY_CURRENT_USER\Software\Lotus\Notes\8.0] "NotesIniPath"="H:\\lotus\\notes.ini"

Redirecting via the Registry

 

Shortcut method:
Edit the shortcuts on the all users desktop and the start menu so the target line is as follows (quotation marks and all)
"C:\(Install location of Lotus Notes)\notes.exe" "=h:\lotus\notes.ini"

Redirecting via Editing Shortcuts

Some Notes (Get it?!)

Currently on Windows 7 I do a Single User Install of the Standard Client. I've found that if I do a multi-user install I get prompted for my ID password for ntaskldr.exe. Googling has not returned a way to correct this.

While this modification does allow users to roam between computers, they can not have more than one instance of Notes open at a time.

After you've successfully got Notes functioning redirected you can delete the Data directory from the local machine. As long as your redirects are in place, it will never be recreated.

My users are not administrators on their machines. A single user install by default stores the users Data folder in the Program Files directory, which a user can't write to. But since we're redirecting that folder to a writeable location the users never have any permission issues.

Re-enable URL AutoFill on FireFox 4

Posted in Blog, Tech on September 23rd, 2010 by Matt – Be the first to comment

The default behavior in Safari has always been that, while typing a URL, enter selects the most likely recommendation. Its super efficient. Why it's not the default of all browsers, I'll never know. FireFox before version 4 had the ability to auto-complete address bar suggestions. In about:config the option was called browser.urlbar.autoFill. With Version 4, that option no longer functions. As usual an extension has come to the rescue!

The "Enter Selects" FireFox Add-On

The enter selects add-on doesn't truly auto-fill the remainder of the the URL bar. Instead it simply selects the first suggested awesomebar result for whatever you've typed. The end result is the same. A quick "g, enter" gets me to Google, "l, enter" gets me to lifehacker, "j, enter" gets me to Jalopnik. I know I could have set up some tags on my bookmark entries, but this is a much more effective method that changes over time as the sites I visit change.

Another entry goes on my FireFox must have extension list.

Thinning Down FireFox 4's Tab Bar - Update!

Posted in Blog, Tech, Tutorial on September 16th, 2010 by Matt – 11 Comments

This post is now outdated, please see the update available here:

http://gdgtry.com/2011/01/thinning-down-firefox-4s-tab-bar-2/

My previous post about modifying FireFox 4's tab bar layout has been one of the more popular posts on my blog. After updating to FF4 Beta 6 the modification broke, but I've found a solution:

#navigator-toolbox[tabsontop="true"] #TabsToolbar{
padding-left: 80px !important;
padding-right: 102px !important;
padding-top: 2px !important;
margin-top: -25px !important;
}

#appmenu-button{
padding: 3px 5px 3px 5px !important;
height: 20px !important;
}

As you can see, the only change is we tell the tab bar to move up 25 pixels from where it was. We also ditch the tab position as fixed as it's not really necessary.

FireFox 4 with a better tab layout

This gets us back to our old style. I haven't had time to test all the edge cases to see if it messes anything up, but it should get your normal browsing bar back to an acceptable size.

Finding out where a picture was taken using EXIF info

Posted in Blog, Random, Tech, Tutorial on August 18th, 2010 by Matt – 13 Comments

Alternate title: How to creepily stalk people using their pictures.

Since I've gotten an iPhone 4 I've stopped carrying a normal camera with me on outings. I find the iPhone's camera more than sufficient for most of my photo needs. Many other people are also doing the same. The fun thing about most camera phones now, is that they tag image information with GPS coordinates. Thanks to some easy online tools, you can now track people only by their pictures.

Lets get an example. I did a Google Search for "shots taken with my iPhone" and the first result is a blog with "9 Cracking Shots Taken With My iPhone". The second picture posted is a pic taken on a road supposedly in Death Valley. Lets see if it is.

A test image for GPS EXIF inforation

We can download a program to view where the photo was taken via its EXIF information. Programs like "Simple EXIF Viewer for Mac OSX" work well. Or you could install a FireFox extension like "EXIF Viewer", it's a very nice way to quickly view information for any image embedded on a web page. But both of these seem silly to install when you probably only need to view EXIF info once in a blue moon.

My new favorite way to view where photos were taken is to use online tools like "Jeffery's EXIF Viewer" or the "Find EXIF" website. So, using our example, we would: Right click the image, Copy Image Location, Paste the image location into one of the online tools. In this example I've used Jeffery's EXIF viewer that embeds a nice little Google Maps pin of where the image says it was taken. Results from the EXIF GPS information

And if you follow the links over to Google Maps, and drop a street view pin as close to GPS data as possible, you get this:

Results from the iPhone's GPS EXIF info

You can view the actual Google Street view location here. Pretty cool.

Some information about laptop docks

Posted in Blog, Tech on August 13th, 2010 by Matt – Be the first to comment

There are two types of docks available for laptops:

Dock for the Dell Latitude Series

  1. Docks that require your laptop to be open and running to use and use a low performance method of connection. These docks are available for almost any laptop and use a single USB cable to hook up. I really won’t recommend them for a couple of reasons: They’re low performance and they require that the laptop be sitting open and have the laptop screen on when plugged into them. This means if you want to type on your other screen with a real keyboard and mouse, you’ll have to have your laptop sitting out and open on the desk.
  2. Docks that have a dedicated port and sit in a cradle. These are high performance and do not require your computer to be open when in use. In addition these docks usually include significantly more connectivity options. This is the type of dock I use every day here at work. I recommend this style over the USB style.

If you want to go with a cradle style dock then that limits your options. There aren’t many 17” laptops compatible with a cradle style of dock. The Dell Latitude laptop series is the best choice at this time. Their larger size laptop has a 15.6” screen.

If you really want a larger computer and don’t mind having your laptop sitting out while docked or just want to skip the dock all together, then you have more options.

Targus Universal USB Dock

Targus Universal USB Dock

USB docks like the the Targus Universal USB Dock allow almost any size and style computer the ability to have a dock.

Alien Swarm - A Casual Gamer's Game

Posted in Blog, Gaming, Random on July 28th, 2010 by Matt – 1 Comment

Originally released as a mod for Unreal Tournament 2004, Alien Swarm has been bought, refreshed and released by Valve as a free mod for their Source Engine. Being free, there's absolutely no reason to not download this game and give it a shot. According to my Steam profile, I've managed to put in 12 hours of play into Alien Swarm since it's release 10 days ago. That's a lot for someone like me who only manages an hour or two after work. I love this game and would gladly pay for it. Let me tell you why.

The long description: Alien Swarm is a four player, co-op, online game, that's played in the top-down perspective. The goal is to travel through various levels with four companions played by other players and complete various tasks to try to rescue a colony on another planet that's been over-run by alien creatures. There are four roles to choose from that can give each player a boost in various abilities.  Included among the many abilities: shooting, explosions, hacking and healing. A large selection of weapons are available with each person carrying two to allow for some flexibility. Tactics can be discussed over the games integrated voice chat or drawn on the in-game level map, similar to football plans (though often with much more penis drawing).

The short description: Kill massive quantities of aliens with three buddies.

For a free game, the quality is outstanding. Alien Swarm can be compared to games that many other companies wouldn't flinch at charging $50 for. However, being free, there are some downfalls: There isn't a single player campaign or an offline campaign (there is an offline practice mode). You can only play with three other real people, no bots. There's only one official campaign available, but with the modding tools freely available I expect many community developed campaigns swiftly appearing.

Here's why I really love this game: The average level requires about 8 minutes to complete. That means, even if you only have about 10 minutes to spare, you can drop in, play a level and pop out. Unlike many other online games, Alien Swarm doesn't require time for you to "warm up" and get into the game. Most levels start slow and build up to a crescendo at the end.

Alien Swarm is the definition of a casual gamers game. It's the antithesis to StarCraft 2. If you know my opinion on StarCraft 2, you know that's a good thing. Where StarCraft2 is a frustrating grind that requires a significant time investment to get anywhere, Alien Swarm is a relaxing walk through fields of mindless slaughter. That's not to say Alien Swarm isn't intense. The finales to the levels are often finished on the brink of death, with much yelling and laughing over the voice chat.

Once the mod community release a few more campaigns, Alien Swarm will really hit it's stride. Go download it now if you haven't. There's no reason not to. It's the best game for its price, bar none.