Sunday, February 26, 2012

Microsoft Multimedia Keyboard and the Function Lock Key

I have a microsoft multimedia keyboard with a function lock key.
Each function key does other tasks, e.g. F2 is UNDO.
However, F2 is also the "Rename" shortcut for Windows which I use very regularly to rename files. F6 is the shortcut to jump to the URL bar in Internet and Windows Explorer, etc.

Annoyingly, the F keys are OFF by default so every time I go to rename a file, I end up undoing the last action that I performed. Quite often this can be a file move and I then have to remember which file I last moved and re-move it! I suppose I could press F3 to "Redo" but that's not the point!

You can of course, turn on the function keys by pressing the Function Lock key - but usually by the time I realise I have not pressed it the damage is already done!

Anyway, others have had the same frustration that I have and created a registry hack that reverses the button functionality. So that by default, the Function Keys are the Function Keys and not whatever arbitrary functions the Microsoft engineers decided I needed instead.

The registry hacks are here:
http://jtsang.mvps.org/scancode_method.html

As with any registry hack, you should always backup your registry, take a system restore point, pray to your god(s) and of course EDIT the file to make sure it does nothing terrible (if you know what you're looking for).

As of the time of writing, these files work fine and are safe. I used 2gflockelim-w-perma-prtscn.zip. But there are others there that might be more helpful.

In fact, this is all it is:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,0e,00,00,00,3b,00,3b,e0,3c,00,08,e0,\
3d,00,07,e0,3e,00,3e,e0,3f,00,3f,e0,40,00,40,e0,41,00,41,e0,42,00,42,e0,43,\
00,43,e0,44,00,23,e0,57,00,57,e0,58,00,58,e0,37,e0,52,e0,00,00,00,00


Feel free to make your own .reg file with the above code.

Make sure to reboot after applying the registry fix. If you want to undo all of this. Simply delete the "Scancode Map" entry and reboot.

Friday, February 17, 2012

Access Remote Server Resources in asp.net

I am writing an asp.net page for work that needs to access files on servers in remote offices, and serve those files to the user who requested it.
The asp.net app knows the path to the file, and in testing a simple command like this works:

Dim FileExists As Boolean = My.Computer.FileSystem.FileExists(filePath)

The problem is that in testing, the user account being used to execute the above code under is my own. But on the production web server, the iis worker process is running under "NETWORK SERVICE" and that account is not on the domain and does not have access to resources...well anywhere.

The solution to this problem was to impersonate a user with domain privileges, and use NTFS permissions to allow that user account access to the resources I need to access.

Using code I found here: http://support.microsoft.com/default.aspx?scid=KB;EN-US;306158#4

I used the code under the "Impersonate a Specific User in Code" section and it worked perfectly!

I basically just copier the code in to my user control with the exception of the code in the form_load sub, and used this where I needed it:

If impersonateValidUser("Username", "Domain", "Password") Then
'Insert your code that runs under the security context of a specific user here.
FileExists = My.Computer.FileSystem.FileExists(filePath) = True
undoImpersonation()
Else
'Your impersonation failed. Therefore, include a fail-safe mechanism here.
Throw New Exception("Unable to access KD files. Security failure.")
End If


Be sure to undo the impersonation after the code you need elevated has executed.

Note: I tried to use the Domain Administrator account for testing, and it seemed to impersonate it, but the code did not execute with elevated privileges. I used a normal domain user account and that did the trick. There must be some failsafe to disallow the use of the Administrator account in this way.

Monday, February 6, 2012

I am cursed

Woke up this morning to find that somebody had broken in to our unit, rummaged through my Wife's handbag and found her wallet. Took all her cash and then left.

This is getting a bit out of hand.

Thursday, February 2, 2012

Am I cursed?

I genuinely think I might be cursed. Any ideas?


Evidence:

Late November 2011:
I crash my car, my pride and joy. I write it off, and two other cars with it. Other parties lie to cover their butts, so I get found to be at fault and lose a bunch of points off my license.

Early December 2011:
Get a speeding fine in a state I've never driven in before, on a road I've never driven on before, in a car I've never driven before, which I later find out has a faulty speedo. While interstate on a work trip!

Early January 2012:
First day back at work, and it turns out the night before our NSW Head Sales office was struck by lightning. Twice.
Strike fried almost every VoIP phone, almost every Switch, the only server, and all of the VMs that were running on it, the Cable Modem, 8+ motherboards in workstations, 5+ PSUs in workstations.
Residual damage from the strike destroys several further switches in varying degrees of sparks and electrical smoke.

Two weeks ago, I get cut off by some jerk in a white van who pretends to let me merge (I have right of way) and then speeds up at the last second to try and make me run out of road and crash in to a gutter.

Last Week, nearly get killed by a courier truck almost crushing me while driving through North Ryde.

Last night, after cooking dinner I seriously burn my finger and now there's a massive blister on it that is annoying the hell out of me.

For the last 3 weeks one of my customers has had a problem that I simply cannot figure out how to fix. It's stressing the hell out of me.

Work keeps piling up faster than I can complete it, and people keep hassling me for things that I just don't have time to do.

I keep getting woken up at 5:30am by the guy across the road doing a burnout on his way to work.

Two nights ago, my SSD in my PC dies completely!

Last night, I get woken up at 1:30am by the MD's assistant because the MD is overseas and needs a file deleted on the network.

Tonight, the night before I go quad biking with by Brother-In-Law, the power at our Head Office goes out and all the servers go down. Now I have to wait for the power to come back on and go in to work to turn everything back on that doesn't turn on by itself. My off-sider is at a medical appointment in the morning and won't be around tomorrow. What's the bet I miss quad biking altogether?

I think I missed a couple things.

FML