Login   Search
Skip Navigation Links
Home
Application Security Tips
Oracle , PL/SQL
IT Product Reviews
Project Management
Forum
Contact Us
Links & References
Avoid SQL Injection attack
Threats and Countermeasures: S.T.R.I.D.E
Input Validation
Session Management
Authentication Mechanism
Cross Site Scripting Vulnerabilities
Configuration Management
Scroll up
Scroll down
Oracle 9i - Programming basics PL/SQL
PL/SQL - Conditional Statements – IF
PL/SQL -Nested Block
LOOPS in PL/SQL
PL/SQL Records
Cursors in PL/SQL
PL/SQL Tables
PL/SQL Exceptions
PL/SQL Procedures
PL/SQL Functions
Oracle supplied packages
Packages
PL/SQL Ref Cursors
Types in Oracle PL/SQL
Varrays
Nested Table
Bfile and LOBs
Bulk Binding
Know Depandencies
PL/SQL Wrapper
Triggers
Scroll up
Scroll down
DBMS_SQL package
DBMS_DDL Package
DBMS_JOB Package
UTL_FILE Package
DBMS_METADATA Package
DBMS_PIPE Package
DBMS_SESSION Package
Scroll up
Scroll down

 

Blog

  • Imperativeness of agile methodology in software development
  • Get list of installed softwares on machines in your network
  • VMWare - Error - the vmware authorization service is not running
  • Add chart / graphs in ASP.net application / website
  • Microsoft Ramp Up

Blog

  • Review: uCertify.com: PrepKit for: 70-529 (C#)
  • Bird eye Review: uCertify.com: PrepKit for: 70-529 (C#)
Skip Navigation Links

> Blog entries about: Programming
Get list of installed softwares on machines in your network

I was looking for a way to get list of softwares installed in machines in our network for verifying something. I did not wanted to go & login in each machine & then collection list of softwares from add / remove programs. 

So I decided to write a small program that will do this for me.

This is how we can do it. List that you see in add remove program is stored in Machine registry at path SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  under local machine.

So your program will connect to registry of each machine specified & read the list. Then compile that list by removing list items such as Updates / Fixes etc as per requirement.

Below function will enumerate the softwares installed in a text file & also will display it on console application.

private static void WriteSoftwareListToFile(string MachineName , string ReportFileName)

{

StreamWriter sw;

if (File.Exists(ReportFileName))

{

sw = File.AppendText(ReportFileName);

}

else

{

sw = File.CreateText(ReportFileName);

}

sw.WriteLine("\r\nSoftwares installed on " + MachineName +

" on " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString());

//Registry path which has information of all the softwares installed on machine

string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

// using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))

sw.WriteLine("\r\nSoftware Name \t Software Version");

try

{

using (RegistryKey rk =

RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, MachineName).

OpenSubKey(uninstallKey))

{

foreach (string skName in rk.GetSubKeyNames())

{

using (RegistryKey sk = rk.OpenSubKey(skName))

{

string SoftwareName = string.Empty;

string SoftwareVersion = string.Empty;

try

{

SoftwareName = sk.GetValue("DisplayName").ToString();

SoftwareVersion = sk.GetValue("DisplayVersion").ToString();

}

catch (NullReferenceException exNull)

{

SoftwareName = string.Empty;

SoftwareVersion = string.Empty;

}

if (SoftwareName != string.Empty)

{

//Exclude Updates , Fixes

if (!(SoftwareName.Contains("Security Update for Windows") ||

SoftwareName.Contains("Hotfix for") ||

SoftwareName.Contains("Update for") ||

SoftwareName.Contains("Update for Windows")))

{

Console.WriteLine(SoftwareName + " " + SoftwareVersion);

sw.WriteLine(SoftwareName + "\t" + SoftwareVersion);

}

}

}

}

}

}

catch (Exception Ex)

{

sw.WriteLine("\r\n Exception :" + Ex.Message);

}

sw.Close();

}

 

You can call this functions for all require machines in your network like below. Please note if you are running the application your domain ID need to have registry read access for all the machines your are accessing.

 

static void Main(string[] args)

{

string[] Machines = new string[]

{

"MachineHostName1",

"MachineHostName2",

"MachineHostName3",

"MachineHostName4",

"MachineHostName5",

"MachineHostName6" };

string FILE_NAME = "SoftwareList_" + DateTime.Now.ToShortDateString().Replace("/", "") + ".log";

for (int i = 0; i < Machines.Length; i++ )

WriteSoftwareListToFile(Machines[i], FILE_NAME);

Console.ReadLine(); // To make the o/p readable.

}

{1/25/2010 12:28 PM} {0 comments}  {Tags: C#, Code Samples, Programming, Tips & Tricks}
Add chart / graphs in ASP.net application / website

There are lots of commercial graph or chart controls for ASP.net. But if you are looking for free chart / graph components below mentioned components may be useful for your needs.

  • Zed Graph
    The best ever I could find is Zed Graph.
    It has nice features
    Free Source Code or Binaries can be downloaded from
    http://sourceforge.net/projects/zedgraph/

      There is a good tutorial available to use this component 
         http://www.codeproject.com/KB/graphics/zedgraph.aspx

         One simpler example for ZedGraph for ASP.net is available at Sailing Kay’s blog
            http://sailingkay.blogspot.com/2007/03/zedgraph.html

  • For very Simple HTML Graphs rendered via ASP.net.
    This is very simple horizontal bar chart. It dynamically creates html table with cells background color gives look of a bar chart.
    http://www.codetoad.com/asp.net_graph.asp

This article references to ASP.net 2.0 development.

 

{12/18/2009 3:51 PM} {0 comments}  {Tags: ASP.net, C#, Code Samples, Free, Programming, UI}
Use your IT skills to earn money

Online Jobs , Freelancing  , and lot more

 

The On Demand Global Workforce - oDesk
{9/29/2009 9:58 PM} {0 comments}  {Tags: Programming, Tips & Tricks}
How to write a message to MSMQ and read a message from MSMQ ( C# , .net )

This is a very very basic bare-bones tutorial on writing to and reading from an MSMQ queue.

The example methods are both using a private local queue and use the default XMLFormatter.

First create the private queue:
-Open the Computer Management Console
-Navigate to Message Queuing under Services and Applications
-Expand Message Queueing, right-click on Private Queues and create a new private queue.

If you don't see the Message Queueing option under Services and Applications, you don't have MSMQ installed on the machine. To install it, choose Add/Remove Windows Components and check Message Queueing and proceed with the installation.
  
To write to a queue:
1. Specifiy the path to the queue - for a local private queue, the path should be in the form ".\private$\<queue name>" - replace <queue name> with the actual queue name e.g. ".\private$\testqueue"

2. Create a message of the type you wish in a Message object.
3. Create the queue object, supplying the path to it as a parameter.
4. Call the Send method on the queue, supplying the Message object created as a parameter.

The code should look something like the method below:

public string InsertInQueue()

{
   
string msg = "Test Queue Object"; //message contents

   string queuepath = ".\\private$\\testqueue"; //path to queue

    MessageQueue myQueue = new MessageQueue(queuepath); //create queue object

    Message myMsg = new Message(msg); //form Message object

   try

   {

     myQueue.Send(myMsg); //write message to queue

    return "Success";

   }

  catch(Exception ex)

   {

    return ex.Message;

   }

}

To read a message from a queue:

1. Specifiy the path to the queue
2. Create the queue object, supplying the path to it as a paramater.
3. Specify the formatter, either on the queue or by creating separate formatter object.
4. Read the message from the queue, by calling the Receive method on the queue.
5. Convert the message body as appropriate and return the value.

Sample code is shown below demonstrating how to read from a queue:

public string ReadFromQueue()

{

  string queuepath = ".\\private$\\testqueue"; //specify queue path

   MessageQueue myQueue = new MessageQueue(queuepath); //create queue

  //specify typenames - this is needed by the formatter, to enable it to read the message contents
  string
[] typenames = {"System.String"};

  //The line below specifies the formatter on the queue
  //myQueue.Formatter = new XmlMessageFormatter(typenames);

  //read message from queue 
  Message myMsg = myQueue.Receive(
new TimeSpan(0, 0, 5));

  XmlMessageFormatter fmt = new XmlMessageFormatter(typenames);

  //The line below is valid if the formatter is specified on the queue, as shown above
  //return myMsg.Body.ToString();

  //Since we've selected to specify a separate formatter, we need to read the contents
 //of the message using the formatter

  return
fmt.Read(myMsg).ToString();

}


PS: You must reference System.Messaging for all this to work.

{9/11/2009 12:39 PM} {0 comments}  {Tags: Microsoft, Programming, C#, MSMQ, Code Samples}
Check free disk of your servers / computers on network

Since few days I was facing a problem that some of the servers were short of free space due to disk full.

I was looking for quick & simple way to monitor free space on server. I found some sripts on internet & modified it to suit my requirement .

Below script connects to all listed servers using WMI query , creates a report on c:\ . It can also email the report if you want.

How to use this script ?

  • Copy below code in notepad 
  • List names of computers / server in arrServers .
  • Set flag for email true / false & settings for email server
  • Save file as HDDSpaceCheck.vbs file. 
  • Double click vbs file . It shall show report in minute or so depending on number of servers.
  • You can use windows scheduled task to schedule this activity & get email notification .

 

' ******************** Start of Script *************

' Author : Rahul S Bagal  07/13/2009
' This Script Checks Free Disk space in servers defined in "arrServers "


' Define Names of servers to be checked for disk space
arrServers = Array("Server1","Server2","Server3","Server4")

' Email Settings

Const SendEmail = True    ' Turn this flag to false you you do not wish to receive the report in email
const DisplayReportOnScreen  =  True  ' Turn this flag if you do not want to open the created report file. 

strServer = "MailserverName"
intPort = 25
strFrom = "
DoNotReply@domain.com"   ' Set from Email address for email reports
strTo = "
YourName@domain.com"       ' Set to email address where you wish to receive email

' Report File defination
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

' This is the file name where email
strFilePath = "C:\HDDRerport" & Month ( now ) & Day(now) & year(now) & ".txt"


'The WMI query bit...
For i = LBound(arrServers) To UBound(arrServers)
 strBody = strBody & "Please find below a report on local disks for server : " & arrServers(i) & vbCrLf & vbCrLf
 On Error Resume Next
 Set objWMI = GetObject("winmgmts:\\" & arrServers(i) & "\root\cimv2")
 Set colDisks = objWMI.ExecQuery("Select * from Win32_LogicalDisk Where DriveType=3")' Where DeviceID = '" & strDiskLetter & "'")
 If Err.Number = 0 Then
  For Each objDisk in colDisks
   strBody = strBody & "Drive " & objDisk.DeviceID & " - " & vbTab & "Total Size(MB): " & bytesToMB(objDisk.Size) _
    & vbTab & vbTab & "Free Space(MB): " & bytesToMB(objDisk.FreeSpace) & vbtab & " Free Space ( % ) : " & round( bytesToMB(objDisk.FreeSpace) / bytesToMB(objDisk.Size) * 100 , 2 ) & vbcrlf
  Next
 Else
  strBody = strBody & "!ERROR! connecting to " & arrServers(i) & ". " & Err.Number & " - " & Err.Description
  Err.Clear
 End If
 strBody = strBody & vbCrLf & vbCrLf
Next

' Write to File

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    (strFilePath , ForWriting , True)
objTextFile.WriteLine("Server Disk Space Report" & vbCrLf )
objTextFile.WriteLine(strBody )
objTextFile.Close
set objFSO = nothing

'email Section

if SendEmail = True then 
 On Error Goto 0
 Set objMail = CreateObject("CDO.Message")
 With objMail
  .Subject = "Server Disk Space Report"
  .From = strFrom
  .To = strTo
  .TextBody = strBody
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 '2 = use a specified SMTP server, 1 = use local SMTP service
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer 'Your SMTP Server
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = intPort 'Server port
  .Configuration.Fields.Update
  .Send
 End With
end if

Set objMail = Nothing
Set objWMI = Nothing
Set colDisks = Nothing
Set objNet = Nothing


' Display report if flag is set

if DisplayReportOnScreen = True then
 Dim WshShell
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.Run strFilePath
 Set WshShell = nothing
end if

Function bytesToMB(intbytes)
 bytesToMB = FormatNumber((intbytes / 1024) / 1024,,,,-1)
End Function

' ******************** End of Script *************

{7/13/2009 5:16 AM} {0 comments}  {Tags: Programming, WMI, VB Script, Tips & Tricks}
1 2> >>|



Designed & Developed by Rahul Bagal