Restive Technology

“Technology makes it possible for people to gain control over everything, except over technology” -John Tudor

Chances are you have run into this problem if you have ever tried copying your files from Windows to another computer, using Windows Explorer, to back them up.  You get an error such as “Cannot copy filename:  It is being used by another person or program.  Close any programs that might be using the file and try again.”

When this happens, your whole copy stops, and you have no idea how far it got before it stopped.  It becomes a painful process.  Fortunately, there is a program out there called ROBOCOPY, which somehow is supposed to stand for ‘Robust Copy’, it almost works if you ignore the second O.  Anyway, this program works great, by continuing in the event of an error.  It skips all files in use.  ROBOCOPY is a command-line tool, but it has some gui addons to make it easier to use (it’s really not that difficult–how many options can there be to copy files?)

But what if you want to copy in-use files too?  Opened files are just as important as closed files, if not moreso.  Enter Volume Shadow Services and a little utility called HOBOCOPY (I sense a naming trend here…). HOBOCOPY interacts with Windows by creating a VSS snapshot, which is basically a point-in-time copy of all your files, whether open or closed.  HOBOCOPY isn’t as polished as ROBOCOPY, and it wasn’t written by Microsoft, but it is a good utility nonetheless.

Here is a script I wrote to take the work out of using HOBOCOPY remotely.

@echo off
:: Backup Script
:: usage: backup.bat <computername> <path>
:: Stores it in local \\computername\backup path, needs to be shared with full write privileges
:: Required files: psexec.exe, hobocopy.exe

IF [%2]==[] goto instr

set cmp=%1
set src=%2
set dst=\\%computername%\backup\%cmp%

c:
cd \backup
IF EXIST backup.log del backup.log

echo Backup Script > backup.log
echo Backup Script
echo Backup of %src% to %dst% >> backup.log
echo Backup of %src% to %dst%

psexec -s -c \\%cmp% c:\backup\hobocopy.exe /full /skipdenied /r /y %src% %dst%

echo Backup Complete! >> backup.log
goto end

:instr
echo Backup Script
echo usage: backup.bat ^<computername^> ^<path^>
echo example: backup NGARA c:\
echo Stores backup in local \\computername\backup path, needs to be shared with full write privileges
echo Required files: psexec.exe, hobocopy.exe

:end
set src=
set dst=
set cmp=

Since it interacts with the operating system, it needs to have local access to the source drive (in otherwords, if you’re copying from SRC to DST, you can’t run it on DST).  The batch file makes it work so that you can run it from DST.  Note that I’ve used PSEXEC, another great utility, to remotely execute HOBOCOPY from the destination computer.  That way, if I am backing up a remote user’s system, I don’t have to be physically near the computer.

In order to use the script, first you have to set up the destination computer DST:

1. Create a directory called c:\backup on DST

2. Share that directory with All permissions to Everyone

3. Copy PSEXEC.EXE and HOBOCOPY.EXE into c:\backup

4. Create ‘backup.bat’ and copy the above code into it, save in c:\backup

5. Run the script from a command prompt on DST:

C:\> backup.bat SRC C:\

Where SRC is the computername of the source computer and C:\ is the drive you want to back up.  Note that only local drives are supported.

Errors:

Access Denied – Check your shared permissions.  Note that the Security permissions AND the Share permissions must both be set to allow write access to a shared directory.  Windows treats them separately and requires both to allow you to write to a directory.

COM failure 0×80042301 – There is a blog post about this one, but I haven’t figured it out yet.

Download here:

HOBOCOPY – Hosted by SourceForge (it’s open source!)  Click the Files tab, then browse through Hobocopy – 1.0.0.0 – Hobocopy-1.0.0.0-XP-32bit-Release.zip.  Then extract it to c:\backup

PSEXEC – Download and unzip into c:\backup

ROBOCOPY – Part of the Windows 2003 Resource Kit Tools.  If you want to try this out, Install the Resource Kit, then go into C:\program files\Windows Resource Kits\Tools and copy robocopy.exe to c:\backup

I just started experimenting with PowerShell for a project I’m doing.  I haven’t seen any good examples on the web for how to run a PowerShell script generically from a batch file, so I’m sharing this framework.

First of all, before you run PowerShell scripts, you must change the security settings so that they will run.  You can do this in PowerShell itself:

C:\>powershell
PS C:\> Get-ExecutionPolicy
Restricted
PS C:\> Set-ExecutionPolicy RemoteSigned

After you have affected the security change, you can start using PowerShell.  Next, write a batch file to execute your script:

:: psscript.bat
set psscript='C:\psscript.ps1'

echo Running PowerShell Script: %psscript%
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe ^&%psscript% %*
set psscript=

A couple of comments on the batch file:

Notice that the path to psscript.ps1 is in single quotes.

I am executing the script by passing an odd array of characters to powershell.exe.  The carat is an escape character for .bat files which tells windows not to process the “&” as if it were part of the command line.  Therefore, the batch file passes & directly to powershell.  In addition, I’m telling the batch file to pass all batch arguments by using %* (older versions of dos and maybe windows have used %1- to pass all arguments, but that definitely does not work on my testbed using Windows 2008 R2).   On the command prompt, the command would look like this:

powershell.exe &'path-to-ps1.ps1' arg1 arg2

And here is the code for my first PowerShell script.  It is designed to take a directory path as the argument from the command line and output a list of files and directories sorted in order of size from largest to smallest.

Here is the first PowerShell script.  It’s really simple, and makes use of piping.

# psscript.ps1
Get-ChildItem $args[0] | Sort-Object Length

To execute the code, run the batch file and pass in an argument like so:

psscript1.bat C:\

You should get a listing of your files and directories in C:\ ordered by size.  Enjoy!

Problem:

My mirrored RAID array died on a Dell Precision 380.  The hard drives were 80 GB each, and I wanted to create a new array that was bigger, and move everything to the new array.

Tools used:

BartPE (PEBuilder)

-  Microsoft DiskPart

DriveImage XML

Dell Support (for Drivers)

REGEDIT and SC (Windows command-line tools)

Solution:

I created a new RAID array using Intel’s Matrix Storage menu, which doesn’t give a lot of options.  The new drives are both 160GB, so I made a RAID 1 with them, and kept the good RAID 1 drive from the old setup.  I had to integrate the Intel Matrix storage drivers and DriveImageXML into BartPE, then create the disk so that I could boot from it.  I booted into BartPE and ran DriveImageXML to copy the old partition to the new partition. Then I marked the partition as Active in Diskpart by typing:

NET START DMSERVER
NET START DMADMIN
DISKPART
SEL DISK 0
SEL PART 1
ACTIVE

After that was complete, I shut off the computer, removed the old drive, and started it up again.

When I booted up, I got a strange result: Windows logs me on, and then immediately logs me off.  The problem, as it turned out, was that Windows wanted to assign the new partition a new drive letter instead of C:  After some research, I discovered that this is hidden in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\
\DosDevices\C:
\DosDevices\L:

So after browsing the hidden paths \\systemname\c$ and \\systemname\L$ I was sure that there was no C: drive and that L: should have been C:.  Keep in mind that I cannot log into the system, but I know it is on the network.  I had to find some way to access the registry remotely, rename these entries, and restart the computer.

Enter SC and REGEDIT.  With Regedit, you can go to File – Connect Network Registry… and open a registry file remotely, provided that you have access and the service “RemoteRegistry” is started.  But that program was not started, so I had to start it manually from another connected computer:

C:\> SC \\sysname START RemoteRegistry

This started the service, and I was able to connect to it and make the necessary changes.  Whew.

The Samsung 204b has been a great monitor for me for years.  Recently, it has started to take longer to “warm up” before displaying anything.  It got to the point where I would turn it on, or move the mouse to wake it up, and then wait up to a minute or longer before anything showed up on the screen.  Finally, yesterday, it just stopped displaying anything.  The indicator light that signals power was on, but nothing was displaying on the screen.  It was time for a repair.

The first thing I did was google “samsung 204b repair” and I came across this website:

http://pavel.kirkovsky.com/2009/03/samsung-syncmaster-204b-repair/

Among other things, it showed me that CapXon capacitors on the power supply board were the most likely fault, repair was possible and pointed to a mouser cart that already contained the necessary parts.  As it turned out, I only needed to replace the two bad capacitors that are endemic to this brand of monitor: C110 and C111.

Read on for a step by step guide to repair the Samsung 204b.

I don’t want to get rid of this monitor, imagine having to track down all those decals again for the new one!

Front view, sorry about the blur.

The first step is to jam a screwdriver into the crack near the buttons and try to find out where the plastic tabs are that keep the monitor together.

Clearly the tabs are on the bigger side, so I have to pry in this direction.

As I pop a tab, I continue down the side of the monitor until the whole bezel is loose.  Some of the tabs break, but that won’t keep the monitor from staying together later.  If you want to be really careful, there are tools that facilitate this process.  I only used a common screwdriver.

This is a two-handed job.  One hand holds the bezel, the other takes a picture.

The buttons are connected by a thin wire, which can be disconnected from the main body after I remove the back section of plastic.

And here it is without the front or back case.  There are six screws to remove.  Two on each side and two on the upper left seen here.

Do not lift here! Instead, lift from the corners. I made this mistake while taking the picture before I realized I was lifting the whole circuit board instead of just the frame.  The frame can be lifted off by itself.

Aha!  You can see that the two caps in the middle of the picture are swelling from the top.  This is a clear indication that they are bad according to the website.
http://pavel.kirkovsky.com/2009/03/samsung-syncmaster-204b-repair/
In my monitor, only these two caps were bad, lucky for me.

The caps are numbered C110 and C111.

The board must still be liberated from its case by detaching two cables on the right and one on the left, unscrewing four screws, and gently lifting the board out of the case.  Then, set the case aside and get ready for some soldering.

Here are the target caps, C110 and C111 from the back of the board.  My mission is to desolder these four connections, bend the pins back, and remove the caps.

Done, and new caps soldered in place. You can see the new ones I bought were too big for the space, but still fit nicely with all the room around them.
The original caps were rated 820μF, 25V.  The new ones are 820μF, 50V, which I read was fine as long as it’s rated above the voltage you plan to use.

I laid one of the caps flat against the board.  There was lots of room and positioning it this way prevents any kind of problem closing the case.  I didn’t have a lot of clearance above it.  Just make sure none of your leads will touch anything metallic, or there will be problems.

With the caps in place, I put the board back in its spot, plugged in the cables (3 on the power board, plus one attached to the bezel for the buttons) and put the monitor back together.  Now comes the true test.  Will it work?

Success!  The whole project took about an hour and a half for me, and I have no experience with this particular monitor.  A very easy fix for someone who is careful, dedicated, and knows how to solder.

Hope you find this informative.

The process is really simple:

1. Backup your data! Always do this before doing something new that will modify partitions and boot records.

2. Create a partition on your existing windows 7 drive.  That may require you to go into Disk Management and shrink a partition; there are guides online for how to do this.  If you assign it a drive letter, such as D:, Windows XP will detect it and choose its SystemRoot as D:\WINDOWS.  It’s weird, but consistent.  There are ways to have Windows XP think that its partition is C: and Windows 7 think that its partition is C: but that gets confusing really fast when working on files from both.

3. Boot from the Windows XP CD and install Windows into the new partition.  Be very careful that you don’t overwrite the existing Windows 7 partition.

4. Windows XP will have overwritten the boot record.  You want the Windows 7 boot record in place, so boot up from the Windows 7 DVD and choose the Repair capability.  It has a feature to automatically repair the boot record, which will overwrite the Windows XP boot record with the Windows 7 boot record.

5.  Now all you need to do is add the Windows XP partition to the Windows 7 boot menu like so:

a. Run CMD as Administrator (right-click on the command prompt icon and choose Run As Administrator) and type the following commands:

bcdedit /create {ntldr} /d "Windows XP Professional"
bcdedit /set {ntldr} path ntldr
bcdedit /set {ntldr} device partition=D:
bcdedit /displayorder {ntldr} /addlast

Now, when you type “bcdedit” it should show your partition at the end of the list.

If XP won’t boot, check that the following files are in the root of the XP drive:

NTLDR
BOOT.INI
NTDETECT.COM

If not, copy them from the Windows XP cd from x:\i386\* where x: is your CD drive.

http://www.tweakvista.com/articles/39206/how_to_dual_boot_xp_and_vista/

http://www.annoyances.org/exec/forum/winvista/t1252461430

http://support.microsoft.com/default.aspx/kb/919529?p=1

The MBR is the first 512 bytes of your hard drive.  All x86 systems that don’t use EFI start booting from this sector.

There is a lot of information on the web about it already, but I am working on a program that will decode the MBR and display its secrets for you to see.  It is entirely written in JavaScript, PHP and HTML (with a little CSS for flavor), and it should be ready to post in a few weeks.

Imagine this – You boot from one DVD, and a menu comes up:

1. Install Windows

2. Boot BartPE

3. Boot from Dos

4. Boot from Linux

5. Run Memtest86+

6. Anything you can think of

This is a reality – using CDSHELL or GRUB4DOS.   I’ve been intrigued by the different ways in which to create a multiboot DVD or USB stick, and these are the two ways I’ve found that seem the most solid.  Don’t be fooled by the name GRUB4DOS, because it can boot Windows and Linux just as well as DOS.  Sorry, MacOS users, but this doesn’t apply to you.

If you want to create a multiple-installers dvd, look no further than http://flyakite.msfn.org because it is the definitive resource on using CDShell to install multiple versions of Windows from one DVD.

For those of you who want to run Linux or boot from USB, I believe GRUB4DOS is your best bet.  I’d like to spend more time and post details about how to do these things, hopefully when I have more time.  If you are the go-to guy for fixing computer problems in your network of friends, you will find it really helpful to have multiple ways to boot a dead system.  The best thing about GRUB4DOS is that you have so many options.  If you want to boot the same images via PXE, USB or DVD, you can create the same basic structure and make it work on all three the same way.  CDShell, on the other hand, can only be used from DVD or possibly from another bootloader like GRUB4DOS.

IP configuration difficulties

I have two new interesting things to post today.  The first is a solution to a strange problem.  A coworker of mine suddenly found that his laptop would not connect to the internet.  I opened a command window to see if he got any IP information, and I saw:

C:\Documents and Settings\username>  ipconfig

Windows IP Configuration

C:\Documents and Settings\username>

That’s it.  No adapters were listed at all.  I ran across this experts-exchange article that helped solve the problem.

I only had to:
regsvr32 netshell.dll
regsvr32 netcfgx.dll
regsvr32 netman.dll

But in addition, if that doesn’t work for you, there are other steps you can take.  One user booted into safe mode and removed the network card drivers, then let Windows detect them again.  Another user had to perform the following:

- Reinstalled all wireless/wired drivers from Dell
- Reset my Winsock using netsh: http://support.microsoft.com/kb/892350
- Reinstalled Winsock/Winsock2 using these instructions from MS: http://support.microsoft.com/default.aspx?scid=kb;en-us;817571
- Ran the 3 DLL register commands from the first post.
- Ran Winsock XP Fix for good measure: http://www.snapfiles.com/get/winsockxpfix.html
- Rebooted Windows


NHawk to the rescue for .NET and rrdtool on Windows

I would like to write a program in C# (.NET) that will automatically update RRD graphs on Windows.  The incredibly useful rrdtool and its windows binary can be used to update rrd graphs on the same machine they’re graphing.  I want to do this for performance reasons and for scalability.  I don’t need to have all the graphs on one server, the way we run cacti currently.

I found a wrapper project, NHawk, that allows me to write RRD commands using .NET objects.  The only thing that I can’t figure out how to do is GPRINT.  I’m about to email the author and find out if there is an update.

Whenever I migrated a linux server using the VMware Converter, my ethernet devices disappeared. I found a quick and easy way to restore them without any fancy work. Just delete (or move) the file /etc/udev/rules.d/70-persistent-net.rules. This file is used to associate the eth devices with a mac address so that they always come up the same way. When VMware converts a machine, it assigns a different mac address to the virtual ethernet adapter, so this file needs to be deleted.

Thanks to http://techblog.romero.id.au/2009/06/ubuntu-missing-eth0-after-cloning-in-vmware/ for the explanation.

A long time ago, in a galaxy far far away, Windows always ran on DOS.  Furthermore, file names longer than 8 characters with a 3 character extension were not allowed.  Nor were files that ended in a space.

When Microsoft decided to extend the file name length to more than 8.3 characters, they made the latter backwards-compatible with the former dos ways.  Therefore, a file name like

“My Pictures”

was interpreted in 8.3 format as

“MYPICT~1″

Normally, this feature is never used, because modern day Windows programs use long file names with spaces and other symbols with no problem.  But today, I found an anomaly, a directory of my friend’s pictures that was created (in Unix) with a space at the end, and Windows simply refused to delete it. All the history of Windows and DOS came rushing back to me in one sweet moment.

I tried all the classic ways to do it.  Command line, reboot, try to rename the directory before deleting it.  The problem was, Windows could tell that the file had a space at the end.  I would type ‘del Mich<tab>’ and Windows would fill in the rest of the prompt to say ‘del “Michelle “.’  But I couldn’t delete it until I stumbled across a simple solution:

First, use “DIR /X” to find the 8.3 filename.  Then use del to delete that simple 8.3 name.

Simple, yet profoundly historic.  Much as Microsoft has tried to hide DOS and render it irrelevant in Windows XP, it still shows its roots now and then.