Friday, February 29, 2008

Monday, February 18, 2008

Scripting with C# Script

I have been playing cscript recently and I have found it a better alternative to Jscript. With C# Script you have the power of C# Language with the scripting capability. Hence, you don't have to compile your code when making modification to it.

You also have the option to create an executable out of the script.

Here is an example of accessing COM from C# Script. Notice the include tag on the first line

//css_prescript com(SYSINFO.SysInfo.1, SisInfoLib);
using System;
using SisInfoLib;
class Script
{
[STAThread]
static public void Main(string[] args)
{
SysInfoClass sysInfo = new SysInfoClass();
switch (sysInfo.ACStatus)
{
case 0:
Console.WriteLine("Not using AC power");
break;
case 1:
Console.WriteLine("Using AC power");
break;
default:
Console.WriteLine("Unknown AC power status");
break;
}
if (sysInfo.BatteryLifePercent != 255)
Console.WriteLine("Battery life " + sysInfo.BatteryLifePercent + "%");
else
Console.WriteLine("Battery charge status not known");
}
}