Tuesday, 24 August 2010

Wednesday, 18 August 2010

Setup Passive FTP on Windows 2003 and IIS6

Two key items need to be completed for this:

  1. Configure FTP to use a specific range of passive ports so only a short range need be allowed through Windows Firewall.
  2. Setup the passive FTP port range to work through Windows Firewall.

Configure FTP to use a restricted range of passive FTP ports

By default passive FTP under IIS 6 will use a port in the range 1024 – 65535.
When setting your own range of ports the range must be within 5001 – 65535.

Enable Direct Metabase Edit in IIS
1. Open the IIS Microsoft Management Console (MMC).
2. Right-click on the Local Computer node.
3. Select Properties.
4. Make sure the Enable Direct Metabase Edit checkbox is checked.

Configure PassivePortRange via ADSUTIL script
1. Click Start, click Run, type cmd, and then click OK.
2. Set the directory to Inetpub\AdminScripts. Depending on your system configuration this can either be achieved by entering cd Inetpub\AdminScripts and then pressing ENTER or cd C:\Inetpub\AdminScripts and pressing ENTER or locate the path for your system.
3. Type the following command and press ENTER (replace the range 5500-5700 with the port range you wish to use):  adsutil.vbs set /MSFTPSVC/PassivePortRange "5500-5700"
4. Restart the FTP service.

BEWARE the port range must be separated by a – and not a comma, must be enclosed by double quotes and must not overlap with a range in use by any other application. Failing to comply with any of these restrictions will mean the FTP service will not start, if you attempt to restart IIS none of the IIS services will start until you have resolved the issue. Should this happen go back to the command prompt mentioned above, browse to the AdminScripts folder, enter adsutil.vbs set /MSFTPSVC/PassivePortRange "5500-5700" and press ENTER, the FTP service will now start while you work out what went wrong.

Configure Windows Firewall

You will need to add your range of ports as exceptions in Windows Firewall.

1. Click Start, click Run, type cmd and then click OK.
2. Type in the following and hit ENTER (replace the port numbers with the range you are using): FOR /L %I IN (5500,1,5700) DO netsh firewall add portopening TCP %I "Passive FTP"%I
3. Each port will be added with an OK confirmation.

Final steps for firewall configuration:

1. Manually add an exception for TCP port 21.
2. Make sure that the FTP server option IS NOT ticked under Network Connection Settings in Windows Firewall, if it is then your passive FTP port range will be ignored – strange but true! The network connection settings can be found by opening Windows Firewall in Control Panel, select the Advanced tab, select each connection in turn, click Settings, ensure the box next to “FTP Server” is not ticked.

Thanks to John.Geek.NZ for the heads up on the last Windows Firewall gotcha.

Stop and start services from the command line

net stop <service name>
net start <service name>

A full list of the exact services is found in the registry under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services key

Tuesday, 20 July 2010

AJAX jQuery GET caching

It seems the HTTP specification allows anything in a GET request chain to cache the results of a request.  Internet Explorer has apparently been well known for this but now Firefox has started to exhibit the same behaviour.
If using jQuery ajax GET requests you need to do this to prevent it:
    $.ajaxSetup({cache: false});
In addition, to ensure the results are definitely not cached a random string can be added to the end of the request URL e.g.
    var randomNumber = Math.floor(Math.random() * 1000);
    var url = targetUrl + '?rnd=' + randomNumber;

Sunday, 20 June 2010

Convert Wordpress to Blogger format

Having tried out Wordpress on a cheap host the experience was just too slow so now moving back to Blogger. If for any reason you need to move from Wordpress to Blogger you will need to convert the XML export file.

For Small Blogs
Wordpress2Blogger web service provides a simple Wordpress to Blogger conversion. Login into your Wordpress blog then goto "Manage" or "Tools" tab and export your blog as an XML file.

Now upload the file to Wordpress2Blogger online service to make it Blogger compatible. Download the resultant file and import it into Blogger via the Blogger dashboard. Your Wordpress posts will be imported as drafts, from there you can check and publish then as necessary. This method works for export files up to 1Mb.

For Larger Blogs
Larger blogs require a different method. Take a look at the Google Blog Converter project. As pointed by Google OpenSource blog this new Open Source project provides the ability to easily move blog posts and comments from service to service. This initial release provides Python libraries and runnable scripts that convert between the export formats of Blogger, LiveJournal, MovableType, and WordPress.

Wednesday, 16 June 2010

SQL Server Backup Job Script

BACKUP DATABASE [{{DBName}}] TO  DISK = N'{{FullBackupPath}}' WITH  INIT ,  NOUNLOAD ,  NAME = N'{{DBName}} backup',  NOSKIP ,  STATS = 10,  NOFORMAT

Windows 7 Shortcut Keys

Windows + ↑ (Up Arrow) – Maximize window
Windows + ← (Left Arrow) – Snap window to left side covering half of desktop space. Continue pressing the keyboard shortcut will rotate the window between snap to left, snap to right and restore to normal position.
Windows + → (Right Arrow) – Snap window to right side covering half of desktop space. Continue pressing the keyboard shortcut will rotate the window between snap to left, snap to right and restore to normal position.
Windows + ↓ (Down Arrow) – Minimize the window. Restore to normal size and position if the window is currently maximized.
Windows + Home – Clear all but the active window.
Windows + Space – All windows become transparent so you can see through to the desktop.
Windows + Shift + ← (Left Arrow) – Move the active window to the adjacent monitor on the left for dual or multiple monitors setup.
Windows + Shift + → (Right Arrow) – Move the active window to the adjacent monitor on the right for dual or multiple monitors setup.
Windows + T – Show preview thumbnail of running applications in Windows Taskbar one by one without mouse over.
Windows + P – Adjust presentation options of the display on computer or projector.
Windows + + (Add) – Zoom in.
Windows + – (Minus or Dash) – Zoom out.
Shift + Click a Taskbar item: Open a new instance of that particular application.
Windows + D – Show desktop and restore desktop (minimize or restore all windows).
Windows + M – Minimize all windows.
Windows + U – Open Ease of Access Center.
Windows + F – Search window.
Windows + G – Bring all gadgets on top and foreground.
Windows + X – Run Windows Mobility Center.
Windows + R – Open ‘Run’ command.
Windows + E – Run Windows Explorer.
Windows + L – Lock the computer.
Windows + Pause [Break] – Open System Properties.
Windows + [number] – Activate and run the program pinned on Windows 7 Taskbar, running program won’t be affected.
Windows + Tab – Windows Aero Task Switcher
F1 – Help
F3 – Search

SQL Server 2005 Error When Creating SQL Agent Job

I am running SQL Server 2005 Workgroup Edition, I get the following error when creating a SQL Server Agent Job:
Unable to cast object of type 'Microsoft.SqlServer.Management.Smo.SimpleObjectKey' to type 'Microsoft.SqlServer.Management.Smo.Agent.JobObjectKey'. (Microsoft.SqlServer.Smo)
Not good!
The error can have a number of causes. Solutions include:
  1. Installing SQL Server 2005 SP2 (claimed by a number of individuals to work).
  2. If you are accessing the SQL Server across a network, logon to the server using remote desktop or similar and attempt to create the job locally.

Sunday, 13 June 2010

Access each character of a string

foreach (char ch in stringVar)
{
  Console.WriteLine(ch.ToString());
}




OR


String.ToCharArray()

Environment SpecialFolder directory paths

The Environment.SpecialFolder enumeration can be used to obtain the full path to system special folders.
The enumeration includes:
Supported by the XNA Framework
ApplicationData
Common repository for application-specific data for the current roaming user.
CommonApplicationData
Common repository for application-specific data that is used by all users.
LocalApplicationData
Common repository for application-specific data that is used by the current, non-roaming user.
Cookies
Common repository for Internet cookies.
Desktop
The logical Desktop rather than the physical file system location.
DesktopDirectory
The directory used to physically store file objects on the desktop.
Favorites
Common repository for the user's favourite items.
History
Common repository for Internet history items.
InternetCache
Temporary Internet files folder.
Supported by the XNA Framework
Programs
The directory that contains the user's program groups.
MyComputer
The My Computer folder.
n.b.
The MyComputer constant always yields the empty string ("") because no path is defined for the My Computer folder.
MyMusic
The My Music folder.
MyPictures
The My Pictures folder.
Recent
The directory that contains the user's most recently used documents.
SendTo
The directory that contains the Send To menu items.
Supported by the XNA Framework
StartMenu
The directory that contains the Start menu items.
Supported by the XNA Framework
Startup
The directory that corresponds to the user's Startup program group.
System
The System directory.
Templates
The directory that serves as a common repository for document templates.
Supported by the
 XNA Framework
Personal
The directory that serves as a common repository for documents.
This member is equivalent to MyDocuments.
MyDocuments
The My Documents folder.
This member is equivalent to Personal.
ProgramFiles
The program files directory.
CommonProgramFiles
The directory for components that are shared across applications.
AdminTools
The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.
CDBurning
The file system directory that acts as a staging area for files waiting to be written to a CD.
CommonAdminTools
The file system directory that contains administrative tools for all users of the computer.
CommonDocuments
The file system directory that contains documents that are common to all users. This special folder is valid for Windows NT systems, Windows 95, and Windows 98 systems with Shfolder.dll installed.
CommonMusic
The file system directory that serves as a repository for music files common to all users.
CommonOemLinks
This value is recognized in Windows Vista for backward compatibility, but the special folder itself is no longer used.
CommonPictures
The file system directory that serves as a repository for image files common to all users.
CommonStartMenu
The file system directory that contains the programs and folders that appear on the Start menu for all users. This special folder is valid only for Windows NT systems.
CommonPrograms
A folder for components that are shared across applications. This special folder is valid only for Windows NT, Windows 2000, and Windows XP systems.
CommonStartup
The file system directory that contains the programs that appear in the Startup folder for all users. This special folder is valid only for Windows NT systems.
CommonDesktopDirectory
The file system directory that contains files and folders that appear on the desktop for all users. This special folder is valid only for Windows NT systems.
CommonTemplates
The file system directory that contains the templates that are available to all users. This special folder is valid only for Windows NT systems.
CommonVideos
The file system directory that serves as a repository for video files common to all users.
Fonts
A virtual folder that contains fonts.
MyVideos
The file system directory that serves as a repository for videos that belong to a user.
NetworkShortcuts
A file system directory that contains the link objects that may exist in the My Network Places virtual folder.
PrinterShortcuts
The file system directory that contains the link objects that can exist in the Printers virtual folder.
UserProfile
The user's profile folder. Applications should not create files or folders at this level; they should put their data under the locations referred to by ApplicationData.
CommonProgramFilesX86
The Program Files folder.
ProgramFilesX86
The Program Files folder.
Resources
The file system directory that contains resource data.
LocalizedResources
The file system directory that contains localized resource data.
SystemX86
The Windows System folder.
Windows
The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables.
Full Microsoft resource: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

Saturday, 12 June 2010

HTC Phone Comparison

I currently have an HTC Touch Diamond and have been looking at changing to an Android phone. A quick comparison of the main options of HTC Desire, HTC Legend and HTC Wildfire.
Touch Diamond Desire Legend Wildfire
CPU Speed 528 MHz 1 GHz 600 MHz 528 MHz
CPU Type Qualcomm® MSM7201A Snapdragon Qualcomm MSM7227 Qualcomm MSM7225
Width 51 mm 60 mm 56.3 mm 60.4 mm
Height 102 mm 119 mm 112 mm 106.75 mm
Depth 11.35 mm 11.9 mm 11.5 mm 12.9 mm
OS Windows 6.1 Android 2.1 Android 2.1 Android 2.1
Control TouchFLO 3D HTC Sense HTC Sense HTC Sense
ROM 256 Mb 512 Mb 512 Mb 512 Mb
RAM 192 Mb 576Mb 384 Mb 384 Mb
Internal Storage 4Gb
Additional Storage Micro SD up to 32 Gb Micro SD up to 32 Gb Micro SD up to 32 Gb
Weight 110 g 135 g 126 g 118 g
Display 2.8 in TFT-LCD VGA 3.7 in AMOLED WVGA 3.2 in AMOLED HVGA 3.2 in QVGA
Network Tri-band Quad-band Quad-band Quad-band
GPS GPS & GPS-A GPS GPS GPS
Bluetooth 2.0 with EDR 2.1 with EDR 2.1 with EDR 2.1 with EDR
Wi-Fi IEEE 802.11 b/g IEEE 802.11 b/g IEEE 802.11 b/g IEEE 802.11 b/g
3G 7.2 Mbps 7.2 Mbps 7.2 Mbps
GPRS 114 Kbps 114 Kbps 114 Kbps
EDGE 560 Kbps 560 Kbps 560 Kbps
Connector HTC ExtUSB Micro-USB Micro-USB Micro-USB
Connector jack 3.5 mm stereo jack 3.5 mm stereo jack 3.5 mm stereo jack
G-sensor Yes Yes Yes
Digital compass Yes Yes Yes
Proximity sensor Yes Yes Yes
Ambient light sensor Yes Yes Yes
Camera 1 3.2 mega pixel 5 mega pixel 5 mega pixel 5 mega pixel
Camera 2 VGA CMOS
Flash Yes Yes Yes
Geotagging Yes Yes Yes
Mic Built in
Radio FM with RDS FM FM FM
Audio formats MP3, AAC, AAC+, WMA, WAV, and AMR-NB .aac, .amr, .ogg, .m4a, .mid, .mp3, .wav, .wma .aac, .amr, .ogg, .m4a, .mid, .mp3, .wav, .wma .aac, .amr, .ogg, .m4a, .mid, .mp3, .wav, .wma
Video formats .3gp, .3g2, .mp4, .wmv .3gp, .3g2, .mp4, .wmv .3gp, .3g2, .mp4, .wmv
Battery Li-Ion 900 MAh Li-Ion 1400 MAh Li-Ion 1300 MAh Li-Icon 1300 MAh
Talk time 270 min WCDMA

330 min GSM
390 min WCDMA

400 min GSM
440 min WCDMA

490 min GSM
440 min WCDMA

490 min GSM
Standy time 396 hrs WCDMA

285 hrs GSM
360 hrs WCDMA

340 hrs GSM
560 hrs WCDMA

440 hrs GSM
690 hrs WCDMA

480 hrs GSM

Thursday, 10 June 2010

Orange Mobile Contract Renewal - Beware

For any existing Orange customers hoping to obtain a competitive renewal on their Orange contract, beware!
A number of phone companies commit to providing the same deals to their existing as they use to lock in new customers. Some, T-Mobile for one, even claim to offer better deals to their existing customers.
Orange used to be fair handed on contract renewals and would assess past usage, upgrade phones and commitment to future usage on a new contract. This is no longer the case. Their policy is now to base all new deals (both contract and phone) on the past usage, regardless of the new contract value. In addition to this certain phones are flagged so Orange reps are unable to offer competitive deals to existing customers – this applies to the most popular handsets.
For a new customer it is possible to obtain an HTC Desire from almost any network for free on a £30 a month contract, this includes Orange on the rare occasions they have any in stock. My mobile usage is average but not heavy but will increase some what in the coming months with a high demand for data. Based on my past usage an HTC Desire would be £150 when obtained at the same as a contract renewal, this is the case even if I chose to renew with the most expensive £80 a month Panther deal!
I am sure Orange couldn’t care less that one customer is about to leave for another network but I can’t be alone in being screwed by their latest policies. Maybe when enough customers have left for other networks they will have to adjust their terms more in favour of the loyal customer who has stuck with them through good times and bad, mostly bad…

Wednesday, 2 June 2010

Apple iPhone and iPod WebClip icons

The iPhone and iPod Touch devices allow a user to save a WebClip bookmark to a site on their Home Screen.
To specify a bookmark icon for all pages of a web site, place a PNG image named "apple-touch-icon.png" in the root directory of your web site - similar to the "favicon.ico" for site icons.
To override the site bookmark icon on a specific web page, insert a <link> element similar to <link rel="apple-touch-icon" href="/customIcon.png"/> within the <head> element of the page.
The bookmark icon dimensions should be 57x57 pixels. If the icon is a different size it will be scaled and cropped to fit.
appleeg
Safari will automatically composite the icon with the standard "glassy" overlay so it looks like a built-in iPhone or iPod application.

Friday, 21 May 2010

Programmatically grant user privileges

When installing services, in particular SQL Server, it is a frequent requirement to create a service user and assign certain rights. To assist users during installation it is helpful to gather the required information (e.g. username + password) amd programmatically create the user for them. To achieve this you will need to create the user, assign it to the appropriate groups and grant any specific rights. Granting privileges and impersonation is covered in Corinna John's CodeProject article: http://www.codeproject.com/KB/cs/lsadotnet.aspx
How to add a user to the local system using C#: http://support.microsoft.com/kb/306273
How to add a user to the domain using C#: http://en.csharp-online.net/User_Management_with_Active_Directory%E2%80%94Creating_Users

Compress and de-compress strings in C#

A collection of resources on compressing and encrypting strings in C#.
Microsoft documentation on the System.IO.Compression.GZipStream class:
http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx
Helpful example class utilising GZip:
http://www.csharphelp.com/2007/09/compress-and-decompress-strings-in-c/
The GZipStream class is predominantly used for file compression but can be used efficiently for compressing strings of 300-400 characters or more. Below 300 characters there isn’t any measurable gain from the compression and for particularly short strings the compressed version may in fact be larger.
Class provided by C Sharp Help:
using System.IO.Compression;
using System.Text;
using System.IO;

public static string Compress(string text)
{
    byte[] buffer = Encoding.UTF8.GetBytes(text);
    MemoryStream ms = new MemoryStream();
    using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
    {
        zip.Write(buffer, 0, buffer.Length);
    }

    ms.Position = 0;
    MemoryStream outStream = new MemoryStream();

    byte[] compressed = new byte[ms.Length];
    ms.Read(compressed, 0, compressed.Length);

    byte[] gzBuffer = new byte[compressed.Length + 4];
    System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
    System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
    return Convert.ToBase64String (gzBuffer);
}

public static string Decompress(string compressedText)
{
    byte[] gzBuffer = Convert.FromBase64String(compressedText);
    using (MemoryStream ms = new MemoryStream())
    {
        int msgLength = BitConverter.ToInt32(gzBuffer, 0);
        ms.Write(gzBuffer, 4, gzBuffer.Length – 4);

        byte[] buffer = new byte[msgLength];
        ms.Position = 0;
        using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))
        {
            zip.Read(buffer, 0, buffer.Length);
        }

        return Encoding.UTF8.GetString(buffer);
    }
}

Friday, 7 May 2010

Drop Default Constraint

The basic syntax for dropping a constraint is quite simple:
ALTER TABLE {{MYTABLENAME}} DROP CONSTRAINT {{CONSTRAINTNAME}}
The problem comes if you have created unnamed constraints as SQL will have assigned a random name. You need to discover the constraint name before you can drop it.
To discover the constraint name:
SELECT name FROM sysobjects so JOIN sysconstraints sc ON so.id = sc.constid WHERE object_name(so.parent_obj) = '{{MYTABLENAME}}' AND so.xtype = 'D' AND sc.colid = (SELECT colid FROM syscolumns WHERE id = object_id('dbo.{{MYTABLENAME}}') AND name = '{{COLUMNNAME}}')
To discover and drop the constraint:
DECLARE @defname VARCHAR(100), @cmd VARCHAR(1000);
SET @defname = (SELECT name FROM sysobjects so JOIN sysconstraints sc ON so.id = sc.constid WHERE object_name(so.parent_obj) = '{{MYTABLENAME}}' AND so.xtype = 'D' AND sc.colid = (SELECT colid FROM syscolumns WHERE id = object_id('dbo.{{MYTABLENAME}}') AND name = '{{COLUMNNAME}}'));
SET @cmd = 'ALTER TABLE {{MYTABLENAME}} DROP CONSTRAINT ' + @defname;
EXEC(@cmd);
GO
alter table {{MYTABLENAME}} drop column {{COLUMNNAME}}
GO

Thursday, 15 April 2010

Modify local security policy to grant service rights

Specific rights must be granted to user accounts to allow the account to be used to run as a service. There are a number of possible methods.
Method 1: Grant rights using Group Policy
This can be achieved using group policy: http://support.microsoft.com/kb/256345/
Method 2: Grant rights using Security templates
Similar to method 1 but using Security templates to change the permissions on system services.
   1. Click Start, click Run, and then type MMC.
   2. On the Console menu, click Add/Remove Snap-in.
   3. Click Add.
   4. Select the Security Configuration and Analysis snap-in, and then click Add.
   5. Click Close, and then click OK.
   6. In the MMC, right-click the Security Configuration and Analysis item, and then click Open Database.
   7. Give a name for the database, and then browse to where you would like to store it.
   8. When prompted, select a Security Template to import. For example, the "basicwk.inf" contains values for the standard settings found on a Windows 2000 Professional computer.
   9. In the MMC, right-click the Security Configuration and Analysis item, and then click the Analyze Computer now option. Choose a location for the log file, when prompted.
  10. After analysis is complete, configure the service permissions as follows:
         1. Double-click the System Services branch in the MMC.
         2. Right-click the service that you want to change, and then click Security.
         3. Click Edit Security.
         4. Add user accounts as required, and configure the permissions for each account. By default, the user will be granted "Start, stop and pause" permissions.
  11. To apply the new settings to the local computer, simply right-click the Security Configuration and Analysis item, and then click the Configure Computer Now option.
Method 3: Grant rights using Subinacl.exe
The final method for assigning rights to manage services is to use the Subinacl.exe utility from the Windows 2000 Resource Kit. The syntax for this is:
SUBINACL /SERVICE \\MachineName\ServiceName /GRANT=[DomainName\]UserName[=Access]
Full details from Microsoft:
http://support.microsoft.com/?kbid=288129

Wednesday, 14 April 2010

SQL 2005/2008 Ad hoc access to OLE DB provider has been denied

I have a previous post on enabling adhoc access for SQL 2000 (http://blog.bansheetechnologies.co.uk/2009/02/ad-hoc-access-to-ole-db-provider-has.html), SQL 2005 and 2008 are a little different.
SQL 2005/2008 returns the following:
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
To enable OpenRowset and OpenDatasource:
  • Launch the "SQL Server 2005 Surface Area Configuration" tool.
  • Click "Surface Area Configuration for Features"
  • Select "Server Name > Database Engine > Ad Hox Remote Queries"
  • Tick "Enable OPENROWSET and OPENDATASOURCE" support.
  • Click OK

After completing the above steps you might see the following error when you run the query again:

Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server.

To resolve this:

  • Open regedit
  • Expand "HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL.1\Providers" – depending on how many instances you have installed you may have MSSQL.1, MSSQL.2 etc – the instance name is shown as the (Default) value under each branch – check this to ensure you are editing the settings for the correct instance.
  • If it isn't already present add a new DWord setting under MSDASQL with a name of DisallowAdhocAccess and value of 0.

Monday, 8 March 2010

Free Port Scanner

Concerned about open ports and security problems.
You can make a start with the free port scanner provided by Security Metrics.
They offer two flavours of scan, either home or business.
Home
  • Quick Port Scan of 22 ports
  • Immediate results
  • Security recommendations available via email

Business
  • For Webmasters, Network Administrators, and Executives - test up to three  servers.
  • Comprehensive
    - Port Scan - 65,535 TCP ports & many UDP ports
    - Thousands of Vulnerability Assessment tests
    - Mail Proxy test for open relays
    - Test for hundreds of default username/passwords
    - Website html spidering for XSS & other leaks
  • Email notification when the tests are completed
  • Upon authentication you will receive complete vulnerability assessment results

Wednesday, 3 March 2010

C# Get User Desktop Path

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
See full post on the SpecialFolder enumeration.

Thursday, 25 February 2010

jQuery Lightbox Scripts

jQuery Lightbox Plugin
image
jQuery lightBox plugin is simple, elegant, unobtrusive, no need extra markup and is used to overlay images on the current page through the power and flexibility of jQuery´s selector.
lightBox is a plugin for jQuery. It was inspired in Lightbox JS by Lokesh Dhakar.
Supports: images.
Main site: http://leandrovieira.com/projects/jquery/lightbox/
Fancybox
image
FancyBox is a tool for displaying images, html content and multi-media in a Mac-style "lightbox" that floats overtop of web page.
It was built using the jQuery library. Licensed under both MIT and GPL licenses
Supports: images, HTML, iFrame content
Main site: http://fancybox.net/
Shadowbox
image
Shadowbox is a web-based media viewer application that supports all of the web's most popular media publishing formats. Shadowbox is written entirely in JavaScript and CSS and is highly customizable. Using Shadowbox, website authors can showcase a wide assortment of media in all major browsers without navigating users away from the linking page.
Supports: images, Flash, Quicktime, Windows Media Player, HTML
Main site: http://www.shadowbox-js.com/index.html
ThickBox
image
ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.
Supports: images, gallery images, inline content, iFramed content, AJAX content
Main site: http://jquery.com/demo/thickbox/
Fancy Zoom (jQuery)
image 
This works with any html (images, text, headings, flash). The only caveat is it doesn't currently work with AJAX. Whatever you want to zoom to must be html already on the page.
Supports: images, inline content, text
Main site: http://static.railstips.org/orderedlist/demos/fancy-zoom-jquery/
Facebox
image
Facebox is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote pages.
It's simple to use and easy on the eyes. Download the tarball, view the examples, then start enjoying the curves.
Supports: images, DIVs, iFrame content
Main site: http://famspam.com/facebox
nyroModal
image
Designers seem to like using modal windows more and more, as they provide a quick way to show data without reloading the entire page. It's easy to use and easy to design.
The big problem I experienced with every plugin I tried either using Prototype/Scriptaculous or jQuery is the customization. They say you can do whatever you want simply but that's not fully true. The default CSS works fine, but most of time it's a mix between required elements and optional. That mean you have to be very careful when editing it.
The other problem is the animation. That's the worst point. I never found one plugin allowing to redefine easily the animations.
I tried to solve these problems with my plugin. I documented everything possible. The default CSS contains only optional rules. Without it, the plugin will works perfectly —but will also looks very sad. Regarding the animations, you can simply redefine them from A to Z. Thanks to the useful jQuery function like animate, fadeTo or the future enchant, it's pretty simple.
Moreover, I added the ability to define many callbacks at different time in the process to allow you to edit the settings, the data or do whatever you need.
Supports: images, inline HTML, iFrame, AJAX, video
Main site: http://nyromodal.nyrodev.com/
Interface Imagebox Demo
image
Supports: images.
Main site: http://www.intelliance.fr/jquery/imagebox/
Pirobox
image Supports: images
Main site: http://www.pirolab.it/pirobox/
prettyPhoto
image
prettyPhoto is a jQuery based lightbox clone. Not only does it support images, it also add support for videos, flash, YouTube, iFrames. It’s a full blown media lightbox. The setup is easy and quick, plus the script is compatible in every major browser.
It comes with useful APIs so prettyPhoto can be launched from nearly anywhere (yes, that includes Flash)!
Supports: images
Main site: http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

Monday, 22 February 2010

Windows 7 Disable UAC

Particularly when using a PC for development purposes the inbuilt user account control (UAC) can be a pain. The following steps will disable UAC completely, the same process can be used to reduce the level of UAC on the system.
  • Choose "Start"
  • Enter "Action Center" in the search box
  • Press Enter
  • Click "Change User Access Control settings"
  • Move the slide to "Never notify"
  • Click OK
  • Restart the PC

Enable IIS in Windows Vista

In Windows Vista and above all of the available features are installed by default but aren’t necessarily enabled. By default IIS is disabled in Windows Vista, the following steps will allow you to enable the feature.
  1. Open Control Panel
  2. Click "Programs"
  3. Click "Turn Windows Features on or off"
  4. Expand "Internet Information Services"
  5. Expand "Web Management Tools"
  6. Tick "IIS Management Console"
  7. Expand "World Wide Web Services"
  8. Expand "Application Development Features" and tick ".NET Extensibility" and ASP.NET
  9. Expand "Common Http Features" and tick "Default Document", "HTTP Errors" and "Static Content"
  10. Expand "Health and Diagnostics" and tick "HTTP Logging" and "Request Monitor"
  11. Expand "Security" and tick "Basic Authentication", "IP Security", "Request Filtering" and "Windows Authentication"
  12. Click OK

Friday, 19 February 2010

Exception Types

SystemException
A failed run-time check;used as a base class for other.
AccessException
Failure to access a type member, such as a method or field.
ArgumentException
An argument to a method was invalid.
ArgumentNullException
A null argument was passed to a method that doesn't accept it.
ArgumentOutOfRangeException
Argument value is out of range.
ArithmeticException
Arithmetic over - or underflow has occurred.
ArrayTypeMismatchException
Attempt to store the wrong type of object in an array.
BadImageFormatException
Image is in the wrong format.
CoreException
Base class for exceptions thrown by the runtime.
DivideByZeroException
An attempt was made to divide by zero.
FormatException
The format of an argument is wrong.
IndexOutOfRangeException
An array index is out of bounds.
InvalidCastExpression
An attempt was made to cast to an invalid class.
InvalidOperationException
A method was called at an invalid time.
MissingMemberException
An invalid version of a DLL was accessed.
NotFiniteNumberException
A number is not valid.
NotSupportedException
Indicates sthat a method is not implemented by a class.
NullReferenceException
Attempt to use an unassigned reference.
OutOfMemoryException
Not enough memory to continue execution.
StackOverflowException
A stack has overflown.

Tuesday, 16 February 2010

Recover a stolen laptop or device with Prey

Very handy open source utility for remotely monitoring your laptop/device in the hope of capturing details of the miscreant!
http://preyproject.com/
Prey helps you locate your missing laptop by sending timed reports with a bunch of information of its whereabouts. This includes the general status of the computer, a list of running programs and active connections, fully-detailed network and wifi information, a screenshot of the running desktop and — in case your laptop has an integrated webcam — a picture of the thief.

Friday, 5 February 2010

VS Bootstrapper package locations

Between VS 2005 and VS 2008 the bootstrapper locations changed.
Visual studio 2005:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages
Visual studio 2008:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

Hide form title bar

To hide a form title bar without making the form borderless:
1. Set the form ControlBox property to false.
2. Set the form Text property to string.empty

Microsoft Leaks Office 2010 Upgrade Plan

Originally posted to the Microsoft partner site and then hastily removed Microsoft have revealed the specifics of their upgrade plans for purchasers of Office 2007 to be able to update to 2010 when it is released.

Original page.

Google cached version.

Original text:

Microsoft Office 2010 Technology Guarantee Program


Sell Office 2007 today and your customer can download Office 2010 free!
How the program works:


Purchase Office 2007—Customer buys qualifying Office 2007 product (with or without a new PC) from an authorized reseller between March 5 – September 30, 2010.

Install and Activate Office 2007—Customer installs and activates Office 2007 by September 30, 2010.

Download Office 2010—Customer simply downloads Office 2010 for free when Office 2010 is available, or orders a DVD for a fee. Customer must request upgrade by October 31, 2010.

Below are some of the Office 2007 products your customer can purchase and activate between March 5 and September 30, 2010 to be eligible for the Office 2010 upgrade.

clip_image001
Office 2010 downloads will be accessible at general availability. Discs can be ordered for a fee. Eligible Office 2007 software must be purchased from Microsoft or an authorized reseller and activated between March 5, 2010 and September 30, 2010. Request your Office 2010 product by October 31, 2010 using your activated Office 2007 Product Key and dated sales receipt. One Office 2010 product per qualifying Office 2007 purchase, limit twenty-five per person.

Wednesday, 3 February 2010

Connect Coldfusion to SQL Server Express

Having recently installed SQL Server Express 2005 on a client server running CFMX 7 I have had to work through the torture of attempting to make the existing SQL Server database driver and then realising it will not work with anything higher than SQL 2000!

The instructions below are based on FusionCube but have been modified for my needs.

These instructions assume you have already install SQL Server Express and Management Studio Express.

Prepare the database server
  1. Open the SQL Server Management Studio
  2. Click on the Registered Servers button in the toolbar
  3. Right-click the SQL Express server.
  4. Select “SQL Server Configuration Manager”
  5. If needed, enable the TCP/IP protocol under SQL Server Configuration Manager > SQL Server 2005 Network Configurations > Protocols for SQLEXPRESS
  6. Double-click the TCP/IP protocol to view the properties.
  7. Click on the IP Addresses tab and make sure that the TCP Port is set to 1433 for every IP type.
  8. Close the configuration manager.
  9. Right-click the SQL Express server in SQL Management Studio, select Properties.
  10. Go to the Security item and make sure that you have Mixed Mode enabled. Save the settings.
  11. Restart he SQL Server instance.
  12. Once the server restarts, create a new login to be used by ColdFusion, give it a SQL Server Authentication password, and set the default database to the one you’re setting up.

Setup the ColdFusion datasource. At this point you have a choice of the Microsoft JDBC driver or the very popular open source JDBC 3.0 drive jTDS. I have included the instructions for the Microsoft driver first, the jTDS instructions are further down the page.
  1. Download the Microsoft SQL Server 2005 JDBC Driver
  2. Install the JDBC drive as described on the Microsoft page.
  3. Locate the sqljdbc.jar file in the JDBC driver install folder. Copy the .jar file to WEB-INF\cfusion\lib directory, or wherever your cfusion\lib directory is located.
  4. Restart ColdFusion Application Server otherwise it will not pick up the new driver.
  5. Log in to your ColdFusion Administrator.
  6. Create a new datasource, set a name and make the datasource type ‘other’.
  7. Fill in the fields with the following properties
    JDBC URL: jdbc:sqlserver://{server name}\sqlexpress:1433;DatabaseName={database name}
    Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Driver Name: SQL Server 2005 JDBC
  8. Enter the username and password you created in step 12 of the database instructions above.
  9. Save the new datasource and check it verifies.

The jTDS driver:
  1. Download the jTDS Driver
  2. Extract the contents of the ZIP.
  3. Locate the jtds-1.2.5.jar file in the JDBC driver install folder. Copy the .jar file to WEB-INF\cfusion\lib directory, or wherever your cfusion\lib directory is located.
  4. Restart ColdFusion Application Server otherwise it will not pick up the new driver.
  5. Log in to your ColdFusion Administrator.
  6. Create a new datasource, set a name and make the datasource type ‘other’.
  7. Fill in the fields with the following properties
    JDBC URL: jdbc:jtds:sqlserver://{server name}/{database name}:1433;useLOBs=false;instance={instance name};
    Driver Class: net.sourceforge.jtds.jdbc.Driver
    Driver Name: jtds-1.2.jar
  8. Enter the username and password you created in step 12 of the database instructions above.
  9. Save the new datasource and check it verifies.

The useLOBs parameter shown above can be used to improve performance and stop the driver converting text and ntext fields to CLOB, thanks to the original post here.

Thursday, 28 January 2010

Good quality icon packs for web and Windows development

Thanks to a helpful post from:

http://www.queness.com/post/320/22-beautiful-icon-packs-for-web-design-and-development
  • Circular Icons

  • bwpx.icns

  • Gallery 2 Icons

  • KDE Icons

  • Credit Card Icons

  • Fugue Icons

  • Diagonal Icons

  • Danish Icons

  • LED Pixel Icons

  • Flag Icons

  • Mini Icons

  • Onebit Icons

  • WYSIWYG Sapphire Icons

  • Watercolor Icon Pack

  • Sweetie Basepack Icons

  • Sweetie WebCommunication Icons

  • Brand Spanking New Mini Icons

  • TwoTones Icons

  • Twotiny Icon Set

  • Splashy Fish Icons

  • Web Injection Icons

  • Mania Icons
  • Add comments to any website page

    Handy universal comments system with simple integration:
    http://disqus.com/
    Disqus (dis·cuss • dĭ-skŭs') is all about changing the way people think about discussion on the web. We're big believers in the conversations and communities that form on blogs and other sites.

    Take website screenshot using ASP.NET

    Utilising a hidden web browser control it is possible to take a screenshot of any website. The code shown below is based on an article at plentyofcode.com (sorry the site now appears to be offline May 2012) but I have translated it from VB.NET to C# and will work in .NET so theoretically for any Windows or ASP.NET web project.
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    namespace WebsiteScreenshot
    {
        public class GetImage
        {
            private int s_Height; private int s_Width; private int f_Height; private int f_Width; private string myURL;
    
            public int ScreenHeight { get { return s_Height; } set { s_Height = value; } }
            public int ScreenWidth { get { return s_Width; } set { s_Width = value; } }
            public int ImageWidth { get { return f_Width; } set { f_Width = value; } }
            public int ImageHeight { get { return f_Height; } set { f_Height = value; } }
            public string Website { get { return myURL; } set { myURL = value; } }
    
            public GetImage(string website, int screenWidth, int screenHeight, int imageWidth, int imageHeight)
            {
                myURL = website; 
                s_Width = screenHeight; 
                s_Height = screenHeight; 
                f_Height = imageHeight; 
                f_Width = imageWidth;
            }
    
            public Bitmap GetBitmap()
            {
                WebPageBitmap shot = new WebPageBitmap(this.Website, this.ScreenWidth, this.ScreenHeight); shot.GetIt();
                Bitmap pic = shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
                return pic;
            }
        }
    
        class WebPageBitmap
        {
            WebBrowser myBrowser; string url; int height; int width;
    
            public WebPageBitmap(string url, int width, int height)
            {
                this.height = height; this.width = width; this.url = url;
                myBrowser = new WebBrowser(); myBrowser.ScrollBarsEnabled = false; myBrowser.Size = new Size(this.width, this.height);
            }
    
            public void GetIt()
            {
                myBrowser.Navigate(this.url);
                while (myBrowser.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                }
            }
    
            public Bitmap DrawBitmap(int theight, int twidth)
            {
                Bitmap myBitmap = new Bitmap(width, height); Rectangle drawRect = new Rectangle(0, 0, width, height);
    
                myBrowser.DrawToBitmap(myBitmap, drawRect);
    
                Image imgOutput = myBitmap; Image oThumbnail = new Bitmap(twidth, theight, imgOutput.PixelFormat); Graphics g = Graphics.FromImage(oThumbnail); g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
    
                Rectangle oRectangle = new Rectangle(0, 0, twidth, theight); g.DrawImage(imgOutput, oRectangle);
    
                try 
                { 
                    return new Bitmap(oThumbnail); 
                }
                catch (Exception ex) 
                { 
                    return null; 
                }
                finally 
                { 
                    imgOutput.Dispose(); 
                    imgOutput = null; 
                    myBrowser.Dispose(); 
                    myBrowser = null; 
                }
            }
        }
    }
    

    Wednesday, 27 January 2010

    iPad is finally confirmed

    Apple’s new all singing all dancing device has been announced!

    See the live feed here: http://live.gdgt.com/2010/01/27/live-apple-come-see-our-latest-creation-tablet-event-coverage/

    Here’s what the Apple iPad looks like.

    Image courtesy of GdGt.com

    Friday, 15 January 2010

    Capture screenshot in C#

     

    A helpful article here from Geekpedia.

    This is fine for taking a standard screenshot from a Windows desktop. As an alternative solution I have a project here for taking a screenshot of a website using any .NET environment.