Author Archives: Timur K

ccScreenSpy – hidden screenshot capture and emailer application

I have received a number of requests regarding a screen capture application after posting the FileSlinger program in conjunction with the Logitech motion capture. While this was a fun quickie to code, I am really having trouble finding many ethical reasons to use a tool like this, but I guess I will assume that it will be used for automated testing and UI capture….

Ah.. Who am I kidding. I know it will probably be used to spy on employees and significant others so tsk tsk!

Anyway, the premise of the app is simple:

  • Run without a window (application is hidden to the nake eye, but you could spot/kill it in the Task Manager)
  • Capture the screen(s) at a configurable time interval
  • Email the screen captures via SMTP once a specified number of captures has been reached
  • Delete the files that have been emailed

System.ServiceModel.Web missing from .NET references

I ran into this issue more than twice already, so I figured I’d help Google be more effective in solving it for others..

One of the cool things about WCF is that it is fairly straight forward to configure communication with non .NET enabled technologies (i.e. Java, JavaScript, etc) via JSON or just plain SOAP. I am considering writing my own how-to on getting this to work, particularly from JavaScript and Android applications, but that is a topic for another post.

However, I will mention that one of the stipulations for getting this to work is decorating the OperationContract interface members with additional attributes, namely WebInvoke or WebGet.

These attributes are members of the System.ServiceModel.Web namespace and you need to add a reference the System.ServiceModel.Web .Net component in your application.

The thing that repeatedly happens to me is that when I go to add the reference, System.ServiceModel.Web is missing form the list. I then scratch my head and contemplate whether or not it is a deja vu experience (and it is).

The issue is quite simple – System.ServiceModel.Web is not part of the ‘.NET Framework 4 Client‘ Profile, which is the default profile Visual Studio creates for a WCF library project. It is however, part of the plain old ‘.NET Framework 4’ Profile.

The solution is to change the Target Framework in your project’s Application Properties (in Project Properties). Do that and voila! System.ServiceModel.Web is now available for your referencing pleasure.

Sorry for the excessive French jargon in the post.


ccQuickMint – Import Mint Transactions into QuickBooks

I’ve been using for the last couple of years and I’ve found it to be an invaluable tool for personal (and business) finance management and visualization. After it was acquired by Intuit, I was a bit worried, but it does look like Mint will replace QuickBooks online and not the other way around. However, one thing that I thought surely would come out of the acquisition would be ability to seamlessly trade data between the two applications. My accountant prefers to get my financial data in QuickBooks format and I certainly prefer the ease and intuitiveness of Mint. I always knew that mint allowed exporting transactions into Excel via comma-separated values file (CSV) and I was very surprised to find out that QuickBooks only allows limited Excel import – you cannot import transactions but only lists of vendors and such.

After some poking around, I found out about ability to import transactions into mint using IIF files. Essentially, these are specially formatted text files that include information about the transaction and account involved. After reading some documentation, I decided to bite the bullet and write a tool to convert transactions exported from mint into IIF, such that they can be imported into QuickBooks.

Welcome ccQuickMint – a tool to convert Mint’s transaction export into a format that can be imported into QuickBooks.

Read more…

How to Check if a Process is a Windows Service in C#

To make the long story long, sometimes it is handy to be able to tell if a given process is a service. Actually, I started from a simpler place – I simply wanted to tell if the current process was running as a service… And what do you know, turned out not to be so simple after all.

As usual, I did a fair amount of Googling before settling on the DIY course of action. Unfortunately, Google came up short on a succinct way to accomplish this seemingly trivial feat. Approaches suggested by my fellow code warriors included:

  • Get a list of all services via ServiceController.GetServices() and then compare them to the running application. Couple of issues with this one: getting the process path from Service controller is not a get_property type of operation and if there are processes with the same name/path where one is running as a service and another as a regular app this option fails.
  • Check the Security ID associated with the process. If it is service-like (e.g. SECURITY_SERVICE_RID or SECURITY_LOCAL_SYSTEM_RID) assume it is a service, otherwise it is not. Well… That does not work very well. I ran some quick tests and my console app ran as SECURITY_NT_NON_UNIQUE. I then ran the same app as a service (yep, that’s right..) and it showed up as SECURITY_LOCAL_SYSTEM_RID. Success – I thought. Well, then I changed the service “Logon As” properies to run as my user and the SID went right back to SECURITY_NT_NON_UNIQUE, so Failure! As a side note, in the pursuit of this solution I used values returned by System.Security.Principal.WindowsIdentity.GetCurrent().User. I also found this snippet which brought back some memories.. Oh coding C++ in 1995.. Things were so much simple back then…
  • Another suggestion was to see if ServiceBase appears anywhere in the call stack… I didn’t want to touch that one.

Read more…

The transaction log for database ‘VIM_VCDB’ is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases

I will confess up front, that MS SQL is not my strong suit as I always have dealt with open source DBs like MySQL. However, due to no fault of my own, I was facing the issue summarized in the title of this post in the scope of MS SQL.

Searching the tubes revealed that this can happen for many reasons and there are various (in my opinion poor) solutions for it. The gist of the issue seems to stem from the fact that MS SQL maintains a transaction log between backups, such that data can be recovered even between incremental or full backups. Nice idea and all, but why not provide a toggle for this functionality for those “extreme” cases where you don’t care about the data?

For the purposes of full disclosure, I was running into this issue with VMWare’s vSphere Server, which apparently uses MS SQL as it’s back end. The VMWare VirtualCenter Service apparently logs VM activity to the DB. Thus, if you have some automated systems that involve a lot of VM operations (i.e. reverts, shutdowns, etc), you can run out of DB log space pretty fast. When this happens, the VirutalCenter Service crashes with this message:

An unrecoverable problem has occurred, stopping the VMware VirtualCenter service. Error:

Error[ VdbODBCError] (-1) “ODBC error: (42000) – [ Microsoft][ SQL Native Client][ SQL Server]The transaction log for database ‘VIM_VCDB’ is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases” is returned when executing SQL statement “UPDATE VPX_DATASTORE WITH (ROWLOCK) SET INFO = ? WHERE ID = ?”

Read more…

C# Regular Expression to Match Everything But…

If you dabble into Regex-driven processing, this one can come in handy. For those of us who don’t consider Regular Expressions regularly (ba-dum-tshh), coming up with one from scratch can take a little time… but I digress.

This particular regular expression should result in a match for all inputs, except those containing the specified string:


The expression above will return a match for all inputs, except those that contain letter sequence ‘ipsum‘. 

Salt and pepper to taste, test it here.


How to Turn a Directory into a Drive in Windows

Sometimes it can be handy to expose a directory on your hard drive as a ‘virtual’ drive. That is, make a directory appear as if it were another hard drive on your computer such that you can refer to it as ‘D:\’ for example.

Well, for honesty’s sake, this is really rarely handy but hey.. One case I ran into recently involved sharing some files via Remote Desktop session. Unfortunately, RDP allows you to share drives, but not specific directories. Sharing all of C-drive did not make me feel warm and fuzzy, so I opted to just share specific directory, and that involved making Windows perceive it as a hard drive.

My solution is rather silly:

  • Share the directory as a windows share
  • Navigate to \\ – your own computer
  • Map the shared directory as a network drive

    Read more…

ASP.NET Code Snippet – Button Click Confirmation

It can frequently be quite useful to ask the user to confirm their submit request in an ASP.Net page. There are a lot of code samples out there that “emit” javascript in the server-side function once the postback has been issued. This can be appropriate if you need to do parameter validation or any background processing before asking for confirmation. However, for situations where you just want to make sure the button was not clicked by accident, this works quite well:

<asp:Button ID="bnTruncateDB" runat="server" OnClick="bnTruncateDB_Click" Text="Truncate The Database" 
   OnClientClick="return confirm('Are you sure you want to remove all DB entries?');" />

The generated HTML code calls Javascript confirm(…) function when the client-side onclick event is raised. The postback will only be processed if the confirm(…) call returns true (user clicks ‘Yes’).


WCF – The type name ‘ServiceReference1’ does not exist in the type ‘…’

Recently, I ran into another candidate for the WTF files having to do with an error message similar to the one in the title of this post. Here is the scoop.

I created a WCF service library implementing some basic functionality. Actually, to verify the error I am describing, I just created a new WCF Library project and used the default code contained therein.

Subsequently, I created another project that would become the WCF client. Here comes the iffy part..

Typically, I do not like keeping default file names generated by Visual Studio (i.e. Program.cs). Reasons for this include search ambiguity, dislike of non-descript code files, and just personal taste.

However, one of the things that Visual Studio offers during the name change, is to change the name of the class contained in the code file. So, if you rename Program.cs containing the following:

Read more…

How to highlight the current file in Visual Studio Solution Explorer

This is a silly little UI feature that used to be default on previous versions of Visual Studio – navigating to and highlighting the code file that is currently being edited in Visual Studio in the Solution Explorer tree. Well.. Apparently it is not the default in Visual Studio 2008, and every time I install the Studio on a new box, I have to recall exactly what I did to get the task accomplished. So I figured I’d post it

Solution Explorer

So, in Visual Studio, go to Tools->Options, select ‘Projects and Solutions’ on the left hand side, select ‘Genera’ sub-item and make sure ‘Track Active Item in Solution Explorer’ is checked off.

Hope this helps,


Unable to connect to the Microsoft Visual Studio Remote Debugging Monitor…

Remote Debugging is not something that typically comes into play when working on standalone applications. Well, maybe that’s not entirely true. My first exposure to remote debugging actually came about during some driver development I did back in the day – debugging a BSODing driver is best from a remote machine (and nowadays from a VM host..)

However, in the ever expanding world of distributed systems development, remote debugging can be key when the application being debugged is just a single node in a distributed system.

When it works, remote debugging is amazing. Well, actually it’s exactly the same as debugging a local application, but given that the application is actually running on a remote machine, which does not need to even have Visual Studio installed, it’s pretty cool.

However, there are numerous gotchas to getting remote debugging to work, and by talking about the blogtitle error message,  I am starting somewhere in the middle. The exact message is:

Unable to connect to the Microsoft Visual Studio Remote Debugging Monitor named ‘….’. The Microsoft Visual Studio Remote Debugging Monitor on the remote computer cannot connect to the local computer. Unable to initiate DCOM communication. Please see Help for assistance.

Error Message

‘…’ would be replaces by the IP address or machine name you are trying to debug.

Read more…

SerialTray – Terminal Emulator Launcher

Zonemicro MicrocontrollerIn my rapidly diminishing spare time, from time to time I engage into ridiculous activities such as programming microcontrollers similar to the one pictured here (check out this site for similar goodies). Typically, the data exchange with these devices occurs via a serial port and I use a USB to serial adapter since COM ports are hard to come by these days.

For the terminal emulator software, I personally like to use Tera Term. However, as with other emulators, one of the annoying things is that it requires you to specify the COM port (i.e. COM5) for the connection, but any given time you plug the USB cable, you may not know what the resulting COM port is. Similarly, if you have multiple devices connected, things get confusing as well.

USB-to-SerialEnter ‘Serial Tray’. Basically, it is a tiny app that resides in the Windows System Tray. When you right-click its icon, it lists available COM ports along with their friendly names. Check out this article on the associated coding struggle.

The application comes with an XML file (because that’s how I roll in terms of configuration) where you can configure a 3rd party application that should be launched when a particular port is selected. In my case, I launch Tera Term. Within the same XML configuration, you can specify application parameters that can include a variable %PortNumber%, which will resolve to the number of COM port you’ve selected (e.g. ‘1’ for ‘COM1’).

Read more…

The parameter is incorrect – at System.Diagnostics.EventLog.InternalWriteEvent

I’ve recently encountered this error in my error logging component. Naturally, an exception inside an exception handler is rarely a good thing and I was left scratching my head about what was going wrong.

There are numerous schools of thought in regards to what the best approach is to logging application errors. Consumer issues aside, when applications are administered by me or my team, I prefer using Windows event log or a file. In fact, I’ve written a general purpose library that allows an error, warning, or info to be logged in event log, text file, or displayed via user interface.

The error gracing the title of this post occurs during EventLog.WriteEntry function call. Actually, the exception is in the scope of the Win32Exception and this can occur during WriteEntry call on a couple of occasions. Most notably, when the Event Log is full (in this case, you cal Clear the log and try the re-write). However, this was not the case for me.

Another notable case for this exception is when the message exceeds the maximum message size, which is in the vicinity of 32000 odd bytes. The reason I am not specifying an exact number, is that apparently the actual maximum message size is tied to the length of the machine name and event log source that is writing the message.

Sadly, this too was not the cause of the error message.

Read more…

How to get friendly names for COM ports in C#

Recently I was developing a little application that needed to enumerate existing COM ports on a machine and then display them in a menu. Generally, this task is quite simple to accomplish:


I believe under the hood, this method simply enumerated the HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM key.

However, the tricky part was that I wanted to display human-friendly names that identify the device similar to they way they are displayed in the Device Manager. Well, this turned out to be a little more complicated than I thought.

Google revealed a couple of strategies that turned out to be limited.

1. WMI

There are a couple of WMI objects that one could enumerate to get a list of ports. However, none seem to produce a complete set.

SELECT * FROM Win32_SerialPort
SELECT * FROM Win32_PnPEntity

Read more…

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

Sometimes enhanced security translates to enhanced frustration. I think the exception gracing the title of this post is a decent example of this phenomenon…

This exception occurs in a couple situations involving creation of an EventLog object. Legitimate causes include:

  • Writing an entry (WriteEntry) via an EventLog object with a non-existent source (source that was not created via CreateEventSource(…) call
  • Calling CreateEventSource in the context of an account with insufficient credentials (i.e. non-admin)