Developer

Various notes useful to developers only

Writing to EventLog from MSI custom action

I had a task to write to event log from within MSI custom action (WiX in my case, but that doesn’t matter) and the logging should be with the same source as MSI itself is using – e.g. “MsiInstaller”. I couldn’t find a proper way to do this and ended up writing to log myself, without using any of MSI API methods. I took the logging method from ATL with small modifications. Here it is: #pragma warning(push) #pragma warning(disable : 4793) ...

Refactoring succeeded! :)

I feel like refactoring worked just fine

Using Amahi: Installing Subversion and Migrating Repositories

Since all my code is stored in Subversion, which is currently installed on Windows Home Server, I had to check how to install a Subversion server on Amahi server and how to migrate all my repositories there. The installation is pretty straight forward, everything is done form command line. 1. Install subversion: yum install subversion 2. For some reason SQLite was outdated for me, so verify that you have the latest version: yum update sqlite 3. Create a root folder for all your repositories. It can be any name and any location. I choose to...

Regular Expression to extract quoted text

If you have a text enclosed with single or double quotes and optionally containing escaped quotes inside the text, the following regular expression will help you to extract the text: (['"])(?<text>.*?)(?<!\\)\1 For example, parsing text: 'Hello world'  'World\'s test' "World's test" will yield following results: Hello world World\’s test World’s test Technorati Tags: Regular Expressions

Enumerating user privileges

We had some issues in the impersonation code and I needed to enumerate privileges of currently logged in user – before and after impersonation. Since I couldn’t find quickly such code, I wrote it myself, by compiling few pieces I found on net. Hopefully it will be useful. static void EnumRights() { uint length = 0; bool res;   //...

How to split SQL file by GO statement

In some situations when using scripts to create/update database in code, I had to split input SQL script file by GO statements, as SqlCommand doesn’t really understand it. But in some place, I’ve came to a strange-looking code that does exactly that but… in really weird and NOT correct way. So here we go. How NOT to write: //separator char not used in TSQL char ch = '^';   //Ed: str is the text from SQL batch file ...

PowerShell and untrusted domains

I have a few PowerShell scripts that execute various automation tasks on our build machine, like sanity test of the latest build for example. The common scenario is to revert-VMWare-snapshot, copy latest build to target machine, execute whatever needs to be executed. This worked fine until I was asked to do the same tests on different domain, which is not in trust with domain of our build machine. At first glance, I thought that –Credentials parameter in PowerShell will do the trick, but it turned out it doesn’t work at all for functions like Copy-Item or Set-Content. I thought...

Setting property by name with automatic type conversion

I liked the idea of binding to properties in WPF or Workflows. So implemented something similar (although less powerful) in my code: I had a list of tasks and their data context, so I needed somehow to “bind” data from context to properties of tasks. As a part of implementation, I have created a method that allowed me to take an object (task), take one of its properties by name and assign that property a value. Everything in reflection, since property name nor its value is not known at design time and only evaluated at runtime. Remembering that my value is...

Setting WPF Dialog owner from within WinForms application

I had some WPF dialog that I need to show from older WinForms application, or more precisely from some WinForms UserControl. The problem was to set Owner of that dialog, GetWindow() didn’t work (of course) and leaving dialog without an owner, made it possible to disappear when user switch from application to application. And I didn’t want to show it in task bar either. Thankfully, there is a very easy way, which, for some reason, I didn’t find quite fast – use WindowInteropHelper class. Here is an example: ...

Sending E-mail From PowerShell v1.0

While in PowerShell 2 there will be a “Send-Mail” cmdlet (as I heard), I needed something for current version. Here is the self-explaining PowerShell script for sending mails with optional attachments and multiple recipients. Remember to change the hard-coded “mail.server.com” to your own mail server, otherwise nothing will work :). ############################################################## # Send e-mail with optional attachments # function SendEmail { param( $From, $To, $Subject, $Body, ...

Full Developer Archive