Search This Blog

Thursday, June 9, 2011

Grep'ing files in Windows 2008 with PowerShell

For the life of me I can't get the windows search function to work correctly under Windows 2008 to do full-text recursive searches of a directory tree -- supposedly you need to reset the folder options under Windows to search file contents but it just doesn't work right.

Here's a simple way to do it using PowerShell:



PS> get-childitem d:\ -include *.aspx -recurse select-string -pattern '.toggle'

Here I'm doing a recursive full-text search of a directory tree for files containing the string '.toggle' (it's a JQuery function I used sometime over the last year that I needed an example of).

This works well and, unlike the built-in Windows "search" function (quotes are intentional), its operations are transparent and actually work.

Thursday, March 10, 2011

Reminder - Enumerating column names of a dataviewrow

So that I don't waste another hour trying to remember this ... to quickly enumerate the column names in a DataRowView object, use this collection.

((System.Data.DataRowView)(data_userBindingSource.Current)).Row.Table.Columns

Friday, February 11, 2011

Reminder: Regex "greedy" matching in gVIM

To remind myself -- when using gVIM, "greedy" matching doesn't use the "?" question mark character used in PERL but, instead, the string "\{-}". I need this about once every three months and completely forget what the string is -- well, here it is to remind me.

Example:

   [DoT PO Uninstall Number] [nvarchar](255) NULL
   :%s/^\[.\{-}\].*/\1/

results in:

   DoT PO Uninstall Number

From the best gVIM cheatsheet available: www.rayninfo.co.uk/vimtips.html

Friday, January 28, 2011

"The RPC server is unavailable" problem demoting a domain controller in an NT domain

When using HyperV for an enterprise development task I needed to rapidly create, promote, and then demote servers. The promotions went fine but I ran into problems doing the demotions -- I kept running into a problem where I got the message claiming that "The RPC server is unavailable." The error message claimed that it couldn't contact another DC in the domain to complete AD replication before it did the demotion, which seemed unlikely since DNS was set up correctly.

I don't know why this solution worked, but ... the way to get this fixed was to go to another DC in the devdomain, bring up the "Active Directory Sites and Servers" admin tool, select the server I was trying to demote, expand the "NTDS" child icon, then right-click on it to get the "Replicate Now" context menu option.

I clicked on that to force a replication then tried the demotion opration again. This time it worked.

Thursday, January 6, 2011

"CLR has been unable to transition from COM context for 60 seconds" error in Visual Studio

This is an error in VS2008 I've gotten infrequently that appears when running a really long process (in my case, a recursive treewalk of a very large Active Directory structure) in the Visual Studio Debugger.

The title of the messagebox is ""ContextSwitchDeadlock was detected" and the text reads like: "The CLR has been unable to transition from COM context 0x12345 to COM context 0x54321 for 60 seconds ..."

The code is not the problem, it's the debugger being helpful when it thinks there's a runaway process.

The answer is to change some settings in the debugger to stop Visual Studio from halting on long processes: "Debug", then "Exceptions", then "Managed Debug Assistants". Uncheck the box for "ContextSwitchDeadlock."

One note -- this is not a system-wide settings change, it seems to be in the project's .suo file and specific to the project you're debugging.

Thursday, November 4, 2010

Deploying a Windows Service with a Visual Studio "Setup and Deployment" project

Installing Windows Services using the “Setup and Deployment” template and creating a “Setup” project is significantly superior to using the “Installutil” command-line utility, but the steps involved in setting up a windows service to install using one of these projects can be a little involved.

Here is the most concise description available on-line:

http://msdn.microsoft.com/en-us/library/zt39148a.aspx#4803

Please note that the section that I always get hung up on is adding the service to the "custom actions" section of the setup and deployment project:

To add a custom action to the setup project

  1. In Solution Explorer, right-click the setup project, point to View, and then click Custom Actions.

    The Custom Actions editor appears.

  2. In the Custom Actions editor, right-click the Custom Actions node and click Add Custom Action.

    The Select Item in Project dialog box appears.

  3. Double-click the Application Folder in the list to open it, select Primary Output from MyNewService (Active), and click OK.

    The primary output is added to all four nodes of the custom actions — Install, Commit, Rollback, and Uninstall.

  4. In Solution Explorer, right-click the MyServiceSetup project and click Build.

This step is not obvious at all, which is why I consistently miss it (and why, from Googling around, it looks like many other people miss it too).

Monday, September 27, 2010

Renaming executable application name in Visual Studio 2008

Before I forget again ... to change the name of an application executable in VS2008 (be it a forms application or console application), don't try changing the assembly configuration file: it won't work.

You need to select the project, choose "Properties", and then change the assembly name under the "Application" tab.