TOGGIT - IN SEARCH OF CERTIFICATION
 TOGGIT
     IN SEARCH OF CERTIFICATION
    
     
  
TOGGIT IN SEARCH OF CERTIFICATION

Visual Basic .Net Sample Code and Applications

MAIN
Logon to ToggIT
Join ToggIT
Home
Home
Contact Us
Career Building
Certification Maps
Partners
Technopedia
.Net Source Code
Free Networking Tools
Free IT Publications
Microsoft
2003 Certifications
270 Win XP Pro
290 2003 Server
291 2003 Network Inf
293 Plan Network inf
294 2003 Active Directory
224 Exchange 2000
DBA Certifications
228 SQL 2000
229 SQL 2000
MCSD Certifications
526 Windows Apps
305 ASP.NET
2000 Certifications
210 Professional
215 Server
216 Network inf.
217 Directory Svc.
218 Managing 2K
219 Design Dir Svc.
220 Design Security
270 Win XP Pro
221 Design Net Inf.
Cisco
CCNA
CompTia
A+ Hardware 2003!
A+ Software 2003!
Network+
Security+
New Wireless
CWNP program
Java 
Java Goodies 



MCSE Top-Rated Sites



 

Join Toggit Now!
Avoid Annoying Ads!

 Your Email:

 New Password:

See the list of .Net articles
Reading from and Writing to the Windows Registry in .Net

This code sample shows you how to use the available Visual Basic .Net objects to read and write to and from the Windows registry.

This code assumes that you have a textbox named Textbox1 to receive output, but you can use any string value in its place.

First, we will look into a parent key and see the names of all of the sub-keys. Our parent key in this example is named Acme, and is located in the hKey.LocalMachine.Software registry hive.
 


Dim
s() As String = Registry.LocalMachine.OpenSubKey("SOFTWARE\Acme").GetValueNames

For
x As Integer = 0 To s.Length - 1
    TextBox1.Text &= s(x) & vbCrLf
Next
 

Once you know the name of the subkey that you want to read, you can read the data from it. In this example we want to read from the Acme subkey a value named UserName:



Dim
myParentKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim
mySubKey As Microsoft.Win32.RegistryKey = myParentKey.OpenSubKey("SOFTWARE\Acme", True)
If
mySubKey Is Nothing Then
    
mySubKey = myParentKey.CreateSubKey("SOFTWARE\Acme")
End If
TextBox1.Text = CStr(objSubKey.GetValue("UserName", ""))
 
It is just as easy to write a value into the registry. For this example we will set the UserName to hold the value "Joe":

Dim
mySubKey As Microsoft.Win32.RegistryKey
Dim
myParentKey As Microsoft.Win32.RegistryKey
myParentKey = Microsoft.Win32.Registry.LocalMachine
mySubKey = myParentKey.OpenSubKey("SOFTWARE\Acme", True)
'create if doesn't exist
If
mySubKey Is Nothing Then
     mySubKey = myParentKey.CreateSubKey(SubKeyName)
End If
mySubKey.SetValue("UserName", "Joe")
 


 

Study and Research resources:
Microsoft Certification Info:
 
See the list of .Net articles

 

TOGGIT      IN SEARCH OF CERTIFICATION

All information on this site is copyright ToggIT.com unless otherwise specified. Material submitted or posted this site may also contain materials that are copyrights of individual contributors. It is illegal to copy, publish, reproduce, or distribute any materials from this site with the express permission of the owner of this material.

The material on this web site is not sponsored by, endorsed by or affiliated with Microsoft, Inc, CompTIA, or Cisco Systems, Inc. Microsoft, Inc.® ,Windows XP, Windows 2000, Windows 2000 Server, Windows 98, Windows NT, Visual Basic, Visual C++, Visual FoxPro, SQL server and Microsoft logos are trademarks or registered trademarks of Microsoft,  Inc. in the United States and certain other countries. A+, Server+, and Network+ are all registered trademarks of CompTIA. CCNA, CCNE, and the Cisco logo are all registered trademarks of Cisco Systems. All other trademarks are trademarks of their respective owners.