Get Device Info vb.net

Tuesday, July 29, 2008

Get Process ID ,MAC Address ,Volume Serial No.,Mother Board ID

Imports System.Management

Private Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject

For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId
End Function

Private Function GetMACAddress() As String
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = String.Empty
For Each mo As ManagementObject In moc
If (MACAddress.Equals(String.Empty)) Then
If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
MACAddress = MACAddress.Replace(":", String.Empty)
Next
Return MACAddress
End Function



Private Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
disk.Get()
Return disk("VolumeSerialNumber").ToString()
End Function
Private Function GetMotherBoardID() As String
Dim strMotherBoardID As String = String.Empty
Dim query As New SelectQuery("Win32_BaseBoard")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strMotherBoardID = info("SerialNumber").ToString()
Next
Return strMotherBoardID
End Function

Convert text to Image in vb.net


Imports System.Drawing
Imports System.Drawing.Bitmap
Imports System.Drawing.Graphics
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Image


Private Sub a()
Dim Text As String = "Rajiv Ranjan"
Dim FontColor As Color = Color.Red
Dim FileName As String = "Image1"
Dim objBitmap As New Bitmap(Width, Height)
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim objColor As Color
Dim objFont As New Font(FontName, FontSize)

Dim objBrushForeColor As New SolidBrush(FontColor)
Dim objBrushBackColor As New SolidBrush(BackColor)

objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
objGraphics.DrawString(TextBox1.Text.ToString, objFont, objBrushForeColor, objPoint)
objBitmap.Save(Application.StartupPath & FileName & ".JPG", ImageFormat.Jpeg)

How to Delete Shortcut

Wednesday, July 16, 2008


Private Sub DeleteShortCut()
Dim fso As New Scripting.FileSystemObject
Dim DPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Try
fso.DeleteFile(DPath & "\ABC.lnk", True)
Catch ex As Exception
Try
dpath = Strings.Left(dpath, 26)
fso.DeleteFile(DPath & "All Users\Desktop\ABC.lnk", True)
Catch
End Try
End Try
end Sub

Some Namespaces and their use

Wednesday, July 9, 2008

Some Namespaces and their use:
System: Includes essential classes and base classes for commonly used data types, events, exceptions and so on(Base Class of all)

System.XML: Includes classes for XML support

System.Windows.Forms: Includes classes for creating Windows based forms

System.IO: Includes classes for data access with Files(Input and Output Operation)

System.Data.OleDb: Includes classes that support the OLEDB .NET

System.Data.SqlClient: Includes classes that support the SQL Server .NET provider

How to create a function

How to create a function
public function functionname(argument ) returntype


end function

Get OS information in VB.Net

?How to Get OS Version in VB.Net
'''' This Function Is written in vb.net Which will return the version of OS

Public Function GetOSVersion() As String
Dim osInfo As OperatingSystem
Dim sAns As String
osInfo = System.Environment.OSVersion
With osInfo
Select Case .Platform
Case .Platform.Win32Windows
Select Case (.Version.Minor)
Case 0
sAns = "Windows 95"
Case 10
If .Version.Revision.ToString() = "2222A" Then
sAns = "Windows 98 Second Edition"
Else
sAns = "Windows 98"
End If
Case 90
sAns = "Windows Me"
End Select
Case .Platform.Win32NT

Select Case (.Version.Major)
Case 3
sAns = "Windows NT 3.51"
Case 4
sAns = "Windows NT 4.0"
Case 5

If .Version.Minor = 0 Then
sAns = "Windows 2000"
ElseIf .Version.Minor = 1 Then
sAns = "Windows XP"
ElseIf .Version.Minor = 2 Then
sAns = "Windows Server 2003"
Else 'Future version maybe update 'as needed sAns = "Unknown Version"
End If
Case 6
sAns = "Windows Vista"
End Select
End Select
End With
Return sAns
End Function

instance of an application in VB.Net


?How to Check the instance of an application in VB.Net
''' Check whether the instance of an application is running or not
Private Function CheckInstanceOfApplication() As Boolean

CheckInstanceOfApplication= False

Dim AllProcesses As Process()
AllProcesses = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
If (AllProcesses.Length > 1) Then
Return True
End If
End Function

'''''''''''''''' End Here

Get O.S. Information

''How to get OS Info in VB ?

Option Explicit
Private Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long

szCSDVersion As String * 128

End Type

'in module or gen decl.
Public Declare Function GetVersionExA Lib "kernel32" _(lpVersionInformation As OSVERSIONINFO) As Integer
' function to get OS Version
Public Function getosVersion() As String
Dim osInfo As OSVERSIONINFODim lRV As Integer
osInfo.dwOSVersionInfoSize = 148
osInfo.szCSDVersion = Space$(128)
lRV = GetVersionExA(osInfo)
With osInfo
Select Case .dwPlatformId
Case 1
If .dwMinorVersion = 0
Then getosVersion = "95"
ElseIf .dwMinorVersion = 10
Then getosVersion = "98"
End
IfCase 2
If .dwMajorVersion = 3 Then
getosVersion = "3.51"
ElseIf .dwMajorVersion = 4 Then
getosVersion = "4.0"
ElseIf .dwMajorVersion = 5 Then
If .dwMinorVersion = 0 Then
getosVersion = "2000"
ElseIf .dwMinorVersion = 1 Then
getosVersion = "WinXP/.NET Server"
End If
End If
Case Else getosVersion = "Failed"
End Select
End With
End Function

''End here