Occasionally Relevant Insights from a Software Builder


DateStamp – Sending Keystrokes to Another Application

This is a utility I wrote for a department at work to stamp a date and time for an annotation in an e-mail. The e-mail client we are using does not support this feature so we have to do it manually.

The program is interesting because it shows how to send keystrokes from a C# application to another program. I was trying to make the target application active to send the keys, but the command to make it’s document active requires the document name in it’s arguments (see below). I found it simpler to set the DateStamp program so it’s always the topmost window and when you click the Stamp button, it will send an Alt-Tab keystroke to switch to the previous application. The date and time are then sent as key presses. It’s not a very elegant solution but it works.

You can make an application active and send commands with the following statements:

Microsoft.VisualBasic.Interaction.AppActivate("Untitled - Notepad");
SendKeys.Send ("This is a test.");

If you are using C#, you need to add a reference to Microsoft.VisualBasic in order to use the above AppActivate function.

The Send command sends the text as key presses to the application. You can also use the SendWait function which does the same thing but also waits for the message to be processed. If the commands from SendWait are not being processed properly, a slight time delay may need to be set between commands. This is a problem with the .NET Framework.


Scrollable CSS Regions

Frames were an exciting addition to web design when it was released. They would allow you to have fixed regions on your web site which is good for keeping ads or menus constantly visible. The nice thing about the fixed regions is that if there was too much information to display, you can scroll to view the entire content. The only problem is that web browsers rendered the frames differently so text tended to overflow out of the frame which then had to be viewed by using the scroll bars (if they were set to be visible).

The following code defines a CSS scrollable region:

... text ...

If you set the overflow property to auto, the content is clipped to the area defined by div and scroll bars are added if they are necessary. For text, you would normally get the vertical scroll bars and not the horizontal ones.

Setting the overflow property to scroll will clip the contents to the view area and make the horizontal and vertical scroll bars appear regardless of the content overflowing it.

Below is an example of a scrollable CSS region using the above code.


Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi sit amet eros. Pellentesque ullamcorper dignissim dolor. Proin imperdiet lacinia nunc. Nam diam sapien, gravida sit amet, tincidunt ac, ornare vel, lacus. Nam vel eros ut ipsum mollis adipiscing. Etiam rhoncus sapien quis lorem. Proin dignissim mauris convallis leo. Suspendisse et ipsum vitae libero hendrerit porta. Aliquam congue auctor ipsum. Nulla lobortis. Etiam quis eros. Vivamus scelerisque, lacus sed aliquet placerat, sem mauris sollicitudin magna, id sodales ipsum nunc a pede.

Quisque aliquam elit et ligula. Nullam orci elit, pellentesque nec, sagittis eu, congue sed, orci. In nec ligula fringilla quam tincidunt elementum. Proin lacinia. Aenean vulputate, libero sit amet porttitor sollicitudin, diam turpis accumsan massa, et condimentum lectus quam eget enim. Nullam fermentum vestibulum sem. Aenean tempor mi sit amet lacus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Quisque ultrices purus nec neque. Ut dictum orci sed ligula. In hac habitasse platea dictumst. Quisque ultrices tristique pede.


This is a basic example and more can be done, but it should give you an idea what is possible with CSS. You don’t need to use frames to make scrollable areas on your web site.


Making Joomla Work in Windows

Joomla is an easy to use (but challenging to learn) CMS. It will run on any web server with PHP and MySQL installed. Most installations are run on Linux-based servers, but you can run it on Windows as well.

I’ve been testing Joomla in Linux extensively and I learned enough to build a real application with it. So I installed it in Windows and at the end, an error message was displayed that it couldn’t write the config file. The settings that should have been written were cut and pasted into the configuration.php file.

Then you can view the Joomla site in your web browser. This is normally done by typing localhost/joomla_site in the web browser address bar.

Everything seems fine until you login as administrator and try to save changes you make in the site configuration. An error may be displayed that the file can’t be written to. The files may be read only which can be easily fixed by right clicking on it, selecting Properties, and de-selected the Read-only checkbox.

If this doesn’t allow you to write to the config file, you’ll need to give the Internet Guest Account permission to access it. This can be done by right clicking on the config file, select Properties, select the Security tab, and then press the Add button. Press the Advanced button, and then press the Find Now button. Select IUSR_NAME (where NAME is the name of your computer). Press OK and then OK again. With the Internet Guest Account selected, press the Full Control checkbox and then press the OK button. Joomla will then be able to write to the config file.


Decompiling .NET Applications

Have you ever wondered how a program worked? If your not a programmer then you probably wouldn’t think of such things. A software developer, however, might. They would be interested in knowing how a feature or an entire application functioned in order to duplicate it in their own work.

A program can be examined by decompiling it and then studying it’s source code.

What decompiling does is that it translates a program from it’s native machine language (i.e. CPU instructions) to a format easier to read, such as assembly language.

This seems kind of scary. All of the hard work you put into your award winning application can be copied by someone else. But it’s not as easy as it seems.

For example, have you ever tried reading someone else’s source code? Even with comments and meaningful variables, it’s a challenge. Now try reading code with no comments and cryptic variable names. This is what you typically get after decompiling. Trying to interpret decompiled code is a difficult and time consuming task.

However, a decompiled .NET program is easier to read than a Windows native app. Visual Studio leaves the names of identifiers alone when compiling to an assembly. The result is still difflcult to understand but you can have a good idea what’s going on.

If you want to try decompiling a .NET program, you can download Reflector by Lutz Roeder. Be prepared for the surprise when you see how close the decompiled code is to your source code.

Fortunately, Visual Studio comes with a utility to obfuscate .NET programs, the Dotfuscator Community Edition. It will change the names of identifiers so that they will no longer be meaningful. There are also other commercial applications that will do the same thing.

If you want even more security for your code, a linker can be used. This will turn your .NET app into a native Windows program. The advantage of using a linker is that there won’t be the slow JIT precompile stage due to the app already being compiled.

Even with all of these precautions, your code is still not safe. A determined hacker can still decompile your program and figure out what it does. An obfuscation or linking tool may have them looking elsewhere for easier ways to copy code.


Managing Users in phpBB

Managing users is essential when running a forum. In spite of phpBB’s many strengths, it is lacking in this area. Deleting a user in the administration panel is quite an involved task and I normally do this through the backend by directly modifying the phpbb_users table in the MySQL database.

While this is not the recommended way of managing users in phpBB, it’s highly effective and easy to use. You just have to make sure that a user has no posts when you delete them or you’ll have records in your databases that don’t link anywhere. Another risk to directly modify tables in the database is that you might corrupt it in other ways making it unusable. If your not familiar with the phpBB database structure, avoid playing with it. 😉

I recently found a utility called PHPBB Admin Toolkit. This is a utility for controlling all of the settings for a user, including deleting users and all of their messages. Before this, when spammers posted their messages, I had to delete each message one a time. After this was done, the spam user was also deleted. I used to spend about a half hour each day cleansing my forums. I think there are better things to do with my time.

The toolkit allows the deletion of multiple users along with their e-mails. If a spammer manages to post a message, I can quickly and easily wipe out their account and messages.

Also, if a hacker manages to login with the admin account and demotes it or changes the password, the toolkit will allow you to access your forum and regain control over it.

A bonus feature that it includes is a security scan which will show if there are any issues that can compromise your forum’s security.

Overall, the PHPBB Admin Toolkit should be a part of every forum webmaster’s utilities. You can download it at