Tuesday, February 12, 2008

How to Retieve data of an( .ini/.txt/.vbs) file using VBScript based on key-value pair

Class ReadInifile
Dim arrFile()
Dim objFSO, objFile
Function sec_prop(section_name,section_property)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("dataexg.ini", 1)
Do Until objFile.AtEndOfStream
str_sec = objFile.ReadLine
If str_sec = "["& section_name & "]" Then
svalue = ""
Do until InStr(svalue,"[") Or objFile.AtEndOfStream
Redim Preserve arrFile(0)
'MsgBox section_name & section_property
If Not objFile.AtEndOfStream Then
arrFile(0) = objFile.ReadLine
'MsgBox InStr(arrFile(0),section_property)
If InStr(arrFile(0),section_property) Then
a = Split(arrFile(0),"=")
sec_prop = a(1)
end If
svalue = arrFile(0)
End If
Loop
End If
Loop
Erase arrFile
objFile.close
End function
End Class

Dim objINI, Result
Set objINI = New ReadInifile
Result = objINI.sec_prop( "server","servername")
MsgBox Result

Program to send E-mail through VBScript

Function SendMail(SendTo, Subject, Body, Attachment)
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to=SendTo
Mail.Subject=Subject
Mail.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
Mail.Send
Set Mail = Nothing
Set ol = Nothing
End Function
Call SendMail(("adityajoy58@gmail.com;kalyan_kudapa@adp.com"),"hi","HI This is Aditya","") //

Friday, February 8, 2008

How to Get Free space/Total space of Given Drive using VBScript

Dim a,s,t
Call GetFreeSpace("C:")
Wscript.echo s
Function GetFreeSpace(drvPath)
dim fs, d
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(drvPath))
s = "Drive " & drvPath & " - "
s = s & d.VolumeName
s = s & " Free Space: " & d.FreeSpace/1024 & " Kbytes"
s = s & " Total Space: " & d.TotalSize/1024 & "Kbytes"
GetFreeSpace = s
'MsgBox s
End function

How to Open Internet Explorer with particular site using VBScript

Option Explicit

Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")

With objIE
.Visible = True
.FullScreen = False
.Navigate "http://www.igoogle.com/"
Do Until .ReadyState <> 4
WScript.Sleep 10000
Loop
End With

Set objIE = Nothing

How to Open any Windows Application using Vbscript

In this Program, we are opening a Windows calculator

set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "calc"
WScript.Sleep 10000
oShell.AppActivate "Calculator"
MsgBox ScriptEngineBuildVersion //For knowing which Script Engine we are using.

How to Open a Windows Application using Vbscript Program

In this Example, we are opening windows calculator

set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "calc"
WScript.Sleep 10000
oShell.AppActivate "Calculator"
MsgBox ScriptEngineBuildVersion // This line shows which version is the Script Engine in XP