Saturday, August 1

Getting Computer Info through VB.net

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Computer's operating system version: " & _
My.Computer.Info.OSVersion)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Computer's operating system name: " & _
My.Computer.Info.OSFullName)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MsgBox("Computer's available physical memory: " & _
My.Computer.Info.AvailablePhysicalMemory)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
MsgBox("Computer's available virtual memory: " & _
My.Computer.Info.AvailableVirtualMemory)
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
MsgBox("Computer's UI culture name: " & _
My.Computer.Info.InstalledUICulture.DisplayName)
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
ListBox1.DataSource = My.Application.Info.LoadedAssemblies
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
MsgBox("Computer's operating system platform: " & _
My.Computer.Info.OSPlatform)
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
MsgBox("Computer's operating system version: " & _
My.Computer.Info.OSVersion)
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
MsgBox("Stack trace: " & My.Application.Info.StackTrace)
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
MsgBox("Application working set: " & My.Application.Info.WorkingSet)
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text = My.Computer.Keyboard.CapsLock()
If My.Computer.Keyboard.CapsLock Then
MsgBox("CAPS LOCK is on")
Else
MsgBox("CAPS LOCK is off")
End If
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If My.Computer.Keyboard.CtrlKeyDown Then
MsgBox("CTRL key down")
Else
MsgBox("CTRL key up")
End If
End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("syskey.exe", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
' Send the keystrokes to the Calculator application.
My.Computer.Keyboard.SendKeys("U", True)
My.Computer.Keyboard.SendKeys("P", True)
My.Computer.Keyboard.SendKeys("W", True)
My.Computer.Keyboard.SendKeys("prembharti", True)
My.Computer.Keyboard.SendKeys("{TAB}", True)
My.Computer.Keyboard.SendKeys("prembharti", True)
My.Computer.Keyboard.SendKeys("{TAB}", True)
My.Computer.Keyboard.SendKeys("{Enter}", True)
My.Computer.Keyboard.SendKeys("{Enter}", True)

' The result is 22 * 44 = 968.
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If My.Computer.Mouse.WheelExists Then
Dim lines As Integer = My.Computer.Mouse.WheelScrollLines
If lines > 0 Then
MsgBox("Application scrolls " & _
lines & " line(s) for each wheel turn.")
Else
MsgBox("Application scrolls " & _
(-lines) & " page(s) for each wheel turn.")
End If
Else
MsgBox("Mouse has no scroll wheel.")
End If
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If My.Computer.Mouse.ButtonsSwapped Then
MsgBox("Functionality of the mouse buttons is swapped.")
Else
MsgBox("Default functionality of the mouse buttons.")
End If
End Sub

Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
MsgBox("Computer name: " & My.Computer.Name)
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
If My.Computer.Network.IsAvailable = True Then
MsgBox("Computer is connected.")
Else
MsgBox("Computer is not connected.")
End If
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
'Use the UploadFile method to upload a file, specifying the
'source(file) 's location and the target directory location as a string or URI (Uniform Resource Identifier).This example uploads the file Order.txt to http://www.cohowinery.com/uploads.aspx.
My.Computer.Network.UploadFile( _
"C:\My Documents\Order.txt", _
"http://www.cohowinery.com/upload.aspx")

'Use the UploadFile method to upload a file, specifying the source file's location and
'the target directory location as a string or URI. This example uploads the file Order.txt
'to http://www.cohowinery.com/uploads.aspx without supplying a user name or password, shows the progress of the upload, and has a time-out interval of 500 milliseconds.
'////coding session starts
'My.Computer.Network.UploadFile( _
'"C:\My Documents\Order.txt", _
'"http://www.cohowinery.com/upload.aspx", "", "", True, 500)
'coding session ends////



'Use the UploadFile method to upload a file, specifying the source file's location and the target directory location as a string or URI, and specifying the user name and the password. This example uploads the file Order.txt to http://www.cohowinery.com/uploads.aspx, supplying the user name anonymous and a blank password.


'My.Computer.Network.UploadFile( _
'"C:\My Documents\Order.txt", _
'"http://www.cohowinery.com/upload.aspx", "anonymous", "")


End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
If My.Computer.Network.Ping("198.01.01.01") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If



'Determine whether the Ping method returns True, specifying the time-out interval in milliseconds. If no time-out is specified, 500 is used as the default. This example reports whether or not the server can be pinged, by determining whether the Ping method returned True, and it specifies a time-out interval of 1000 milliseconds. Replace www.cohowinery.com with the IP address, URL, or computer name of the server to ping.


' If My.Computer.Network.Ping("www.cohowinery.com", 1000) Then
'MsgBox("Server pinged successfully.")
' Else
' MsgBox("Ping request timed out.")
' End If
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
' Use the DownloadFile method to download the file, specifying the target file's location as a string or URI and specifying the location at which to store the file. This example downloads the file WineList.txt from http://www.cohowinery.com/downloads and saves it to C:\Documents and Settings\All Users\Documents:

' My.Computer.Network.DownloadFile _
'("http://www.cohowinery.com/downloads/WineList.txt", _
' "C:\Documents and Settings\All Users\Documents\WineList.txt")


'Use the DownloadFile method to download the file, specifying the target file's location as a string or URI, specifying the location at which to store the file, and specifying the time-out interval in milliseconds (the default is 1000). This example downloads the file WineList.txt from http://www.cohowinery.com/downloads and saves it to C:\Documents and Settings\All Users\Documents, specifying a time-out interval of 500 milliseconds:



' My.Computer.Network.DownloadFile _
'("http://www.cohowinery.com/downloads/WineList.txt", _
'"C:\Documents and Settings\All Users\Documents\WineList.txt", False, 500)


'Use the DownLoadFile method to download the file, specifying the target file's location as a string or URI and specifying the location at which to store the file, the user name, and the password. This example downloads the file WineList.txt from http://www.cohowinery.com/downloads and saves it to C:\Documents and Settings\All Users\Documents, with the user name anonymous and a blank password.


' My.Computer.Network.DownloadFile _
'("http://www.cohowinery.com/downloads/WineList.txt", _
' "C:\Documents and Settings\All Users\Documents\WineList.txt", "anonymous", "")

End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
My.Computer.Audio.Play("C:\WINDOWS\Media\ding.wav", _
AudioPlayMode.Background)
End Sub

Private Sub Button30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button30.Click
My.Computer.Audio.Play(My.Resources.chimes, AudioPlayMode.Background)
End Sub

Private Sub Button29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button29.Click
My.Computer.Clipboard.SetText("This is a test string.")


'To clear the Clipboard
' My.Computer.Clipboard.Clear()


'To read text from the Clipboard and display it
'MsgBox(My.Computer.Clipboard.GetText())


'To save audio data to the Clipboard
'Dim musicReader As Byte()
' musicReader = My.Computer.FileSystem.ReadAllBytes("cool.wav")
' My.Computer.Clipboard.SetAudio(musicReader)


'To retrieve an image from the Clipboard
'If My.Computer.Clipboard.ContainsImage() Then
' Dim grabpicture As System.Drawing.Image
' grabpicture = My.Computer.Clipboard.GetImage()
' picturebox1.Image = grabpicture
'End If


'to write text in the clipboard
' If My.Computer.Clipboard.ContainsImage() = True Then
'MsgBox("Clipboard contains an image.")
' Else
' MsgBox("Clipboard does not contain an image.")
' End If
End Sub

Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
My.Computer.Clipboard.SetImage(My.Resources.FRIENDS2)
End Sub

Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
Dim cdrive As System.IO.DriveInfo
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox(cdrive.VolumeLabel)

'Get drive type
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox(cdrive.DriveType.ToString)

'Drive's total space

cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox(cdrive.TotalSize)

'Get drive's physical space
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox("Total free space: " & CStr(cdrive.TotalFreeSpace))


'get drive's information
Dim getInfo As System.IO.DriveInfo
getInfo = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox("The drive's type is " & getInfo.DriveType)
MsgBox("The drive has " & getInfo.TotalFreeSpace & " bytes free.")


End Sub

Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click

End Sub
End Class

No comments: