|
-
Oct 11th, 2002, 04:16 PM
#1
Thread Starter
Lively Member
Registry Help - Should be dead easy
ok guys, i want to check a key exists if yes then exit sub, but if it dont exist create it and then exit sub.
<vbcode>
Public Sub Check_Reg()
If Registry.LocalMachine.Name = ("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator") = True Then
Debug.WriteLine("Key Exists")
Else
Registry.LocalMachine.CreateSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator")
End If
End Sub
</vbcode>
thats what i got, dunno if its right guys, Help me please, tnx guys, u all rule
BTW i am useing .NET
-
Oct 11th, 2002, 05:03 PM
#2
Addicted Member
not sure if this is the best way but I know it will get it done.
Code:
Dim RegKey As RegistryKey
Dim s As String
RegKey = Registry.LocalMachine.OpenSubKey("Software\A", True )
Try
s = RegKey.ToString()
Catch
RegKey = Registry.LocalMachine.CreateSubKey("Software\A")
End Try
you will also need to import Microsoft.Win32
Jeremy
-
Oct 11th, 2002, 06:03 PM
#3
-
Oct 12th, 2002, 09:10 AM
#4
Thread Starter
Lively Member
ok dudes, u guys are mint, i think i got a bit confused as to what i was asking but, how do i create a new string, coz the key is like the folder then there is a string with a value, how to i make a string and give it a value, and then chage the value of the string later
-
Oct 12th, 2002, 09:17 AM
#5
Hyperactive Member
I'll give you my custom function for creating file associations. You should be able to figure it from that:-
VB Code:
Public Function AddAssociation(ByVal fExt As String, ByVal appName As String, ByVal appPath As String) As Boolean
Try
Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fExt)
extKey.SetValue("", appName)
Dim appKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(appName)
appKey.SetValue("", appName & " File")
Dim shellKey As RegistryKey = appKey.CreateSubKey("shell")
Dim openKey As RegistryKey = shellKey.CreateSubKey("open")
Dim commKey As RegistryKey = openKey.CreateSubKey("command")
commKey.SetValue("", appPath & " %1")
Return true
Catch
Return False
End Try
End Function
-
Oct 12th, 2002, 09:35 AM
#6
Thread Starter
Lively Member
sorry, im **** at this i have created a key, how do i create a string:
this is my registry key:
"SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator"
how do i create a string called NWHome and give it a value of "c:\temp\scripts\cmd\NWHome.cmd"
-
Oct 12th, 2002, 09:53 AM
#7
Thread Starter
Lively Member
ok chaps got it in the end here it is:
<code>
Imports Microsoft.Win32
Public Class MyClass
Public Sub Make_Reg
Registry.LocalMachine.CreateSubKey("SOFTWARE\Your\Key\Here")
End Sub
Public Sub Make_String
Registry.LocalMachine.CreateSubKey("SOFTWARE\Your\Key\Here").SetValue("Your_String", "Value_Of_Your_String")
End Sub
End Class
</code>
-
Oct 12th, 2002, 11:23 AM
#8
Thread Starter
Lively Member
Question again: how the hell do i close my open key this dont work
Registry.LocalMachine.OpenSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version").GetValue("Version")
Registry.LocalMachine.Close("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version")
help!!!!
-
Feb 10th, 2003, 08:15 AM
#9
Hyperactive Member
I don't know if you've done it yet.
but I think it's something like:
Code:
Registry.LocalMachine.CloseSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|