Friday, October 27, 2006
Disabling U3 on USB Stick (Non-destructively!)
I have a Sandisk Cruzer 4 GB, which I wanted to disable U3 on. Although you can uninstall U3 completely from the drive I didn't want to do something I could reverse later if needed.
The way U3 works is by emulating a CD partition on the USB stick. Windows will autorun a CD much more readily than a removeable mass media partition, so U3 will autorun even though technically it's not an actual CD drive.
One way to prevent the U3 autorun is by removing the drive letter association for the disk, which can be put back later if needed.
Step 1. Load Computer Manager.
Control Panel -> Administrative tools -> Computer Management
Step 2. Select Disk Management
Step 3. Locate the U3 CD emulation drive, which will probably be circa 5 MB.

Step 4. Right click on the drive partition and select 'Change Drive Letter and Paths'.
Step 5. 'Remove' the drive letter.
You will now find when you insert the USB stick U3 will not load because the drive no longer exists as far as autorun is concerned.
To reverse this configuration perform the same steps and 'Add' a new drive.
The way U3 works is by emulating a CD partition on the USB stick. Windows will autorun a CD much more readily than a removeable mass media partition, so U3 will autorun even though technically it's not an actual CD drive.
One way to prevent the U3 autorun is by removing the drive letter association for the disk, which can be put back later if needed.
Step 1. Load Computer Manager.
Control Panel -> Administrative tools -> Computer Management
Step 2. Select Disk Management
Step 3. Locate the U3 CD emulation drive, which will probably be circa 5 MB.

Step 4. Right click on the drive partition and select 'Change Drive Letter and Paths'.
Step 5. 'Remove' the drive letter.
You will now find when you insert the USB stick U3 will not load because the drive no longer exists as far as autorun is concerned.
To reverse this configuration perform the same steps and 'Add' a new drive.
Tuesday, October 24, 2006
C# equivalent CSingleLock / Critical Section
C# has a pretty nifty way to perform critical section locking using the newly created 'lock' statement. For those of you after the quick answer:
Object lockobj = new Object();
lock (lockobj)
{
// Do your locked work
}
To offer a bit more information..
When would you use this?
Critical sections are used when you need to operate on objects, files, or other resources such as database and TCP connections across a number of threads.
If you have multiple threads all trying to write to a file at the same time, for instance (say a log file), what happens if threads try writing at the same time? One thread may get an exception saying it cannot open the file, or worse you may end up losing data if you don't correctly catch the exception.
How does it work?
Quite simply the lock statement will check if the object is locked and if it is it will wait. Once the existing lock is relinquished the waiting thread will then move into the code within the braces and perform its operations.
If you want the full technical details please visit the MSDN.
Object lockobj = new Object();
lock (lockobj)
{
// Do your locked work
}
To offer a bit more information..
When would you use this?
Critical sections are used when you need to operate on objects, files, or other resources such as database and TCP connections across a number of threads.
If you have multiple threads all trying to write to a file at the same time, for instance (say a log file), what happens if threads try writing at the same time? One thread may get an exception saying it cannot open the file, or worse you may end up losing data if you don't correctly catch the exception.
How does it work?
Quite simply the lock statement will check if the object is locked and if it is it will wait. Once the existing lock is relinquished the waiting thread will then move into the code within the braces and perform its operations.
If you want the full technical details please visit the MSDN.
Tuesday, October 3, 2006
Embedding Images in Perl
If you want to distribute a perl script with an embedded binary, for instance, an image, you can do so by converting the binary into base64 (printable text) and then back into binary at runtime.
For an app to convert your binary file into base64 for Windows, take a look at:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q191239
Use this as so:
base64 -e file.gif >base64file.txt
For an app to convert your binary file into base64 for Windows, take a look at:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q191239
Use this as so:
base64 -e file.gif >base64file.txt
Subscribe to Posts [Atom]