Script: NTFS rights on user home directories

Have a normal Windows setup where the user have a home folder on the file server. All the users is connected to there \fileserverhome$%username% via GPO on logon. How ever we found that some of the folders had rights that where messed up. So i wrote a quick script that loopes through all folders and checks if there is a user account in the domain if not it will move the directory to __unconnected__ folder. For all know users it uses cacls command to set rights for the user and admins only. If you need something else you can just edit the cacls command before you run it! Script is provided as is and feel free to modify it…

Download script here: [wpdm_file id=2]

Option Explicit
Dim path, objRoot, domainname, fso, rootFolder, folder, objShell, intRunError
path = inputbox("Enter path of homedirs:")

‘ Get current domain
IF domainname = "" THEN
domainname = objRoot.GET("defaultNamingContext")

‘ Setup FSO connection
Set fso = CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(path)
Set objShell = WScript.CreateObject( "WScript.Shell" )

‘ Go through all homedir folders
For Each folder in rootFolder.SubFolders
if(FindUser(folder.Name, domainname) = 1) Then
‘ Folder found reset the permissions
wscript.echo folder.Name + " – has a user connected! Reseting the permissions…"
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & folder.Path & " /t /c /g Administrators:F ""Domain Admins"":F " & folder.Name & ":F", 1, True)
If intRunError <> 0 Then
wscript.echo folder.Name + " – ERROR assigning rights!"
wscript.echo intRunError
wscript.echo folder.Name + " – Rights asigned!"
End If
elseif(FindUser(folder.Name, domainname) = 0) then
‘ This folder isn’t connected move it
If(folder.Name <> "__unconnected__") then
wscript.echo folder.Name + " – doesn’t have a user connected! Moving to .__unconnected__"
fso.MoveFolder folder.Path, rootFolder.Path + "__unconnected__"
End If
wscript.echo "ERROR: Connection to AD failed!"
End If

Set objRoot = Nothing
Set fso = Nothing
Set rootFolder = Nothing
Set objShell = Nothing

‘ Function to check if user exists
FUNCTION FindUser(BYVAL UserName, BYVAL Domain)
Dim cn,cmd,rs
SET rs = CREATEOBJECT("ADODB.Recordset") "Provider=ADsDSOObject;"

cmd.commandtext="SELECT ADsPath FROM ‘LDAP://" & Domain & _
"’ WHERE sAMAccountName = ‘" & UserName & "’"

SET rs = cmd.EXECUTE

IF err<>0 THEN
FindUser = 2
wscript.echo "Error connecting to Active Directory Database:" & err.description
FindUser = 1
FindUser = 0

Viewing Axis webcam from iPhone

I just installed an axis webcam at home to keep tabs on my home when I’m not there. I tried a few apps for my iPhone to use the cam as easy as possible. I found four free apps for Axis cameras but only one that actually was usable.

Netcamviewer – Don’t support SSL.

CamControl – Works great! Or at least the only one that supports SSL.

CamViewer – Looks really unprofessional, don’t support SSL.

CamSee  – Don’t support SSL.

Facebook login open to enumeration

The error message above is in Swedish, the short version: “The e-mail address you entered isn’t connected to any account in our system.” So instead of telling me that my username / password combo was unsuccessful they actually help me with half the problem. If they only would have told me that the username and password combo was bad I wouldn’t know if I had the correct e-mail address for the account i’m interested in. So I will just try the different e-mail addresses I know of my intended target with some bullshit password until I get “wrong password” error and then I know what e-mail they use. Really not good Facebook!

SQL error after upgrading from express

A few days ago I helped a client update there SQL 2008 Express installation to a real SQL 2008 R2 installation. They have been hitting the wall for the 4Gb database size limit for some time so it was really time. I installed the new instance on the server and all went well. I just don’t understand why SQL 2008 Express uses the default instance name MSSQLSERVER. Last time I had anything to do with the express version off SQL I think I remember the instance was named .SQLEXPRESS or something similar. This isn’t really a problem except that the default instance can’t be accessed unless you name it. Some programs doesn’t solve that issue as well as others and the default instance name of MSSQLSERVER I think should be reserved for the real installation.

How ever the move of the databases was really easy as well. Just took them offline, deattached them from the express installation and reattached them to the new SQL 2008 server install. Then when it was all done I uninstalled the express installation. That was when the problem started. I couldn’t use the SQL Server 2008 Configuration Manager anymore. It just gave my this error:

Cannot Connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager. Invalid namespace [0x8004100e]
[plain]Cannot Connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager. Invalid namespace [0x8004100e][/plain]
After a little digging around I figured out that the WMI namespace had been uninstalled by the express version uninstall. From Microsoft I got the information that the 32-bit express installation shared files should still be on disk and that I could reuse them to fix the issue. According to Microsoft I should be able to do this:
[ps]mofcomp "%programfiles(x86)%MicrosoftMicrosoft SQL Server100Sharedsqlmgmproviderxpsp2up.mof"[/ps]
How ever the installation wasn’t in that folder and I realized that the information was wrong. Part of the installation was actually there but at an other path. So I ended up with this:
[ps]mofcomp "%programfiles(x86)%Microsoft SQL Server100Sharedsqlmgmproviderxpsp2up.mof"[/ps]
That solved the problem and I was able to run the SQL Server Configuration Manager again.

Watchguard SSLVPN unavalible

One organization I work for have Watchguard firewalls and are using SSLVPN. Yesterday it just stopped working. You couldn’t connect with the client and if you tried to access the {firewall address}/sslvpn.html you got “Connection refused”. First I tried to reboot the firewall and ended up with the same result. Checked the debug log and found these entries:
[ps]2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=8dea8c0) not found. Debug
2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=adea8c0) not found. Debug
2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=9dea8c0) not found. Debug
2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=4dea8c0) not found. Debug
2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=7dea8c0) not found. Debug
2011-11-17 20:28:36 sslvpn sslvpn_userlist, entry(virtual_ip=2dea8c0) not found. Debug[/ps]
Googled it, of course, and didn’t really find anything useful. So i started checking all of the config, the access to the AD and stuff like that. Thought that if the firewall didn’t get access to the AD it might just close all AD dependent connections but all looked OK there two.

Finally I found out how to solve it, or really get ride of the problem. It’s hardly a sexy solution but here’s what I did:

  1. I saved my config to an XML file.
  2. I disabled the SSLVPN and saved that config to the firewall.
  3. Opened the saved XML config with SSLVPN enabled and uploaded it to the firewall.

Then it all worked again!

Hyper-V unable to start or connect

Received this error when I was working with my Hyper-V servers. It’s easy to solve but the hos machine has to be rebooted and therefore all the VM machines will be unavailable for a while during the reboot.
[plain]Cannot connect to the virtual machine because the authentication certificate is expired or invalid. Would you like to try connecting again?[/plain]
This error is due to the VMMS certificate expiring. So just run the KB fix and the issue will be gone!

More info:
Direct download of the fix:

Get all from Spotify

I have been checking peoples Spotify settings whenever I get access to there computers for service and stuff like that. And almost all people don’t get all they can from Spotify. Most of the computers I checked uses the premium version, the free version isn’t much fun anymore with all the limitations. If you have a premium account most songs are available in 320kbs but the standard setting is only 160kbs.

In the menu Edit -> Preferences… this can be corrected! Check “High quality streaming” and uncheck “Set the same volume level for all tracks” to get the full range of the track.

On your smartphone you go to the Settings (the small gears icon in the lower right hand corner). Set both Stream and Sync to High Quality and if you ever have bad reception, or anything else that gives you lower data transfer speed, just change the stream setting temporarily. I usually sync all my tracks because Sppotify uses a lot of battery power when streaming all the time!

Windows startup error

Worked late last night, on a friday I know! One of my laptops, an XPS M1530, have been making a strange noise. The speaker locks it self in some strange scream. Sometimes I was able to get it to shut up by tapping on it but other times I had to connect headphones to get it to shut up. Last night I was tired of it so after a did the shutdown I took it apart and ripped out the broken speaker and cut out the cables. Then I put it all together again and tried to start the computer. My entire hard drive is encrypted with True Crypt and I also have a hidden operating system on the machine (both win 7 x64). On start up I got the password screen for True Crypt and entered my password for the decoy system and got this error:

[plain]Error:  error no bootable partition found[/plain]

I goggled a bit and didn’t find anything useful. I realized it probably was the boot properties that was messed up but none of the tools I had could access the disk because it was encrypted. So I did have the recovery cd created by True Crypt so I started it up and decrypted the entire system. Then i restored the original boot loader and tried a reboot.

[plain]Missing operating system[/plain]

So I only got a new error message instead. Google didn’t give me much more then that I should use the windows install cd to repair it. I have been working with windows for a long time and I don’t have any good experiences with Microsoft repairs. So I didn’t want to do some universal end user fix that would f*ck up my system. I booted from the windows dvd with hope of a command prompt. When I selected “Repair my system” it couldn’t find my system but I could read the disk from the prompt. So I took the disk out of the computer and hooked it up to my other laptop and activated the C: drive of the decoy system. Now the repair function of the Windows 7 install DVD could see the installation. I got a dialog that told my that my boot options was messed up and asked me if I wanted to repair them and reboot. Yes please that would be lovely! Did it boot, of course not!

But I got even a new error! Just a blank black screen with a flashing underscore cursor. So what now? I already know that my master boot record (MBR) and probably my boot manager was broken. So I tried to boot from the Windows 7 install DVD again and issued two commands:

[ps]bootrec.exe /fixmbr
bootrec.exe /fixboot[/ps]

Restarted the machine and got a new error again!
[plain][/plain]BOOTMGR is missing
But this was the first good error message so now I could really get down to fixing the issue. Started the Windows 7 installation DVD repair function again and entered the prompt. Issued the following commands:

[ps]chkdsk /r[/ps]

To check for errors and “repair” them. If chkdsk finds anything the disk is usually about to fail. Really don’t like when that finds anything.

[ps]Bcdedit /export C:BCD_Backup
ren c:bootbcd bcd.old
Bootrec /rebuildbcd[/ps]

This rebuilds the boot options for the boot manager. But this command only sacans all the disk trying to find windows installations. I couldn’t see that it found anything but I could access c: so then i entered it manually:

[ps]bcdboot c:windows[/ps]

Then I ran bootrec again:

[ps]bootrec /fixmbr
bootrec /fixboot[/ps]

Then I restarted the machine and it booted without any problem. But only my decoy system, my hidden operating system is still on a partion that looks “RAW”. In my case it doesn’t matter becuase I rarly used my hidden system anyway and really only created it for fun. But I think it would be possible to get the system back but I didn’t try. I’m just glad that my primary system was back on track.

LINQ to SQL: Left join with null values

I was staying up late last night coding on my project and hit a snag. Trying to join two tables that have a 1 to many relationship. The issue was that I was trying to get all the rows from one table and where there where get the corresponding entries from the other table. In short I have one table containing to-do-lists and one table containing the tasks for each list. But I have been a good boy and done all the tasks on some lists so they are empty. When I tried to join them I only got back the lists that had task on them. I dusted of my old copy of SQL Queries For Mere Mortals and was able to do it in SQL. But I wanted do it with SQL to LINQ. After a few hours I couldn’t get any further. Tried to Google it and came up short. So I posted this on

I’m trying to get data from two tables. Todo_Lists and Todo_Items. I manged to join the two like this:
[sql]from list in dataContext.Todo_Lists
from item in dataContext.Todo_List_Items
where list.UserID == userID &amp;&amp; list.ListID == item.ListID
select new
    ListID = list.ListID,
    ListName = list.ListName,
    ItemID = item.ItemID,
    ItemName = item.ItemName
That’s all good in the hood if I just want the lists with Items on them. But I need to return all the lists and where there are Items I need them to be joined in.

Thankfull for any information!

That’s the good thing living in the far north, we have day when the US have night! So when I got back from work I found two answers. None of them was a complete solution but combined they pushed me in the right direction. I realized that I had to give the LINQ engine an alternative to null. This is what I came up with:

[sql]from List in dataContext.Todo_Lists
join Item in dataContext.Todo_List_Items on List.ListID equals Item.ListID into compList
from resList in compList.DefaultIfEmpty()
where List.ListTrashed == false &amp;&amp; (resList.ItemTrashed == false || resList.ItemTrashed == null)
orderby List.ListSortOrder ascending, resList.ItemSortOrder ascending
select new
ItemID = (resList.ItemID == null ? int.MinValue : resList.ItemID),
ItemSortOrder = (resList.ItemSortOrder == null ? int.MinValue : resList.ItemSortOrder)
So lets break it down!
[sql]from List in dataContext.Todo_Lists[/sql]
I want to get the Lists from the Todo_Lists table.
[sql]join Item in dataContext.Todo_List_Items on List.ListID equals Item.ListID into compList[/sql]
I want to join the Items/Task from Todo_List_Items table where the ListID column relationship matches. The two mashed tables goes into compList for complete list.
[sql]from resList in compList.DefaultIfEmpty()[/sql]
Then I select into resList for result list from comList with .DefaultEmpty(). DefaultEmpty() returns the default value if there isn’t an entry. That makes it possible to check for empty records later in the code.
[sql]where List.ListTrashed == false &amp;&amp; (resList.ItemTrashed == false || resList.ItemTrashed == null)[/sql]
Now comes the where. I only want the list that I haven’t sent to the trashcan. This is also true for the items but they can also return a null value. So if I only say resList.ItemTrashed == false I’m right back where I started with only getting the lists with items on them. But by adding || (or) resList.ItemTrashed == null I give the engine an option to match null as a suitable value for selection. That can only return an item that has null or false and I will not receive any that are trashed (resList.ItemTrashed == true). An other thing to note here is all the where options for table Todo_Lists is on the List object and all others are on the resList object. Don’t worry the intellisense will take care of you there.
[sql]orderby List.ListSortOrder ascending, resList.ItemSortOrder ascending[/sql]
Next I want to sort my result. Of course I want to prioritize my lists so I use sort order values to do so. This is really straight forward you don’t have to take into account the possible null values just tell how you want it sorted and it will all be good.
[sql]select new
ItemID = (resList.ItemID == null ? int.MinValue : resList.ItemID),
ItemSortOrder = (resList.ItemSortOrder == null ? int.MinValue : resList.ItemSortOrder)
Now it’s just the selection of the fields left. From List I want all the records returned that meets the where clause so I just select the fields I want. From the Items its a different story. ItemID can be null but that value can’t be returned so you have to substitute it with something else. It also has to be of the same cast as the original field. So if the ItemSortOrder field is null replace it with int.MinValue. That value is not part of the sort order and easy to match when I loop through the records to detect that the list doesn’t have any items. If the field isn’t null I want the value so I put in : resList.ItemSortOrder.

I have to credit msarchet and saus for getting me in the right direction. Without them I wouldn’t got this far. Thanks guys!

jQuery UI: Samples has redundant code

I have messed around a lot with .Net MVC, jQuery and jQuery UI for some time now. I just discovered that one of the examples includes redundant code. I don’t know if all of them do but you need to watch your self. I have seen a few sites that run the jQuery examples straight up and they may have problems with this. It’s really not that big of a deal but redundant code can become a comp ability issue and it’s always bad practice. You also send more data to each client and you waste bandwidth.

The example I found was the tabs control with the ability to add and remove tabs. This is the code they published:
#dialog label, #dialog input { display:block; }
#dialog label { margin-top: 0.5em; }
#dialog input, #dialog textarea { width: 95%; }
#tabs { margin-top: 1em; }
#tabs li .ui-icon-close { float: left; margin: 0.4em 0.2em 0 0; cursor: pointer; }
#add_tab { cursor: pointer; }
$(function() {
var $tab_title_input = $( "#tab_title"),
$tab_content_input = $( "#tab_content" );
var tab_counter = 2;

// tabs init with a custom tab template and an "add" callback filling in the content
var $tabs = $( "#tabs").tabs({
tabTemplate: "&lt;li&gt;&lt;a href=’#{href}’&gt;#{label}&lt;/a&gt; &lt;span class=’ui-icon ui-icon-close’&gt;Remove Tab&lt;/span&gt;&lt;/li&gt;",
add: function( event, ui ) {
var tab_content = $tab_content_input.val() || "Tab " + tab_counter + " content.";
$( ui.panel ).append( "&lt;p&gt;" + tab_content + "&lt;/p&gt;" );

// modal dialog init: custom buttons and a "close" callback reseting the form inside
var $dialog = $( "#dialog" ).dialog({
autoOpen: false,
modal: true,
buttons: {
Add: function() {
$( this ).dialog( "close" );
Cancel: function() {
$( this ).dialog( "close" );
open: function() {
close: function() {
$form[ 0 ].reset();

// addTab form: calls addTab function on submit and closes the dialog
var $form = $( "form", $dialog ).submit(function() {
$dialog.dialog( "close" );
return false;

// actual addTab function: adds new tab using the title input from the form above
function addTab() {
var tab_title = $tab_title_input.val() || "Tab " + tab_counter;
$tabs.tabs( "add", "#tabs-" + tab_counter, tab_title );

// addTab button: just opens the dialog
$( "#add_tab" )
.click(function() {
$dialog.dialog( "open" );

// close icon: removing the tab on click
// note: closable tabs gonna be an option in the future – see
$( "#tabs span.ui-icon-close" ).live( "click", function() {
var index = $( "li", $tabs ).index( $( this ).parent() );
$tabs.tabs( "remove", index );

<div id="dialog" title="Tab data">
<label for="tab_title">Title</label>
<input type="text" name="tab_title" id="tab_title" value="" />
<label for="tab_content">Content</label>
<textarea name="tab_content" id="tab_content"></textarea>

<button id="add_tab">Add Tab</button>

<div id="tabs">
<li><a href="#tabs-1">Nunc tincidunt</a> <span>Remove Tab</span></li>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>

</div><!– End demo –>
The problem is that the register the submit action for the form twice. This code initializes the model popup including the form. I have highlighted the peace of code thats interesting here.
[js] var $dialog = $( "#dialog" ).dialog({
autoOpen: false,
modal: true,
buttons: {
<span style="color: #ff0000;">Add: function() {
$( this ).dialog( "close" );
Cancel: function() {
$( this ).dialog( "close" );
open: function() {
close: function() {
$form[ 0 ].reset();
That peace of code does the exact same thing as this peace of code:

[js] var $form = $( "form", $dialog ).submit(function() {
$dialog.dialog( "close" );
return false;
The first one is a must to initialize the module popup, this is just redundant. I have played around a lot with this and I can’t find any impact in functionality. If you know any or find anything please give me a comment back, but I can’t see that there would be any issues. Then in the end I’m rather corrected and admitting that I’m wrong then running code that isn’t OK.