PING a sequence of IP addresses from the Command Prompt

Have you ever needed to find a free IP address in a given range? Or, have you ever needed to find out which IP addresses in a range are in use? Sure, you can type a bunch of PING commands and note the results. Or, you can loop it:

for /l %i in (96,1,111) do @ping -n 1 10.1.0.%i | find "bytes=" 

Simply replace the “96” and “111” with the start/end range, and “10.1.0” with the subnet of your choosing. The “1” in the range is the counter, so if you want to skip values, simply change this number. The output will only list those devices which receive a reply from the PING.

If you have multiple subnets, you can loop the loop, like this:

Or, if you want it all in a fancy batch file, paste the following into a batch file (I call it “pingall.bat”).

@echo off
if "%3" EQU ""  (
    echo pingall.bat ^<networkip^> ^<startip^> ^<endip^> [step]
    goto :eof
)
setlocal
set networkip=%1
set startip=%2
set endip=%3
set step=%4
if "%step%" EQU "" set step=1
for /l %%i in (%startip%,%step%,%endip%) do ping -n 1 %networkip%.%%i | find "bytes="
endlocal

To run this, you specify the network (class C only in this example), the start IP, the end IP, and optionally the step (which defaults to 1). Your execution will look something like this.

C:\utils>pingall.bat 10.1.2 211 215
Reply from 10.1.2.214: bytes=32 time<1ms TTL=128
Reply from 10.1.2.215: bytes=32 time=2ms TTL=64

It’s a quick way to see what’s online in an IP range — and sometimes, that’s exactly what you are looking for.

Create a Windows shortcut to map and open a network drive

After all these years, users still love their drive letters. And inevitably, I still hear the complaint, “My X: drive has disappeared!” Which makes me wonder a few things.

  1. What does the X: drive point to?
  2. Why are we still using drive letters?

It’s not my place to change the world, but we can make it easier on ourselves and our users. So when you have a user who uses network shares mapped to drive letters, create a shortcut on their desktop, and use the following command line in the shortcut — just specify your desired drive letter and your server and share information.

cmd /c "net use x: \\servername\sharename /persistent:yes | explorer x:"

This will both re-map the drive letter if it isn’t mapped, and open a Windows Explorer window to the drive letter. You now put the power in the hands of the user, and free up your time to write blog posts about how you put the power in the hands of the user.

OneDrive sync fails because filename starts with a space

Windows (and, it seems, Microsoft in general) does not like filenames that start with a space. You can’t even create them in Windows Explorer — go ahead and try! If you start the name of a file or folder with a space, Windows will remove the space for you — automatically. Frustrating, eh?

Regardless, there’s sufficient ways to wind off with a file that starts with a space, and inevitably, if you use OneDrive, you’ll get sync errors, because OneDrive (being Microsoft) does not like filenames that start with a space.

The logical step would be to rename the file in Windows Explorer and remove the leading space — but that doesn’t work; Windows will tell you that the filename already exists. (Apparently, those spaces are ignored in more places than one.)

So how do you solve this? Two ways.

  1. Rename the file to something entirely new without a leading space.
    OR
  2. Open a command prompt and type this:
    ren ” myfile.txt” “myfile.txt”

The command prompt lets you use spaces (provided they are in double quotes), and will (accurately) know that a file name with a leading space is not the same as the same file name without the leading space.

Best solution? Avoid the darn spaces altogether.

Installing and configuring memcached and PHP on Windows

After upgrading the CSFBL forums to vBulletin 4.0, I noticed that performance was slightly worse than in the previous version. A little searching revealed that vBulletin supports memcached (an in-memory distributed caching system). Since I’ve got RAM to spare, I figured this is worth a shot.

Unfortunately, getting memcached running on the server (Windows Server 2008 R2 64-bit) took a few tricks, and getting memached running through IIS/PHP was another. To help other people through the same process (and to remind myself in the future), I’ll share the installation and configuration steps that worked for me below.

Downloading and configuring memcached

The official distributions of memcached are written for Linux systems, so the first task is finding Windows binaries. The memcached project site, fortunately, has links to Windows binaries, which are hosted by NorthScale. Both 32-bit and 64-bit versions are available.

(Note that NorthScale also offers their own free distribution of memcached, but I was unable to get this to run on my system.)

Versions of memcached prior to 1.4.5 supported a command-line option that would register memcached as a Windows service (as in memcached -d install), but this option was removed in version 1.4.5. The simple alternative is to schedule memcached.exe to run using the Task Scheduler service (Windows 2008/Vista/7).

You can create a task to run memcached on system startup using the following command line:

schtasks /create /sc onstart /tn memcached /tr "'c:\dev\utils\memcached-amd64\memcached.exe' -m 128"

Note the -m 128 argument; this tells memcached to use up to 128MB of RAM. There are other command line arguments available; most useful aside from -m are -l (to specify what IP addresses to bind to) and -vv (to add verbose logging to the console, useful for testing).

Integrating memcached with PHP

In order for PHP to use memcached, you must download the PHP memcached library and add it as an extension to PHP.

PHP extensions can be downloaded from http://downloads.php.net/pierre. Many different extensions are in here; the one I used was php_memcache-5.2-nts-Win32-vc6-x86-20090408.zip. This extension matches two key requirements:

Getting the right version of the extension is important; download the thread-safe version, or the PHP 5.3 version, and it simply won’t work.

Once downloaded, take the php_memcache.dll and put it in the ext folder in your PHP directory (for me, c:\Program Files (x86)\PHP\ext). Then, open the php.ini file (in your PHP directory) and add the following line to the end:

extension=php_memcache.dll

Restart IIS (from the command line, type iisreset), and if you did everything right, memcached should now be available to PHP. If you want to check, you can create a phpinfo page; if php_memcache is listed in the output, the extension is registered correctly.

Other links

To find out more about PHP, memcached, and Windows, check out the following links.

Can’t install TFS, or the .Net Framework, or almost anything? Check your security policies!

On a newly-rebuild Windows 2003 server, I set out to install TFS 2008. After installing SQL 2005, and SQL Reporting Services, and SQL Analysis Services, and SQL 2005 Service Pack 3, I fired up the TFS installer, only to ultimately get the dreaded “Send Report/Don’t Send Report” dialog box.

Team Foundation Server encountered a problem during setup

Nice! Looking at the install log was so much more revealing.

[09/14/09,13:33:33] Microsoft .NET Framework 3.5: ***ERRORLOG EVENT*** : Error code 1603 for this component means "Fatal error during installation."
[09/14/09,13:33:33] Setup.exe: AddGlobalCustomProperty
[09/14/09,13:33:33] Microsoft .NET Framework 3.5: ***ERRORLOG EVENT*** : Setup Failed on component Microsoft .NET Framework 3.5

Odd, why won’t the .Net Framework 3.5 install? Shouldn’t be hard to fix by downloading the .Net 3.5 installer and installing it manually. Or should it? That didn’t work, either. Again from the install log.

[09/14/09,13:42:31] WIC Installer: [2] Error code 1603 for this component means "Fatal error during installation."
[09/14/09,13:42:31] WIC Installer: [2] Setup Failed on component WIC Installer
[09/14/09,13:42:33] WapUI: [2] DepCheck indicates WIC Installer is not installed.

What does Windows Imaging Component have to do with anything? Probably nothing, but Windows Installer does, so let’s take that route. I download the latest Windows Installer installer (!) and attempt to install (!!) manually. Too bad that didn’t help, either — but at least this time I got an error message seemed to point me in the right direction.

Setup Error: You do not have permissions to update Windows Server 2003.

Now we’re getting somewhere. Googling that exact error message brought me to a Microsoft knowledge base article (KB888791) which told me:

Update.exe version 5.4.1.0 and later versions require that the user who installs the software update is an administrator with certain user rights.

A quick look at the policy settings on the server showed me that the Administrators group didn’t have the “Back up files and directories” right, as shown below.

A quick request to IT to grant the Administrators group the missing right, and viola! TFS, and other software, is finally installing.

Apparently, this may have been the root cause issue for software not installing or uninstalling properly a week or so ago, when I put in the original request to have the server rebuilt, which leads me to wonder. If Update.exe knows what rights it requires, why doesn’t it check for them, why doesn’t it provide a clear error message indicating what is missing, and why doesn’t this information bubble up appropriately to MSI installers that use Update.exe?

The world may never know.

A free replacement for the Windows defragment utility

Defragmenting hard drives is something that is often unnecessary, but when it is necessary, most people run the built-in Windows “Disk Defragmenter” utility. It’s serviceable, but there is a better option: JkDefrag.

There’s a few things that make JkDefrag an improvement over what Windows offers:

  • It runs on anything that mounts like a disk drive — including USB drives and memory sticks.
  • You can run it from Windows, from a command line, or as a screen saver.
  • It offers several different optimization strategies.
  • It can be configured to defragment specific drives, files, or folders, or to exclude defragmenting specific drives, files, or folders.
  • You can run it in the background and tell it to run at less than full speed.
  • It’s continually developed by a person who you can actually talk to via an online forum.
  • There’s no installer — just extract files from a ZIP archive into a directory and run the executable.
  • It’s free, as in free beer, and open source.

Hats off to Jeroen Kessels for writing a fine utility and making it available for free. He doesn’t even ask for donations (too bad, because I’d have sent him a few bucks if he did!).

Separating SQL script files generated by Microsoft SQL (by type)

There’s one great feature in SQL: the “Generate Scripts” command. Unfortunately, it has one limitation: the default filenames of scripts look something like this:

dbo.fnc_PlayerValue.UserDefinedFunction.sql
dbo.UserSelect.StoredProcedure.sql

I’d much prefer the filenames to match the object name, without the owner (‘dbo’) or object type. In other words, I’d prefer the above two files to look like this:

UserDefinedFunction\fnc_PlayerValue.sql
StoredProcedure\UserSelect.sql

How do we get from point A to point B without a lot of manual file copies and renames? We use the FOR command!

First, create a subdirectory for each object type (Table, StoredProcedure, UserDefinedFunction, View, Schema, Trigger, and User), then run the following from a command prompt.

for %i in (*.User.sql) do for /f "delims=., tokens=1-3" %j in ("%i") do move %i %k\%j.%l
for %i in (*.Schema.sql) do for /f "delims=., tokens=1-3" %j in ("%i") do move %i %k\%j.%l
for %i in (*.Trigger.sql) do for /f "delims=., tokens=1-3" %j in ("%i") do move %i %k\%j.%l
for %i in (*.sql) do for /f "delims=., tokens=1-4" %j in ("%i") do move %i %l\%k.%m

The command above will look for each file with a *.sql extension in the current directory. For each of those files, it copies it to a directory based on the type of file, and ensures the new file only includes the object name and the .sql extension. So much cleaner now!

Note that this will not work if any folder in the full path to the SQL files has a period in it!

Updated 2009.11.10 to support Trigger, User, and Schema scripts.

Solving distorted sound issues in Boot Camp

I’ve been running a rather expensive Windows Vista computer lately, thanks to Boot Camp. However, two problems continue to plague me:

  1. The latest Boot Camp update from Apple will not install successfully.
  2. Sound is distorted when playing games, typically those using multiple sound channels (i.e. pretty much all games).

Fortunately, I finally found the fix for #2. It wasn’t Vista SP1, and it wasn’t figuring out a way to install the latest Boot Camp drivers (still can’t figure that one out).

The solution: Download and install the latest Realtek HD drivers. Thanks to a post on mac-forums.com which pointed me to the Realtek High Definition Audio drivers page.

One odd quirk: It took two installations of the Realtek drivers before it worked. After the first installation (which removed the old drivers) and a restart, there was no sound at all in Windows. A re-installation of the same Realtek drivers (and another restart), and it’s all working fine…

Just in time for Age of Conan, which should be arriving in a day or two! (It’s for work, really… I’m doing research for the soon-to-be-released web site, www.aochub.com).

ATI video drivers may be more stable than nVidia drivers (but does it matter?)

A friend of mine (who is a reseller for Diamond Multimedia) forwarded me an email last night which shed some interesting insight into video card driver stability with Windows Vista:

ATI Provides Proven Driver Stability

Microsoft is currently involved in a class action lawsuit regarding problems with its “Vista Capable” marketing. As part of this trial, hundreds of pages of internal Microsoft emails were unsealed. If you want to take a look at them, here they are (pdf). Aside from providing some interesting insight into what goes on internally at Microsoft leading up to the release of a new OS, there is also a ranking of the cause of crashes logged with Microsoft.

The rankings, based on crashes logged with Microsoft in 2007, paint a very positive picture of ATI’s graphics drivers. For instance, 28.8% of all Vista crashes were caused by nVidia drivers, compared with 9.3% caused by ATI. When you adjust for market share, we still see that Vista systems are almost half as likely to crash when using an ATI graphics solution…

Author: Blake Eggleston

Now that may be marketing gumbo, but if not, it’s very intriguing.

Of course, the one critical fact missing is how often crashes are caused by video drivers. Do video drivers cause crashes once every 50 hours? 100 hours? 1,000 hours? More than that?

If I use a computer 80 hours a week (rough estimate), a crash every 80 hours is a crash once a week. To me, that’s too much. However, if a crash occurs every 800 hours, that’s one crash every 10 weeks, something which I can tolerate.

As the saying goes, “Better is the enemy of good enough.” nVidia drivers are likely “good enough” — so the “better” ATI drivers (if the claims are true) don’t really matter much, at least not to me.

A Windows user’s first four days with a Mac

On Friday, I received my iMac, bringing me back to the world of the Mac OS for the first time in about eight years. The iMac is not my main rig — I still use a “Wintel” PC running Windows XP for work — it’s a replacement for my home computer (though I eventually hope to expand its use beyond pictures, movies, and World of Warcraft).

So, what’s the initial reaction from a guy who was very entrenched into Windows, but has a solid Mac history?

  • What’s up with the mouse movement? One of the first things I do on any computer I use is turn the mouse speed up all the way. I want the slightest flick of my wrist to shoot the cursor across the screen. Doing this on a Mac made it, well, not as zippy as I’d prefer. Apparently, plenty of people agree, and the fix to the problem is to use some freeware hacks or shareware software (SteerMouse did the job for me).
  • I miss my keyboard shortcuts. Yes, you can do a lot with the Mac keyboard, but I do almost everything with the PC keyboard. I’ve since learned you can press Control-F2 to open the Mac menu for keyboard navigation, but I miss the ability to TAB between fields in web browsers (there is a fix) and the underlined letters that show which keys you can press to activate menu options (somewhat of a workaround).
  • Installing software on a Mac is glorious. I can’t believe how easy they make it. No surprises and no issues.
  • I plugged in my USB devices and they worked immediately — my external USB drive, my digital camcorder, my digital camera, and my photo printer. That never happened on a PC.
  • iMovie is everything that Windows Movie Maker is not.
  • FolderShare works as well on a Mac as it does on a PC — and it made transferring dozens of gigabytes of pictures and movies disturbingly simple.
  • I had to manually turn on the right-click feature on my single-button MightyMouse. That should be on by default.
  • World of Warcraft stopped working after I adjusted some parental controls and firewall settings — apparently an unintended side effect acknowledged by Blizzard — and required a reinstall. Fortunately, reinstall only took me about 30 minutes, about the time it takes to queue up and play one battleground instance.

I’m enjoying the Mac experience so far. It’s definitely something to get used to. My fingers still stumble on the Mac keyboard a bit, and there are some things I miss from Windows-land.