Monday, August 30, 2010

Granting permissions to the ApplicationPoolIdentity

Windows 7 and Windows 2008 RC 2 introduced the concept of managed service accounts and by default, application pools are set to use a managed service account in order to isolate the web application pool without adding additional management of passwords and such.  The downside is that the implementation is half-baked when it comes to giving these accounts permission to other things such as accessing files or directories.

The trick is, when setting the security for the file or folder, select your computer as the location then enter IIS APPPOOL\ApplicationPoolName as the user where ApplicationPoolName is the name of the application pool you want to give permission to.  Microsoft really should make these accounts show up in the GUI, but at least this little trick works.

Friday, August 20, 2010

Why Does Video Cost so Much?

After reading this article about YouTube starting to charge around $5 for certain independent films, I started wondering why it's so expensive to purchase video content instead of music. Don't get me wrong, I think most music is overpriced (most songs went to $1.29 as soon as iTunes allowed them to raise the price from $.99), but from a value proposition, I don't see why video is worth 5 times as much as a song. Sure, bandwidth costs and file sizes are larger due to the inclusion of video and it costs more to produce a video in the first place, but on the other hand, I and most consumers will watch a video once in my lifetime whereas I'll listen to a song multiple times and continue to listen to it throughout my life (assuming it's a good song of course). Is a half-hour show I'll watch once really worth $3.99 (especially when it was originally broadcast over-the-air for free)?

Tuesday, March 23, 2010

How to copy from the GAC

If you're not a .NET developer, you probably don't care.  If you are a .NET developer, you've likely had some case where you've got an assembly installed on your development machine, but when you deploy via XCOPY or some other means, the target server doesn't have that DLL and you get an error.  Today I found the trick to copying out of the GAC.

The trick is, you can't use Windows Explorer.  Open an administrative command prompt (Right-click, run as Administrator) and CD to C:\Windows\Assembly.  This directory is not how it appears when viewed from Windows Explorer.  It actually contains a number of directories organized by the type of DLLs it contains.

Most .NET DDLs are MSIL compiled and thus are contained in the GAC_MSIL directory.  The DLLs aren't in there either, instead they're in a sub-sub-directory, the first being the name of the DLL without the ".dll" extension and the second being what looks like a version number/public key token (e.g. Microsoft.SqlServer.SqlClrProvider.dll is contained in C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlClrProvider\10.0.0.0__89845dcd8080cc91).

The easiest way to find your particular DLL is to use the DIR command repeatedly.  You then want to use the COPY or XCOPY commands to copy the DLL somewhere else.

Happy Coding!

Tuesday, November 24, 2009

Creating Aero-style Wizards in Windows Forms

I spent some time searching for existing controls/frameworks for creating Vista-/7-style wizards in Windows Forms applications.  The best framework I found was at http://bitbucket.org/factormystic/aero.wizard/wiki/Home.  Also available on the site is a project for aero-style controls such as command links and search boxes https://bitbucket.org/factormystic/aero.controls/wiki/Home.

Tuesday, July 7, 2009

How to Open a Link in a New Session with IE8

There are some occasions when you want to sign into the same site twice with two different user IDs.  For instance you might be developing a new web application and need to compare how the application looks if you’re an administrator vs. a non-admin so you want to sign in twice to compare the two side-by-side.

In IE7 or under, you could simply click a shortcut to start a new instance of IE and the new instance would have its own session, but in IE8, they changed things a bit when they introduced their new process model.  Now all the separate processes share the same session unless you explicitly tell IE to start a new session.

To do this, you open the file menu (press Alt if the main menu isn’t shown) and choose “New Session”.  This opens a new IE window with its own session.  As far as I know, the cookies are kept completely separate.

For those of you who like the command line, you could also run iexplore.exe (located in C:\Program Files\Internet Explorer by default) with the -nomerge parameter.  This also means that you can create a shortcut to start a new instance of IE with a new session.

What I wanted though was to be able to right-click a link and choose “Open in New Session”.  This is a little harder, but turned out to be easier than I thought.  I originally thought I would have to dust off my C++ skills and finally learn to use COM (which I’ve tried my best to avoid), but all I wound up needing was an html file and a registry entry.

First, create an html file.  You can simply right click the folder where you want to create the file and choose New → Text Document, then rename the file to something with an “htm” extension.  I used C:\Program Files\NewSession.htm, though you can use any name or path you want, just make note of it when you create the registry entry.

Then open the file in your favorite text editor (i.e. Notepad) and copy/paste the following:

<script language="javascript">
var a = external.menuArguments;
if(a && (a = a.event) && (a = a.srcElement) && (a = a.href))
{
var shell = new ActiveXObject("WScript.Shell");
shell.run("\"C:\\Program Files\\Internet Explorer\\iexplore\" -nomerge \"" + a + "\"");
}
</script>


Then save the file.




Note:  Modifying the registry can be harmful to your computer if you don’t know what you’re doing.  If you’re unsure of yourself or you simply want to be careful, it’s best to ask for help from a friend or associate with knowledge of computers.




Then start the registry editor by holding the Windows key and pressing R, typing regedit in the run dialog and clicking OK.  In the registry editor, navigate to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt and add a new key named Open in New Session.  Click this new key then double-click the (Default) REG_SZ and change the Value data to the path to your html file (e.g. C:\Program Files\NewSession.htm) and click OK.  Then add a new DWORD (32-bit) value named Contexts and modify the value to set it to the hex value 20 (32 in decimal).



That’s it!  you can close the registry editor and restart Internet Explorer.  When you right-click a link, there will be a new option “Open in New Session”.  When you click this option, a new instance of Internet Explorer will open with the URL of the link you clicked.  This new instance will have a brand new session.

Monday, June 15, 2009

Resizing Columns in Word 2007

This might apply to previous versions of Word as well, but I came across some interesting tidbits related to resizing columns in Word 2007.

When you move the mouse in between two columns and get the column resize cursor, if you resize a column, in the middle of the table, it makes the next column wider as the previous column shrinks.  If you’d rather resize the whole table, hold the Shift key as you resize.

Every now and then you might find that just the one cell resizes rather than the whole column – in this case, make sure the cell isn’t selected – when one or more cells are selected, the resizing only affects the selected cells.

Friday, May 1, 2009

Use JavaScript to get the position of the caret in a Text Box

If you have an <input type=”text” /> on your web page and that element currently is in focus, you can use this cross-browser function to retrieve the current position of the caret/cursor:

function GetCaret(input)
{
if(document.selection)
{
var range = document.selection.createRange().duplicate();
//moveStart returns the # of characters moved.
return -range.moveStart("character", -input.value.length);
}
else if(input.selectionStart)
return input.selectionStart;
return -1;
}



Internet Explorer doesn't support the selectionStart property used by FireFox (I've heard Opera uses selectionStart and I believe Safari does as well) so instead we get the currently selected range via document.selection, use the selection object's createRange method to create a TextRange object which is what IE uses to manipulate text data. There doesn't seem to be a direct way to get the position of the TextRange within the parent object, but we can use the moveStart method to move the start point of the range. This method returns the number of characters moved, which happens to be the position of the caret - technically the negative of the position of the caret since you had to move the selection backwards to reach the start.



This method could easily be modified to get the ending position of the selection by using range.text in IE to retrieve the text selected (range.text.length would be the length of text selected) or use input.selectionEnd in other browsers.