Keeping things simple

Posts Tagged ‘Programing

Add routes on VPN connect with Powershell and Task Scheduler

with 12 comments

At my company we use a Microsoft ISA server for our firewall/VPN server. To be able to access the servers at my company via VPN required me to do one of two things:

  1. Use default gateway of the remote network
  2. Add static routes each time I connect via VPN

Option number one has the drawback that in such a scenario all my traffic would be directed through the VPN connection. Since my company has a very restrictive security policy which allows me to access only a couple of servers (TFS, SQL server, …). That effectively means that when connected to the VPN I can not use the internet or any other network resource.

Option number two requires that you add each of the routes to the routing table every time you connect the VPN. This can not be done via a batch script since the IP of the gateway changes on each connect.

So I thought to my self that there should be a better way to do this. With some basic Googling I quickly came up with an elegant solution. The first step towards the solution was a piece found on this blog. The blog discribes the very same problem that I was facing and provides a simple Powershell script that handles the routes. This Powershell script although it does what is need efficiently didn’t completely satisfy me.

Why? Well simply because I lazy and don’t like having to click on a power shell script on the desktop every time I make a VPN connection.

Doing some more Googling brought me to a Technet page that described how to use the Windows Task Scheduler to trigger the Powershell script execution on each VPN connect. Modifying the snippet I created this command which is executed in the Powershell command prompt.

schtasks /create /F /TN "VPN Connection Update" /TR "Powershell.exe -NonInteractive -command C:\vpn.ps1" /SC ONEVENT /EC Application /MO " *[System[(Level=4 or Level=0) and (EventID=20225)]] and *[EventData[Data='VPN NAME']]"

In this command change the path to your script, and change the last part where it says VPN NAME to the name of your VPN connection. This will ensure that the Task scheduler executes your script only and only when you connect that specific VPN connection. The complete explanation of the settings in the command can be found on before mentioned Technet page.

So I was almost there with the solution but the script it self did not satisfy me because I had to add multiple route and ensure that the routes are not already existing. I modified the original script to this version.

# ---------------------------------------------------------------------------------------
# Initial version:
# by Chris @ 30.9.2008
# ---------------------------------------------------------------------------------------
# Modified version:
# by Luka Ferlež @ 6.10.2010
# ---------------------------------------------------------------------------------------
# Add IP routes across a VPN via a DHCP assigned IP address
# Configuration
# ---------------------------------------------------------------------------------------
# Route IP address
$ips = @("", "", "")
# VPN connection IP
$vpnIP = "192.168.90."
# ---------------------------------------------------------------------------------------
# Get the IP address of the VPN connection
$vpnip = ipconfig | findstr $vpnIP
# ---------------------------------------------------------------------------------------
# If we don't have an IP address on the VPN, error and quit
if (!$vpnip) {
"You do not have an IP address on the VPN"
# Trim any leading/trailing whitespace
$vpnip = $vpnip.Trim()
# ---------------------------------------------------------------------------------------
# Split the contents of $vpnip in to an array
$vpnip = $vpnip.Split(" ")
# ---------------------------------------------------------------------------------------
# Find out the depth of our IP address in the array
$bit = $vpnip.Length - 1
# ---------------------------------------------------------------------------------------
# Get out just our IP address on the VPN
$vpnip = $vpnip[$bit]
# ---------------------------------------------------------------------------------------
# Delete routes if existing
foreach($ip in $ips) {
$hasRoute = route print | findstr $ip
if($hasRoute) {
"Deleting route " + $ip
route delete $ip
# ---------------------------------------------------------------------------------------
# Add whatever routes we need
foreach($ip in $ips) {
"Adding route " + $ip
route add $ip MASK $vpnip

This script allows you to simply add the necessary routes at the top of the script, and the script will process them, enjoy.

Written by Luka Ferlež

October 6, 2010 at 22:21

Software engineering is bad engineering

leave a comment »

This a common phrase that is used in reference to software in general. I have heard it from my friends, customers and even co-workers all of which are often ignorant of the complexity and the amount of different factors that are involved in the execution of a software application. I’m especially amassed when my programing colleagues criticize some software with no objective reason and fully knowing that their own software is as equally flawed. The very same question was raised on my new favorite programing Q&A site stackoverflow.

Bugs in software is something that we have to be aware will happen as long as there is software. Now most people that are not familiar with programing always ask why software can’t be bug free? That’s when I ask them if they have experienced something of the following:

  • Oil leak
  • Engine trouble
  • Leaky faucet
  • Wobbly chair
  • Squeaky doors
  • VCR eating the tape

Off course the answer is yes, we have all experienced some of this if not all and this are the equivalent of software bugs. Oil is not meant to leak from your car – bug, chairs are not meant to be wobbly – bug. In short my answer is no we can’t have bug free software because nothing around us is bug free even not ourselves we can only try to keep bugs down to the minimum.

You are not meant to be sick but you still are is that a bug in you immune system or was it caused by something else out of your body’s control? Strange question you might think but what it comes down to is that our body starts to malfunction because something that is out of the body’s control has influenced it and disrupted the normal way of functioning same apply’s to software.

Software developers constantly combat the external influences on their applications be it human input, operating environment, incompatible software or whatever other external source of influence. This all invites so many variables and possibilities in an already highly complex system that is being developed by humans and is thus by default faulty. When developing software you have to take into account different hardware and software combinations on which your software is supposed to run, users that are supposed to use it and when you factor all of that in you get massive number of possibilities. Now as I see it most applications today are quite stable for what & where they are meant to run.

Software engineers are trying to combat all of those possibilities and the bugs that arise from such a number of different scenarios and so far we have seen with each new release of software that they are managing to decrease the number of bugs rapidly and are producing really quality code.

Anybody remember Windows 95? 🙂

Written by Luka Ferlež

December 14, 2008 at 1:03

Posted in Programing

Tagged with

Connecting to TFS

leave a comment »

Like so many things in the programing world, establishing a connection to a TF server can be done in a couple of different ways. I have previously specified everything that you need to start developing an application that will interface with TF server, so I will skip the introduction to TFS development and get my hands dirty right away.

From you code, C# code that is, you can establish a connection to TF server in two basic ways. Both of two create an instance of a TeamFoundationServer class. One is trough a service class TeamFoundationServerFactory and the other is creating an instance of a TeamFoundationServer class manually through a public constructor.

The main difference between the two is that the TeamFoundationServerFactory static class will cache the connected servers, so that every time you request a server, a request is not being sent to the TF server, thus not clogging the server with requests.

TeamFoundationServer server = TeamFoundationServerFactory.GetServer("http://" + serverName + ":" + serverPort);

Now you have your instance of a TeamFoundationServer. Each time you call the GetServer(String) method it will check if the server has been already accessed, and if it was the method will return a cached instance otherwise it will create a new one.You other option is to create an instance of a TeamFoundationServer on your own.

TeamFoundationServer server = new TeamFoundationServer("http://" + serverName + ":" + serverPort);

If you it this way a request will be sent to the TF server to check if it exists, if you do that every time you need something from the server, you will generate a lot of request to the server.Basically if you use the TeamFoundationServerFactory class the framework will handle the caching of the server for you, if you create an instance on your own you will have to store that instance and keep track of it your self.


The TeamFoundationServer constructor way has one benefit over the GetServer(String) method. The benefit is seen when you get around to authenticating the users. When you want to provide user authentication through the GetServer method, you will use the overload that has looks like GetServer(String, ICredentialsProvider)
using the UICredentialsProvider class like so:

TeamFoundationServer server = TeamFoundationServerFactory.GetServer("http://" + serverName + ":" + serverPort, new UICredentialsProvider());


What this will do, it will create a pop up requesting the user credentials every time the user needs to be re-authenticated. The EnsureAuthenticated() method will first check if the user has already been authenticated, and if not it will create a login pop up for user credentials then authenticating the user.In your software you might want to save the user credentials to use them any time the user needs to authenticate. That’s when TeamFoundationServer Constructor (String, ICredentials, ICredentialsProvider) constructor comes into play. With this constructor you can specify in addition to a UICredentialsProvider object that is used as a fall back if the authentication fails, separate NetworkCredential object to be used for authentication.

NetworkCredential networkCredentials = new NetworkCredential(

TeamFoundationServer server = new TeamFoundationServer(
   "http://" + serverName + ":" + serverPort,
   new UICredentialsProvider());


This way the code will try to authenticate first with the selected NetworkCredentials and if that fails it will use the UICredentialsProvider to create the pop up and ask the user for credentials. This way you can save and reuse the users credentials when you want to, and if the authentication fails the framework will ask the user for credentials on its own.


I was having trouble connection to my company’s TF server, since our workstations are in one domain and the TF server is in a separate domain, with an ISA and a Web filtering server in between. I was getting the HTTP error code 407 “proxy authentication failed”, until I found a way to deal with it I lost around 4 hours. The solution is quite simple you just add this to to your config file.

 <defaultProxy enabled="true" useDefaultCredentials="true">
   <add address="serverName" />

When you put this in the application will by pass the proxy for the specified network addresses.

Written by Luka Ferlež

March 18, 2008 at 21:35

Web 2.0

leave a comment »

Been doing some programing lately, since I did none will I was on vacation. I made a couple of years ago a web site for my fathers company, and it has been working quite well, but i had to make some changes to it.

So I started to redo the css and so on, came up to the point of redoing some JavaScript.

Now I was never a big fan of scripting languages, and did do my share of programing in JavaScript, PHP, ASP (VBScript) and so on, and it was never to my liking. The only language I liked using was PHP because there I could use OOP, and that was a big thing for me since I don’t like messy code 🙂

But I abandoned PHP because there were some things that on my opinion make large scale programing difficult. Why? you ask, simply one big down side is the lack of an top notch debugger that can handle and work in all scenarios the same (tried Zend but did not like, I liked the work done with Eclipse). The one thing I could never forgive PHP is the way it handles different types of variables, and that there is no checking of the variables. For example if in certain function I create a variable named eclipse, and than try to reference it somewhere I make a typo and write eclpse = 1 then in that function I will have both variables and will be surprised to find out that my code does not work. Of course I am glad to see PHP developing futher, and so on as I believe PHP is ideal for sites that require some server work done, but not too much :).

Now since we live in the world of expanding Web 2.0 I would expect that the programing languages that are used in presenting data and the web are also evolving, and in this languages I don’t mean the ones that do their work on the server like PHP or VBScript, rather the ones that do their work on the client like JavaScript, CSS, HTML, XHTML and so on I on purpose don’t put XML in any of these groups since I don’t believe that XML is a programing language (nor is HTML but what the hell).

If you look at the parts of code that are executed on the client you will see that all of them are evolving. CSS started with 1.0 now is 2.1, and the 3.0 is under development, the same with HTML and XHTML, now at version 4.01 and 1.0 but with high emphasis on development and version 5.0 and 2.0 are in the works.

What language did not change much since it was introduced in 1995, yes it did change I know, and it is use is highly dependent on DOM, but the thing I dislike most is the lack of OOP. I know that you can create you own objects and so on, but I don’t like the way that is accomplished, which I think is unnecessarily complicated. Again I dislike that the language is not strong typed, and the hole thing with variable types is symptomatic to the scripting languages.

Today with the expanding world of Web 2.0, and exciting new possibilities like AJAX which is the corner stone of Web 2.0, we as programmers would like to give web the look and feel of the desktop, I don’t believe that that will ever be possible, since the client essentially operates in offline mode connecting to the server jut to get the content, and believe that JavaScript and the DOM will be the bottleneck of Web 2.0 development.

Written by Luka Ferlež

March 18, 2008 at 21:29

Posted in Programing

Tagged with

The storyboard

leave a comment »

The storyboard for what I’m trying to do here is quite simple.

Now game publisher have released several series of management games so called tycoon games. What I have always found lacking, was that the games where not deep enough in terms of company management. The games always focus on building a certain industry, selling or transporting the goods to the end customer. That’s where most tycoon games stop, not giving you the depth of full company management. Like human resources, setting salary’s, unions, advertising, organizing company departments to function like at optimal levels. Not to mention setting the goals for your R&D department, picking your CEO’s, CTO’s., CAO’s etc. for your company.

I would also like with the full depth of the managment part of the game, have access to several industries. Like production, retailing, transportation, construction, real estate, media, hotels etc., at your desposal to work with.

If you combine all of this aspects of the game, you get a quite a range of possibilities and long term playability. That is just the basic story board.

Written by Luka Ferlež

March 18, 2008 at 21:23

Game layers

leave a comment »

Ok lets start with the game design, first off all to outline the available layers of the game. Once I complete all the layers, hopefully they will stack up nicely, and provide me with a playable game.

Basic game layers:

1. Map layer
2. Resources layer
3. Objects layer ( buildings, roads, etc.)
4. Construction layer
5. Economic layer
6. AI behavior layer
7. Random events layer
8. Game development layer ( general developments as the game progresses – population rise, economic states etc.)
9. Object behavior layer
10. Data layer ( file system)

Now I might add some or drop some layers from the picture as the development process goes on, but this should be the basic layers that the game should consist of.

Written by Luka Ferlež

March 18, 2008 at 21:21

Start of a slow begining

leave a comment »

I am quite of a casual gamer, you know that type that always complains and always wants more and more of features etc. I understand game developers have a hard time of developing games and adjusting them to please as much gamers as possible. Since I am a software developer my self, and I always have to bend over for my clients, whose count fortunately is not in the millions rather just a dozen of those super smart “managers”, you could say that i have it easier then the game developers.

I have often thought about writing my own game, to correct all that stuff that i found lacking in the games i played. I found often that the games had a good start, but at a certain point it seams like the development stopped, and the features that could have been implemented have not been.

Until now I did not think that one man, without no previous knowledge about game development, directx, graphics and etc. could do, I am a back end, enterprise solution developer, so drawing is not something that I am good at. But now after a saw a few demonstrations by Microsoft, on WinDays, TechEd and community conferences XNA Studio could solve a lot of my problems.

So off to install XNA. First to download the installer, some 80 MB download free from microsoft, and lets try it. But then i find out, I dont have a habit of reading those readmes and so on, that you need Visual Studio Express C# SP1 installed. So I figure this has to be an install bug, since I have Visual Studio Team System SP1 installed on my laptop. But <span style=”font-weight: bold;”>no </span>Microsoft decided that for now it would only support the Express version of Visual Studio for use with XNA Studio. So i download the C# Express version, and install it the same with SP1. Next i find out that the Express version does not support my favorite add in ReShaper, which i find as an essential tool for any serious development. But luckily Microsoft is considering running XNA Studio on other version of VS in the future.

So to recap, to start with XNA you need:
1. Visual Studio Express C# (no exception, there is no hack to run XNA on other versions of VS)
2. Visual Studio Express SP1
3. XNA Studio 1.0 refresh

The OS on my laptop is Vista, and XNA Game Studio does not by its spec support Vista, but fearless as I am, I did it anyway, so far I did not have any problems.

Loaded the SpaceWar example and started to try to figure it out 🙂 keep you posted

Written by Luka Ferlež

July 22, 2007 at 21:18

Posted in Uncategorized

Tagged with , , ,