Recent Posts

Sunday, September 21, 2008

Visual Basic 2005 ( vb .net 2.0) Introduces “My Object”

My object which is introduced by vb net 2005.
This is very useful for the software developers who are trying to learn visual basic in vb .Net 2.0 environment.
It is very helpful for the visual basic programmers to get various information about the computer where the application is running, previously each process were to be coded manually but now this new feature has just made it too simple to use.
The functionality previously available by calling COM libraries or the Win32 API, are now easily accessible through My Object.

Visual Basic 2005 now provides a “speed dial” called The My Object.
By using The My Object, you have the ability to easily access computer, application, and user information, as well as obtain access to Web services and forms.
It is important to understand that The My Object is accessible to you only when writing Visual Basic .NET applications and is not directly available to you when using C#.

Some common questions answered by My objects are listed below:

1. How can I get the user name of the windows user from visual basic net?


2. How can I check if the windows user is an Admin from visual basic net?


3. What is name of the computer where the application is running (vb net)?


4. What is the local or GMT time in the computer where the application is running (vb net)?


5. What is the resolution of the computer where the application is running (vb net)?

My.Computer.Screen.Bounds.Width & _
"x" & My.Computer.Screen.Bounds.Height

6. Check if the network of the computer is available where the application is running from vb net application?


7. What is the operating system of the application where the application is running from vb net?


8. What is the directory path of the application from vb net?


9. How to get collection of open Ports in the computer from vb net?


10. How to play an Audio (.wav) file stored in the computer from vb net?

Here strFile is the path of the file located
Dim strFile As String
strFile = "C:\Program Files\Messenger\online.wav"
Me.lblDisplay.Text =my.Computer.Audio.Play(strFile)

11. How can I get Access to System’s Clipboard from vb net?

If My.Computer.Clipboard.ContainsText = True Then

Me.lblDisplay.Text = My.Computer.Clipboard.GetText.ToString()
ElseIf My.Computer.Clipboard.ContainsImage = True Then
‘ code for getting image
ElseIf My.Computer.Clipboard.ContainsAudio = True Then
‘ code for getting Audio file
ElseIf My.Computer.Clipboard.ContainsData("dd") = True Then
‘ code for getting data “dd”
End If

12. How can I read or write registry from vb net?


13. How can I issue ping command and find out if the host is reachable or not from vb net?

Dim pingResult As Boolean
PingResult= my.Computer.Network.Ping(txtPing.Text)
If pingResult = True Then
MessageBox.Show("Ping of IP:" & txtPing.Text & " succeeded")
MessageBox.Show("Ping of IP:" & txtPing.Text & " was not Successful")
End If

14. How can I read all the text in a file from vb net?

filePath is the path of the file

15. How to copy or move folders from vb net?

My.Computer.FileSystem.CopyDirectory(sourcePath, targetPath, True, True)

The preceding True will overwrite the directory or a file if it already exists in the target path.

16. How to determine the location of My Documents folder with one line of code from vb net application?



Introducing Microsoft Visual Basic 2005 for Developers

Microsoft Press

Related Posts by Categories

No comments:

Post a Comment