Thursday, December 8, 2005

Windows Tablet as a portable gaming device?

I reckon Microsoft is missing a trick here. They should, in my opinion, push Windows Tablet Edition as a portable gaming platform rather than the lacklustre Windows CE. The larger form factor is much more conducive to immersive gaming and the Windows platform easier to port existing games across than the crippled CE platform.

Thursday, October 27, 2005

VBScript to set all local users' passwords to non-expire

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
Wscript.Echo objUser.Name objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag

Sunday, October 23, 2005

Set AD user password to non-expiry

using System.DirectoryServices;using ActiveDs;
//Add reference to COM Active DS TypeLib

static void DontExpirePassword(DirectoryEntry User)
int val;
const int ADS_UF_DONT_EXPIRE_PASSWD =0x10000;
val = (int) User.Properties["userAccountControl"].Value;
User.Properties["userAccountControl"].Value = val ADS_UF_DONT_EXPIRE_PASSWD;

Wednesday, September 28, 2005

Shutting down remote PCs

Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys
Dim sUser, sPassword
'set remote credentials
sUser = "Administrator"sPassword = "password"
'open list of client names
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile("C:\clients.txt")
Do Until oTS.AtEndOfStream
'get next client name
sClient = oTS.ReadLine
'get WMI locator
Set oLocator = CreateObject("WbemScripting.SWbemLocator")
'Connect to remote WMI
Set oConnection = oLocator.ConnectServer(sClient, "root\cimv2", sUser, sPassword)
'issue shutdown to OS ' 4 = force logoff ' 5 = force shutdown ' 6 = force rebooot ' 12 = force power off
Set oWindows = oConnection.ExecQuery("Select " & "Name From Win32_OperatingSystem")
For Each oSys In oWindows
'close the text fileoTS.CloseWScript.Echo "All done!"

You should know a couple of things about this script. First, you need to have a text file named C:\Clients.txt on the machine where the script runs. That file should contain the list of client names you want to shut down. Instead of using a text file, you can modify this script to use ADSI, enabling it to query computer names from Active Directory or an NT domain. However, as you probably don’t want to run this script against every computer on your network (shutting down all of your servers might be bad), the text file provides you with complete control over which computers the script will affect.

Wednesday, August 24, 2005

Setting a User Account Expiration

Type type = usr.NativeObject.GetType();
Object adsNative = usr.NativeObject;
type.InvokeMember("AccountExpirationDate", BindingFlags.SetProperty, null, adsNative, new object[]{"21/01/2006"});

Tuesday, August 16, 2005

Getting PHP to work with MySQL on IIS/W2k3

Make sure that the PHP directory is in the System PATH variable. Only version 5.1.5 works with 64bit W2K3.

Monday, July 25, 2005

Getting a .Net Compact Framework Form to cover full screen

The form must not have a menu or a control box. Set the WindowState to Maximized in the form load event. That's it.

Wednesday, July 13, 2005

Getting PHP MySQL to work on Fedora Core 3

The Php MySQl module is not installed by default on Fedora Core 3. Install the following RPM:

Importing GPG public keys on Fedora Core 3

# rpm --import /usr/share/doc/fedora-release-3/RPM-GPG-KEY*

Wednesday, June 8, 2005

VBScript to delete all files older than 2 months

const fldname = "c:\test"
set fso = createobject("scripting.filesystemobject")
set fldr = fso.getfolder(fldname)
set dttoday = date
set dt2monthsago = dateadd("m", -2, dttoday)

recurse fldr

sub recurse( byref fldr)
dim subfolders,files,folder,file
set subfolders = fldr.subfolders
set files = fldr.files
wscript.echo fldr.path

for each file in files
if file.datelastmodified < dt2monthsago then
wscript.echo "Deleting " & & " last modified: " & file.datelastmodified
on error resume next
end if

for each folder in subfolders
recurse folder
set subfolders = nothing
set files = nothing
end sub

Sunday, June 5, 2005

Getting PHP to work on IIS6 on Win2K3

Copy c:\php\php.ini-distrib to c:\windows\php.ini
In IIS, under 'Home Directory', click on the 'Configuration', 'Application Mappings' tab.
Click 'Add' and enter C:\php\php5isapi.dll for .php extensionGo back to IIS.
Add and allow the PHP ISAPI Extension to IIS Web Service Extensions: C:\PHP\php5isapi.dll Open IIS Manager
Click on "Web Service Extensions"
Add a new Web service extension...Enter "PHP ISAPI Extension" as the "Extension name" Click the "Add..." button and browse to the php5isapi.dll file in your PHP install directory Check the "Set extension status to Allowed" checkbox and click "OK"

Wednesday, June 1, 2005

Getting the virtual URL of a SharePoint web app script

Request.Url doesn't give you what it says on the browser Url box. You need to use the following:

string scriptUrl = Request.ServerVariables["HTTP_VTI_SCRIPT_NAME"];

Tuesday, May 31, 2005

Test for AlphaNumeric in C#

public bool IsAlphaNumeric(String str){
Regex regexAlphaNum=new Regex("[^a-zA-Z0-9]");
return !regexAlphaNum.IsMatch(str);

Friday, May 27, 2005

To create a Sharepoint web app with Visual Studio.Net

Map a drive (S:) to the sharepoint server at "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS".
Create a new project at http://sharepointserver/_layouts/WebAPP.
Visual Studio will fail. Change the path to S:\WebApp and retry.
Visual STudio will complain about permission problems and the need to create an application at the server. Just click okay all the way through.
Go to the sharepoint server. Start the IIS management applet, and browse to the WebApp folder just created. Right-click and select properties. Create an application. Select the Sharepoint application pool.
Restart IIS using iisreset.
Go back to Visual Studio and add reference to Microsoft.SharePoint.dll.
Within each code file, add the following:

using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.Utilities;

Wednesday, May 25, 2005

T-Mobile GPRS UK Settings

Session Type Continuous/Permanent
Security Off
Gateway Address
Authentication Normal
Access Point Name
Port number 9201
Mail server (SMTP)
Username user
Password one2one
Home Page

Friday, May 6, 2005

Send mail in ASP.NET

MailMessage oMsg = new MailMessage();
oMsg.From = "me@MyServer.Net";
oMsg.To = "you@YourServer.Net";
oMsg.Cc = "him@HisServer.Net";
oMsg.Subject = "Test";oMsg.Body = "This is only a test";
oMsg.Attachments.Add(new MailAttachment("c:\temp\Test.txt"));

Tuesday, April 19, 2005

.Net Remoting

Process currentProcess = Process.GetCurrentProcess();
Process [] duplicateProcesses = Process.GetProcessesByName(currentProcess.ProcessName);
if (duplicateProcesses.Length == 1)
TcpChannel chan = new TcpChannel(8420);
System.Type.GetType("InteractiveLogBook.RemoteExecute, InteractiveLogBook"),
"RemoteExecute", WellKnownObjectMode.SingleCall);
TcpChannel chan = new TcpChannel();
RemoteExecute obj = (RemoteExecute) Activator.GetObject(typeof(RemoteExecute),
if (obj == null)
MessageBox.Show("Could not locate running Interactive LogBook", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);

public class RemoteExecute : MarshalByRefObject
public RemoteExecute()
public bool ProcessArgs(String[] Args)

return true;


Downloading a file from Sharepoint 2

// C#
public void DownloadDocument(string localFile,string remoteFile)
// Create the web request object
WebRequest request = WebRequest.Create(remoteFile);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = "GET";
// Get a web response back
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream reader = response.GetResponseStream();
FileStream fstream = new FileStream(localFile, FileMode.OpenOrCreate, FileAccess.Write);
byte [] buffer = new byte[1024];
int bytesRead = 0;
bytesRead = reader.Read(buffer,0,1024);
} while(bytesRead >0);
catch(Exception ex)
MessageBox.Show(host.HostForm,ex.Message,"Error Downloading",MessageBoxButtons.OK,MessageBoxIcon.Error);

Uploading a file to Sharepoint 2

public void UploadDocument(string localFile, string remoteFile)
// Read in the local file
FileStream fstream = new FileStream(localFile, FileMode.Open, FileAccess.Read);
byte [] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, Convert.ToInt32(fstream.Length));
// Create the web request object
WebRequest request = WebRequest.Create(remoteFile);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = "PUT";
request.ContentLength = buffer.Length;
// Write the local file to the remote system
BinaryWriter writer = new BinaryWriter(request.GetRequestStream());
writer.Write(buffer, 0, buffer.Length);
// Get a web response back
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
catch(Exception ex)
MessageBox.Show(host.HostForm,ex.Message,"Error Uploading");
Jeffrey Ting Jeffrey Ting on Facebook Jeffrey Ting on Spock Jeffrey Ting on Plaxo Jeffrey Ting on Spoke Jeffrey Ting on LinkedIn