Wednesday, September 17, 2014

Disconnect users' RDP connection from a remote server

Sometimes you get the message "too many users connected", or you just want to disconnect a hanging session of yourself, and can't access the remote servers desktop, command line tools exist :

To check how many users are connected (and get the session Id of the session you want to kick:

qwinsta /server:[server name/ip]

This will show a list containing sessionname, username, id, etc. 
It's the Id we need for the next step :

rwinsta /server:[server name/ip]  [SessionId]

If you have the necessary rights the session will then be disconnected.

Tuesday, March 4, 2014

Force windows 7 to use Wired LAN connections over wifi connections

I noticed on my Windows 7 pc that the pc connects to WiFi even when connected by a wired LAN. This causes some inconveniences, so I had to find how to turn it of.
To make sure windows 7 prefers LAN, follow these steps :


  • Open the control panel
  • Click Network and Internet
  • Network and Sharing Center
  • (left) Change Adapter Settings
  • Hold the Alt key to make the menus appear and click Advanced
  • Click Advanced settings
  • On the Adapters and Binding tabs :
  • Select the Local Area Connection (names might differ)
  • Push the up arrow next to the list until the Local Area Connection is first in the list













Now just click OK and close all opened screens. Reboot might be needed. 

Tuesday, February 11, 2014

Formatting all files in a solution in Visual Studio

When I had to format all files in a solution,
all I could find at first were macros. Since Visual Studio 2012 doesn't have the macro explorer anymore,
I had to find an other way to accomplish this.

Thanks to this github page I found the follow code that accomplishes just what I need.
Open the Nuget package manager console and paste in (2 lines) :

function f($projectItems) { $projectItems | ? { $_.Name.EndsWith( ".cs" ) } | % { $win = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}') ; $win.Activate() ; $DTE.ExecuteCommand('Edit.FormatDocument') } ; if ($projectItems) { $projectItems | % { f($_.projectItems) } } }

$dte.Solution.Projects | % { f($_.ProjectItems) }
Thanks JayBazuzi!

Wednesday, February 27, 2013

Visual studio locking files on build

More and more I got a problem with visual studio blocking files on build, (Could not copy dll from debug to bin) mostly in web projects (MVC).
A solution was to clean the solution (getting the same error),
waiting a few seconds, cleaning again,
and then building.
Now I found a solution that seems to work,
right click the project,
properties,
Build steps,
and add to the pre build command line :
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

(You need to copy the double quotes too).
It might be needed to add this to more than one project in your solution, just look at the error you get when building.

Wednesday, October 13, 2010

Some handy Javascript array methods

Working with javascript arrays today, I found some handy functions:

- Creating an array :
var ray = [];

- Joining two arrays :
var resultArray = ArrayOne.concat(ArrayTwo);

- Getting only unique items in an array :
(Jquery has a unique function, but it does not work on strings / numbers)
Array.prototype.unique = function() {
var result = new Array();
o: for (var i = 0, n = this.length; i < n; i++) {
for (var x = 0, y = result.length; x < y; x++) {
if (result[x] == this[i]) {
continue o;
}
}
result[result.length] = this[i];
}
return r;
}


- For each in JavaScript(using JQuery):
(although JavaScript has for (item in collection) functionality, it is not useful as it also iterates through the methods of the object.)
$.each(collection, function(index, value) { alert(index + ' : ' + value); });




- Bonus JavaScript : Splitting a string by multiple delimiters :
use a regular expression :
var result = myString.split(/[DELIMITERS]+/);
just replace DELIMITERS with the delimiters you want (one character delimiters)

Thursday, October 8, 2009

IE 6 not showing borders

We had a site that did not show the borders around a div in IE6,
After a while (and using google) I found out that I only needed to add
position: relative; on the element or its ancestors (only that element and descendants are fixed)

I found it Here.

Tuesday, October 6, 2009

Good old VB functions in c# Left, Mid, Right

Missing the good old string functions in c# I wanted to recreate them.
This is my solution where they are resurrected as extension methods.


public static class StringHelper
{
    public static string Right(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(source.Length - length, length);
    }

    public static string Left(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(0, length);
    }

    public static string Mid(this string source, int startIndex, int length)
    {
        if (source.Length == 0 || length <= 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex, length);
    }

    public static string Mid(this string source, int startIndex)
    {
        if (source.Length == 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex);
    }
}


To keep the code from giving errors I check for the length parameter,
if this is not what you want, you can throw an argumentexception for example ...

Thursday, July 2, 2009

Javascipt Replace, Replace All

Working in javascript today,
I found out that in javascript, the replace function only replaces the first occurrence, not all as in c#/VB.
You can test this by pasting the following in the addressbar of (most) browsers:

javascript:alert('test-test-test'.replace('-',''));

To replace all occurrences you need to use regular expression (place the word you want to find between / /g :

javascript:alert('test-test-test'.replace(/-/g,''));


or you can create a javascript function eg:

function replaceAll(text, findText, replaceText)
{
return text.replace( new RegExp(findText,"g"), replaceText);
}

Friday, March 6, 2009

Portable Browsers

Are you a webdeveloper,
or do you need to run some sites in a specific version of Internet Explorer (or Firefox or ... )

Or do you just want to try a new browser version without installing it?

Earlier I put up an article about IETester which allows you to run Internet Explorer 6 (and others) on Vista.
Now I found a new (and better) way to run different browsers without the need for installation :


http://www.xenocode.com/browsers/

Currently they have the following browsers :
- Internet Explorer 8, 7, 6
- Firefox 3, 2
- Google Chrome
- Opera
- Safari

From the site :
Xenocode WebApps do not require any software to be installed and allow multiple application versions to run side-by-side on any version of Windows.


So they should run on any version of windows (not yet tested, only on vista).

Have fun!
It works fine here, and I have

Wednesday, February 25, 2009

Menu Selection Gets Stuck on Screen

At work,

when I chose an item in a right click menu it stuck on screen,
It dissappeared when I locked and then unlocked the pc,
but reappeared the next time I selected an item. This does not work in windows 7 (and maybe 8), the quick workaround there is Start > Run :
tskill dwm

Right clicking the desktop and closing the menu also helped, but this were only workarounds.

I finally solved it :
Go into Windows Performance Options and de-select the option for "Fade out menu items after clicking."

In Vista, you can find it by right clicking My Computer > Properties > Advanced system settings (link on the left) > Advanced (tab) > Performance settings (button) > Visual effects (tab).

To cure it one in windows 7 you can set the corresponding monitor from 32 bit to 16 bit and back again, to remove one item. If it keeps happening, use the above solution.

Friday, February 20, 2009

Windows Needs to Format this device when you plug in usb stick

I recently bought myself a Sandisk Cruzer stick for on the road.
Everything worked fine untill windows (vista) began to complain when I plugged in the stick : Windows needs to format this device (or something very similar)

Having some data on the stick I didn't want to format it, so I started looking around. I found the solution :

With the usb stick plugged in (it does not really matter but it makes it easier)
go to Start / Control Panel
Here depending on whether you have the classic view or not :
Classic view : System / Device manager (left side)
Standard view : Hardware and Sound / Device manager / View hardware and devices

Here find the usb stick driver in the device manager (should be under Disk Drives),
be sure to select the correct one!
Right click it and choose uninstall

After this unplug and replug the usb stick, vista will now install 'new' drivers and that did the trick for me.

I also read somebody who had to redo this when he restarted vista, but in my case this was not needed.

Tuesday, January 13, 2009

Run as different user in Vista and Server 2008

When you shift + right click in Vista (or Server 2008) you will not find the trusted Run As ... Item, all you find is Run as Administrator. But this is not always what you need.
You can use the command prompt and the Runas command but this is not so easy as the old right click command.

Enter Sysinternals, they release a little tool called ShellRunAs that you can find here

After you downloaded it copy the ShellRunas executable to the windows\system32 folder and run shellrunas /reg

From this moment the run as different user item is back in your rightclick menu (or in your shift right click menu)

Thanks Sysinternals!

Thursday, December 18, 2008

Linq Where not exists query

Today I needed a where not exists query in my linq to objects.

Fortunatly I found it using the google :)

Suppose we have 2 lists, the first of a dummy class with properties Id and Name, the second of another dummy class with properties Id and Color (just so they are different)

We can perform a 'where not exists' query as follows :

var OnlyInFirstQuery = (from item1 in list1 select item1.Id)
.Except
(from item2 in list2 join list1Item in list1 on list2.Id equals list1Item.Id select item2.Id);


This will give us a list having only the items in list1 that do not exist in list2, just as I needed.

Thursday, October 9, 2008

Using Internet Explorer 6 on vista

There is probable a few people who would want to run ie6 on vista,
probably the webtesters (like me), or people who don't like ie7 (like me) but do not want to use opera or firefox (unlike me). And since the normal XP portable editions do not work, it seemed there was no answer.

Searching the google did not reveal much,
only that a lot of people were trying the same thing.

Luckily I found a great program IETester which makes this possible
(I did not test yet if it does everything IE6 does, but for my case, it was perfect).

the link is : IETester homepage

This program allows you to run your (or other) sites in
internet explorer version 5.5, 6, 7 and since the latest version 8 beta 2.

I hope this helps somebody!

Wednesday, October 8, 2008

Window opened from javascript

When using javascript to open a window, it appears on top.
When this window loses focus (gets in the background),
and the user clicks the link again, the window is reloaded,
but does not get the focus again.

Since for some people this is important, the solution is to make sure the opened window has the focus :

var openedWindow = window.open("someurl", "somewindowname");
openedWindow.focus();


This will refocus the opened window.

Thursday, August 28, 2008

Internet Explorer 8 Beta 2

Internet explorer 8 Logo
Microsoft has opened up the second beta for Internet Explorer 8

Some new features are :
- Accelerators : Select some text and a new Icon pops up, allowing you to search it with Google, mail it, ...
- Search bar improvements : Sizable, and it can show the first result for seaches on eg. wikipedia
- Web Slices
- Stability : Crash recovery and each tab has its own thread, so crashes should close only one tab.
- Tab groups : When opening a link from a tab, both tabs will get a color, indicating at a glance which tabs belong together.
- Inprivate Browsing (a.k.a. the porno modus) : When activated IE will not remember any cookies, or leave traces from the sites you have visited.
- And more (click here for the tour)

I installed it on vista, and it seemed a little faster (maybe my perception). Tabs groups seems very nice and useful. The first look is very nice, better than IE7, but I guess it will not yet replace my Opera :)

You can download the beta :
Here for XP
Here for Server 2003
Here for 64 bit XP/Server 2003
Here for 32 bit Vista/Server 2008
Here for 64 bit Vista/Server 2008

Enjoy :)

Hug a Developer Today



for larger size : Click Here

Tuesday, August 26, 2008

Linq To SQL Stored Procedure returns an Int

Today I was using Linq To Sql to execute a stored procedure wicht returned results by using a temporary table and dynamic sql (not my stored procedure)
Suprisingly enough when I dropped the procedure on the dbml file,
it generated a function with the return value typed as integer.
As it turned out, linq to sql and temporary tables don't play nice.
And since the database was a sql 2000 db, using table variables was not possible.

The solution turned out to be simple enough,
replace the stored procedure with a dummy one that returns the fields your normal procedure will return (names and type).
Then drop this stored procedure on the dbml file.
This will generate the correct return type for your procedure,
then simple alter the stored procedure to the correct one.

Hurrah, we can now use linq to sql to use our difficult stored procedure.

Wednesday, July 16, 2008

Clipboard problems

Today I when I copied some text,
I couldn't paste it anywhere.

Usually I just use the shortcut keys,
but to test it now, I used the contextmenus.
Copy (or cut) appeared just fine, but when I wanted to paste,
the item was grayed out in the menu.

Looking for the clipboard viewer,
I located it in c:\windows\system32 folder, named clipbrd.exe.

As I started it, it gave me the following error :
The ClipBook service is unavailable or is not started.
Contact your system administrator to have this service started.


All fine and well, but what a weird error, looking at the clipbook service description I found :
Enables ClipBook Viewer to store information and share it with remote computers.


Not exactly what I needed, as remote computers or the clipbook viewer were not my target.

So I just clicked OK,
and tested the viewer,
and 'lo and behold my clipboard functions were working again and I could copy and paste as I wanted.

Monday, June 16, 2008

Opera 9.5 Released

Opera has released it's new desktop version.

Opera 9.5 beautifully engineered

New features contain :

- Faster speed : up to 2 times as fast as the already fast 9.2x builds
- Opera Link : Sync your bookmarks between your desktop(s), opera mini and more
- Fraud protection : According to the company, it is "the first publicly-available browser to protect you from malicious software on the Web." Opera's protection is assisted by Haute Secure, Netcraft, and PhishTank.
- A brand new skin

And of course it is still free. Just click the image above to go to the download site.

After more than a year of testing the alpha / beta / RC builds,
I like the new version, it is much faster,
my only gripes with the new version were :
- When I installed it changed something so that I could no longer just type my search query in the address bar (luckily there is a quick fix : tools, preferences, search tab, edit google properties and check the use as default search provider)
- The close buttons are small (not really a problem as I use mouse gestures)
- The add tab button is moved from the left to the right of the tab bar (but that was also a small change)

So after a small test weekend I like the new version and have not encountered any bug.

Happy surfing!

Edit : 9.51 was released and it fixes a good number of problems users were having with 9.50, just click the banner and you will get the new version.