Skip to main content

Posts

Showing posts with the label Programming

LEAP Sweden - Windows 8 and Windows Server 2012

I am back home in the couch filled with enthusiasm from the last gathering of LEAP Sweden before the trip to Redmond in the end of May. Todays topic was the new versions of Windows (server and client) as well as the Business Intelligence product suite from Microsoft. The Business Intelligence suite basically is a really nice integration between products that already exist. With SQL Server 2012 , SharePoint 2010 and Excel 2010 tightly integrated Microsoft offers a really attractive package. Mikael Nyström showed off some of the new features in Windows Server 2012 . To say the least this is an impressive release. There is a heavy focus on virtualization, storage and terminal services which makes Microsoft a strong competitor against both VMWare and Citrix in the small to medium sized business segment. One of the coolest features has to be conditional permissions. Johan Lindfors gave a demo on Windows 8 development . He showed some samples of how easy it is to develop Met...

Google Search Appliance .NET solution

I recently worked on a project to integrate the search results from a Google Search Appliance into a .NET application. Although it seems like a pretty straight forward task, there were some small issues that I thought I might share. Background The communication with the Google Search Appliance is made simply with a HTTP GET request, which returns an XML formatted response. As for the Suggest service, the request looks about the same but the result returned is JSON encoded. For more information, please see the Google Search Appliance documentation , which is very extensive. Internationalization Since this solution was to incorporate several languages, the .NET application had to support and differentiate the languages. The GSA has very good built-in language support but there were at least one thing that was not completely obvious. The GSA uses either HTTP headers or query string parameters to determine in which language the request is made. If neither of these are supplied...

Get DNS-information using WMI

With the purpose of automation DNS documentation I needed to get information programatically from the DNS servers. The answer to this, and many other similar tasks is spelled  WMI . That is short for  Windows Management Instrumentation , which is an infrastructure for getting information from Windows using a specific query language. Here is a method to get the host names and IP addresses for each A-record on the specified domain. public string Server = "192.168.0.1"; public string Domain = "domain.local"; public string Username = "DOMAIN\User"; public string Password = "Pa$$w0rd"; public Dictionary<string, string> GetHosts() { Dictionary<string, string> hosts = new Dictionary<string, string>(); ManagementScope scope = new ManagementScope(String.Format(@"\\{0}\Root\MicrosoftDNS", Server)); scope.Options.Impersonation = ImpersonationLevel.Impersonate; scope.Options.Username = Username; scope.Opti...

System.DirectoryServices.AccountManagement

Ever since .NET 2.0  System.DirectoryServices.Protocols  have been a part of the framework and in .NET 3.5 even more directory related classes were added, namely  System.DirectoryServices.AccountManagement . That is exactly as it sounds a namespace containing methods for account management. This fits perfectly for a little project I have chosen to call AD Cleanup Tool. This tool will go through all accounts in a domain to clean up certain account properties, such as naming, password policy etc. Some older solutions does not work with todays versions of Active Directory, for instance if I want to set the property  User must change password at next logon . This has earlier been done by setting the property  userAccountControl  with the flag  ADS_UF_PASSWD_CANT_CHANGE . It is not possible to set that flag anymore, but S.DS.AM gives us an even easier solution: using(PrincipalContext context = new PrincipalContext(ContextType.Domain, "192.16...

Destroy old data in TFS

Team Foundation Server only performs soft deletes and the files are very easy to recover just by performing an undelete. After a while the deleted files may use a lot of unneccesary space. From TFS 2008 it is possible to erase the data from the database. On option would be to use  tf.exe and the  destroy  command. That however will be pretty tedious when there is more than one file that should be destroyed. I have created a small application to help with this task. The TFS communication is handled in a separate class which i very simple without any error handling. using System; using System.Net; using System.Windows.Forms; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.VersionControl.Client; using Microsoft.TeamFoundation.VersionControl.Common; namespace TFSCleanupTool { internal class TFS { private string ServerName = null; private VersionControlServer VersionControl = null; internal TFS(string servername) ...

Shuffle part of a List

The amazing game the Cornball is about to be ported to C#.NET. A project which is a lot easier than expected. The number of hours I put down so far is barely hitting two digits and still I have reached a playable alpha version. The source will be published in parts or in its entirety when I am finished, but until then there is one small problem I would like to show that required some extra thought. The class structure consists of Card and Deck, which inherits List<Card>. Deck has a Shuffle method which utilizes the Fisher-Yates  algorithm. public void Shuffle() { Random random = new Random(); for(int i = Count - 1; i >= 0; i--) { Swap(random.Next(i), i); } } internal void Swap(int fromIndex, int toIndex) { Card temp = this[fromIndex]; this[fromIndex] = this[toIndex]; this[toIndex] = temp; } In the middle of the game, only a part of the game should be re-shuffled, which renders this method useless. Long story short, I came up with ...

Nostalgia in Win32 API

I started my programming career by modifying a guestbook written i Perl for one of my first web sites. When I took the step into the Windows platform the natural choice was the Win32 API and C. In my early teens I managed to create a couple of really interesting applications. When Google recently found a  web site  from 1999 for one of these applications I had to take a trip down the memory lane. I have now found two amazing application, written by me in my teens, which even seem to work pretty good on todays operating systems, including a 64-bit Windows 7. The applications are developed and tested for Windows 95/98 so there are no guarantee for the function on other platforms. What I can guarantee is that the applications are 100% free from any malware or other bad stuff. Text  is a revolutionary text editor focused on fancy word proceccing functions instead of unnecessary eye candy. The Cornball  is a solitaire game where the goal is to put the cards in order ...