RSS

Scripting with C# Script

18 Feb

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”);
}
}

Advertisements
 
Leave a comment

Posted by on February 18, 2008 in Development, Technology, Test Automation, Testing

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: