Monday, December 1, 2008

Win32_OperatingSystem-find computer last bootup time

Hi Firends yesterday i have play with Win32_Operating System class and i have found out using this task i can intract with my computer operating system.. I had dig into that and for sample here i am going to write code to find out your computer last bootup time
VB.NET Code

Public Sub Lastbootuptime()
Dim strComputer As String = "." ' Local computer
Dim objWMIDateTime As Object = CreateObject("WbemScripting.SWbemDateTime")
Dim objWMI As Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colOS As Object = objWMI.InstancesOf("Win32_OperatingSystem")
For Each objOS In colOS
objWMIDateTime.Value = objOS.LastBootUpTime
MessageBox.Show("Last Boot Up Time: " & objWMIDateTime.GetVarDate)
Next
End Sub

Abhishek Hingu at:
http://www.indianic.com/

Wednesday, September 3, 2008

Generate Counter Image runtime

1 <%@ page language="vb" contenttype="image/jpeg" %> 2 <%@ import namespace="system.drawing" %> 3 <%@ import namespace="system.drawing.imaging" %> 4 <%@ import namespace="system.drawing.drawing2d" %> 5 <% 6 7 response.clear ' make sure Nothing has gone to the client 8 9 10 dim imgOutput as New bitmap(120, 30, pixelformat.format24bpprgb) ' create a New 24bit, 120x30 pixel image 11 dim g as graphics = graphics.fromimage(imgOutput) ' create a New graphic object from the above bmp 12 13 application("intPageCount")+=1 ' really dumb page counter 14 15 g.clear(color.yellow) ' blank the image 16 g.smoothingMode = smoothingMode.antiAlias ' antialias objects 17 18 ' draw the number on the image canvas in verdana 10pt font bold 19 g.drawString("Count: " & application("intPageCount"), New font("verdana",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2)) 20 21 ' draw a graduated fill across the image 22 g.FillRectangle(New linearGradientBrush(New point(0,0), New point(120,30), color.fromArgb(0,0,0,0),color.fromArgb(255,255,255,255)),0,0,120,30) 23 24 25 imgOutput.save(response.outputstream, imageformat.jpeg) ' output to the user 26 27 28 ' tidy up 29 g.dispose() 30 imgOutput.dispose() 31 response.end 32 33 %>

Tuesday, September 2, 2008

Validate String max length using Reguler Expression in C#

class Program
{
static void Main(string[] args)
{
if (Regex.IsMatch("[Input String]","^.{4,20}$" ))
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
Console.ReadLine();
}
}

Wednesday, May 21, 2008

Universal Contdown timer + javascript

//Javascript to create Universal Countdown timer

function GetCount(){
dateFuture = new Date(document.getElementById('servertime').value); // Get server datetime to find time difference between local time and server time as per GMT
var d=new Date();
var localTime = d.getTime();
var localOffset = d.getTimezoneOffset() * 60000;
var utc = localTime + localOffset;
var offset = document.getElementById('offset').value;
var london = utc + (3600000*offset);
dateNow = new Date(london); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;

// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now!";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";

amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

days=Math.floor(amount/86400);//days
amount=amount%86400;

hours=Math.floor(amount/3600);//hours
amount=amount%3600;

mins=Math.floor(amount/60);//minutes
amount=amount%60;

secs=Math.floor(amount);//seconds

if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
out += secs +" seconds";
document.getElementById('countbox').innerHTML=out;
setTimeout("GetCount()", 1000);
}
}


//
//
//