Coding4Fun - Some Assembly Required - USB Wireless PC Lock
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.
About Newsletter
http://froogle.google.com/froogle?q=%22USB+PC+Lock%22&scoring=p
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?
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.
Cheers!
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.
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?
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?
scott, is the book you are working the wrox book on asp.net 2.0 or is there another book?
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
'-----------------------------------------------
---------------------------
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
it was actually quite mesmorising!
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...
http://sourceforge.net/project/showfiles.php?group_id=144221&package_id=158554&release_id=347792
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
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
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?
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.
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.
Does your improved software give a "Device removed" warning? Or could this be implemented with your plugin interface?
Cool app!