Scott Hanselman

Coding4Fun - Some Assembly Required - USB Wireless PC Lock

August 13, 2005 Comment on this post [28] Posted in Learning .NET | Coding4Fun | Bugs
Sponsored By

In this fourth installment of the "Some Assembly Required" column, Scott Hanselman and Bryan Batchelder find a piece of hardware so compelling - and with included software so bad - that they write their own version using the .NET Framework 2.0.

Big ups to Bryan for letting me piggy back on his initial design and for his help on the article. We've had a lot of fun, fixed a few bugs, introduced a few new ones.

We've also ported the code back and forth so you can get 1.1 and 2.0 versions. The project is up at SourceForge along with source and an installer. Buy the hardware at NewEgg for $15.

NOTE: If you're reading this post and you are the Asian company that makes this hardware, please contact Bryan or I, as we'd like you to use our software as yours really isn't very good. You've got a great product here, and we're happy to have you use our software with attribution. We aren't trying to get rich, just trying to get good karma.

BUGS: If you're running Skype and you're using our software along with the Windows Media Player plugin, apparently Skype doesn't like the Broadcast Window Message that we send to stop the media from playing. I haven't seen the bug myself, but Bryan has, so be aware. It's very likely Skype, not us.

DEVELOPERS: If you develop new plugins or fix bugs - which we hope you do - be sure to release the source, or give them to Bryan and I and we'll post them on SourceForge.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
August 13, 2005 22:34
So, just because you've actually seen this product (and I haven't), what happens if "an evil person" just unplugs the USB portion of the device? If the computer is locked, I'm sure it will stay locked until the user returns, but it will never lock again.

Does your improved software give a "Device removed" warning? Or could this be implemented with your plugin interface?

Cool app!
August 13, 2005 22:52
Are you sure the hardware link is correct? I see a Turtle Beach USB Music Studio Kit.
August 13, 2005 23:45
Froogle listing for this hardware:

http://froogle.google.com/froogle?q=%22USB+PC+Lock%22&scoring=p
August 14, 2005 0:21
NewEgg reports, "We apologize for the inconvenience, but the item you are looking for has been deactivated." Apparently Hanselman's readers are sucking too much bandwidth. ;-)
August 14, 2005 3:39
Scott, This is a great article. This assumes that there is one person using the computer. I am interested in developing this further to where multiple users for a single computer can be setup. For instance, at our lab in school we have 2 or maybe 3 people who use a computer at a single time (and only those 2/3 will use it). So my question becomes this

1. Can multiple keys (the round thing) be used on a sigle usb receiver.
2. How can you associated multiple users to one system? For instance, which one has priority over the other, which one should login before the other.
3. Is it even worth it to work on a multi user environment.

4. Why not just use RFID for which the receiver isn't unique. Any reader will read any RFID and you can maintain a database with the users and their associated RFID. Then when a user comes close, lookup the ID and login that user (Great for AD environment).

Any suggestions? Comments?
August 14, 2005 11:25
Nice! Couple of comments:
1. Here in oz the product is distributed by laser - http://www.laserco.com.au/index.htm?/computeracc/pcacc/ao-usblock.htm - might perhaps be worth contacting them as they'd more than likely know who makes the original.
2. (as a coworker pointed out), combine this with a fingerprint reader and you've got a nice double team of lock when you walk away and unlock when you get close.
3. It should be a doddle to write a winamp pauser, around about 15 lines of code from memory.
4. What would the options be for having one of the sticks plugged into a location without a full PC there? I'm thinking that if there was a cheap enough solution then this could really be nice for a "where'd dan go" tracking system. Meeting room doors, coffee machines, smoke area, etc. Its a bit big brother-ish, but if you didn't want to be tracked you could always leave the fob on your desk :). We have issues with coworkers going awol during the day, wandering off to get coffee or speak to other people. Being able to locate them quickly would be nice.
August 14, 2005 11:36
Oh, and perhaps a silly question. What license is this released under? I had a poke around the source forge site, couldn't find anything.

Cheers!
August 14, 2005 19:55
Here's an idea for corporate expansion... If all the corporate computers happened to have one of these little devices, and all the employees carried around the Fob, then it would be possible for each of the computers to get the specific user interface (key settings, wallpaper, icons, etc.) for each user if when they sit down at any computer in the corporate network.

To point out a scarier, big brother side of things.... it might be possible tell you the last known location of any employee since it has a range of about 10m. Just walking through the office would be close enough to tell you who's walked by. So when Hanselman isn't in his office (which is most of the time), I could find out where in the building he might be.
August 15, 2005 7:47
Sushant:
1. Yes.
2. Dunno...I haven't...
3. Dunno, how do you THINK it should work? :)

DanielF:
1. Turns out we're now in talks with the OEM!
2. I did! ;)
3. Do it!
4. Hm....PocketPC?
August 15, 2005 19:46
Thanks Scott, with this, it will be harder to find unlocked workstations to play pranks on. Good job party pooper! ;)

But I do have a security question. What happens if you walk away, and I put an intermediate USB device between the dongle and the computer, and record the data going back and forth? When the user returns, he or she is quite unlikely to notice if the dongle is in the back of the computer (think corporate workstation). How will this device and software protect against that?
August 15, 2005 22:08
Is it possible to create something based on bluetooth, e.g. cellphone as "green button"?
August 16, 2005 3:29
lol... nice work guys! not really something i'd waste what little daylight i have left on, but still something very cool!!!

scott, is the book you are working the wrox book on asp.net 2.0 or is there another book?
August 16, 2005 5:07
Talks with the OEM. Nice! You'll be (more) famous.
Good call on the pocket PC. Might have to do a spot of research.

Here's the vb.net code to pause winamp. Turned out to be 17 lines :)
I don't have a device just yet, and have never used source forge, so I'm a bit iffy on writing a full plug-in and adding it to the repository. I figure someone should be able to take the guts of this module and turn it into a plugin.

I've uploaded it to http://www.redgum.com.au/downloads/pausewinamp.vb.txt just in case this paste goes skew-wiff

'-----------------------------------------------
Module Main
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function SendMessageA Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private Const WM_USER As Integer = &H400
Private Const WM_COMMAND As Integer = &H111
Private Const WA_PAUSE As Integer = 40046
Private Const WA_GETSTATUS As Integer = 104

Public Sub Main()
Dim hWnd As IntPtr = FindWindow("Winamp v1.x", vbNullString)
If (Not hWnd.Equals(IntPtr.Zero)) AndAlso (SendMessageA(hWnd, WM_user, 0, WA_GETSTATUS) = 1) Then
Call SendMessageA(hWnd, WM_COMMAND, WA_PAUSE, 0)
End If
End Sub
End Module
'-----------------------------------------------
August 17, 2005 4:00
when i try to open the source project UsbWirelessSecurity.sln in vs 2005 beta 2 i get
---------------------------
Microsoft Visual Studio
---------------------------
Unable to open project 'C:\Program Files\PatchAdvisor Labs\USB Wireless Security\source\Installer\UsbWirelessSecurityInstaller.vdproj'.
---------------------------
OK
---------------------------
any suggestions on what im doing wrong?
thx
August 17, 2005 19:23
Craig, try opening the SLN that doesn't include the installer. You don't need the installer anyway.
August 18, 2005 1:07
Jason - our building key tags work the same way. I've been in the back office in the UK and watched someone move about the building by watching the log of "xx opened door y", "xx opened door z" etc.
it was actually quite mesmorising!

Ian
August 18, 2005 20:35
I'm probably blind, but where can I find the .NET 1.1 version? The MSI requires 2.0 be installed, and the source seems to be VS 2005.

I can't install the 2.0 beta 2 on my main work machine yet even though I have no quibbles installing it at home...
August 20, 2005 5:17
The 1.1 is over here:
http://sourceforge.net/project/showfiles.php?group_id=144221&package_id=158554&release_id=347792
August 20, 2005 16:51
Hi Scott.

I just bought this little device after reading your article on Coding4fun and I wanted to write a plugin to do a login automatically when I get in range of the usb key. I've looked all over (KB, google, newsfeeds etc) but I can't see a way to automatically login to the system once you lock the desktop.

Do you or anyone out there know how to login to an account after the Lock Workstation Plugin does its thing.

Thanks for your help.
Sushant
August 20, 2005 21:53
You're asking how to unlock? To the best of our knowledge it's not possible to programmatically unlock a Windows machine. If it was we'd have done it. If you know how or figure it out, we'll do it.
August 20, 2005 22:23
Hi Scott,

Over at Bryan's blog, Rick Lobrecht posted a little snippet that shows how VNC does the unlocking.

The link is as follows:-
http://labs.patchadvisor.com/blogs/bryan/CommentView,guid,718e452f-f71e-41fb-99cf-9fc681eb6de3.aspx

I'm no expert at Win32 so I couldn't tell you if that could work but your expertise might give you some idea of what they are doing.

There must be a way to simulate a CTRL-ALT-DEL and then if there was a plugin to which you gave your password then you could theoretically simulate that keypress too.

I've written a few plugins (5) today and I'll make the source available soon.

Thanks for all your help.
Sushant
August 23, 2005 17:31
I saw the these at Fry's in Renton, WA the other day for $19.99.
August 23, 2005 23:18
I'm using the 2.01 version and I'm trying to put the Batch File Plugin to work. I'm using a Winamp command-line program called "CLEveR" to mute and unmute Winamp, and using another command line utility called "Nircmd" to run the "blank" screensaver on my PC. (too lazy to type in windows password upon return, and I use an external USB sound device to listen to audio which "Mute Audio Plugin" isn't able to touch.)

So, in theory, my "locked.bat" file would be (with the .exe's in the environment path):
@echo off
clever volume 0
nircmd screensaver

But, uhm, its not executing. Where specifically does locked.bat live? In the same directory as the DLL's and whatnot, right?

Also, what is the "Presence Window" setting for?
August 23, 2005 23:22
Locked.bat is in your user specific ApplicationData folder...
August 24, 2005 4:46
Hey, there they are! Excellent, thanks!
September 26, 2005 14:03
Hi, thankyou so much for the VB code to pause winamp - I like C#, so here, with the kind help of:

http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

and some tweaking, is:

public class PauseWinamp
{
[DllImport("user32", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[System.Runtime.InteropServices.DllImport("user32", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern int SendMessageA(IntPtr hwnd, int wMsg, int wParam, int lParam);

private const int WM_USER = 1024;
private const int WM_COMMAND = 273;
private const int WA_PAUSE = 40046;
private const int WA_GETSTATUS = 104;

public static void Main()
{
IntPtr hWnd = FindWindow("Winamp v1.x", null );
if ((!(hWnd.Equals(IntPtr.Zero))) && (SendMessageA(hWnd, WM_USER, 0, WA_GETSTATUS) == 1))
{
SendMessageA(hWnd, WM_COMMAND, WA_PAUSE, 0);
}
}
}

If anyone finds code to unlock a locked workstation, especially in C#, I'd love to hear about it! The following have been useful to me in my endeavours, so far:

http://pinvoke.net/default.aspx/secur32.LsaLogonUser
http://pinvoke.net/default.aspx/user32.LockWorkStation
http://pinvoke.net/default.aspx/user32.LockWorkStation

Matt.
January 20, 2006 20:52
This is a quite nice setup, but without being able to unlock the PC on your return, then I can't see the use of it. Having to type in your password is a major pain. The software that come's with the key allows the PC to be "locked" (in a fashion) and unlocked when you return. Much handier I think. (Even though their software looks awful)
February 03, 2006 23:25
The radio transmission between transmitter and
receiver has no encryption so it's quite easy
to catch the transmission and send it back to
the receiver. Look at the transmission:
http://usprawnienia.wordpress.com/files/2006/02/PCLock.gif
Now I'm doing a hardware sniffer/copier

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.