Hi!
I have a little problem with the registry function. The function is
supposed to check the registry as the main form is activated. If there
is a key it should not write to the registry, as it does.
Can anybody see what I'm doing wrong?
Private Sub WriteToRegistry()
Dim regKey As RegistryKey = Nothing
Dim regValue As String
Try
regValue = "Software\\MyApp"
regKey = Registry.CurrentUser.CreateSubKey(regValue)
regKey.SetValue("RunOnce", "1")
regKey.SetValue("Date", Now)
regKey.SetValue("CopyRight", "©GSB")
regKey.SetValue("UserAccepted", "Miss Piggy")
regKey.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Write_to_Registry",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function CheckRegistryKey() As Boolean
Dim regVersjon As RegistryKey = Nothing
Dim keyValue As String
Dim bExists As Boolean = False
Try
keyValue = "Software\\MyApp\\UserAccepted\\Miss Piggy"
regVersjon = Registry.CurrentUser.OpenSubKey(keyValue,
False)
If (Not regVersjon Is Nothing) Then
bExists = True
ElseIf (regVersjon Is Nothing) Then
bExists = False
WriteToRegistry()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Check_Registry_Key",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
If (Not regVersjon Is Nothing) Then
regVersjon.Close()
End If
End Try
Return bExists
End Function
Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Static IsActivated As Boolean
Try
If Not IsActivated Then
IsActivated = True
CheckRegistryKey()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "MAIN_ACTIVATED",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Hope the code is readable.
Me.Name 6 2137
Hi,
regValue = "Software\MyApp"
Ken
-----------------------------
<gs***@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi!
I have a little problem with the registry function. The function is
supposed to check the registry as the main form is activated. If there
is a key it should not write to the registry, as it does.
Can anybody see what I'm doing wrong?
Private Sub WriteToRegistry()
Dim regKey As RegistryKey = Nothing
Dim regValue As String
Try
regValue = "Software\\MyApp"
regKey = Registry.CurrentUser.CreateSubKey(regValue)
regKey.SetValue("RunOnce", "1")
regKey.SetValue("Date", Now)
regKey.SetValue("CopyRight", "©GSB")
regKey.SetValue("UserAccepted", "Miss Piggy")
regKey.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Write_to_Registry",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function CheckRegistryKey() As Boolean
Dim regVersjon As RegistryKey = Nothing
Dim keyValue As String
Dim bExists As Boolean = False
Try
keyValue = "Software\\MyApp\\UserAccepted\\Miss Piggy"
regVersjon = Registry.CurrentUser.OpenSubKey(keyValue,
False)
If (Not regVersjon Is Nothing) Then
bExists = True
ElseIf (regVersjon Is Nothing) Then
bExists = False
WriteToRegistry()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Check_Registry_Key",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
If (Not regVersjon Is Nothing) Then
regVersjon.Close()
End If
End Try
Return bExists
End Function
Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Static IsActivated As Boolean
Try
If Not IsActivated Then
IsActivated = True
CheckRegistryKey()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "MAIN_ACTIVATED",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Hope the code is readable.
Me.Name
<gs***@hotmail.com> schrieb: regValue = "Software\\MyApp"
[...] keyValue = "Software\\MyApp\\UserAccepted\\Miss Piggy"
Replace the double backslashes ("\\") with single backslashes ("\"). I
assume that the code was based on a sample written in C# where backslashes
must be escaped if the string literal is not a verbatim ('@"bla\bla"')
string literal.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Yes Indeed!
Why did I forget that I moved from C# to VB.NET?
Happy Weekend!
Me.Name
Hi,
regValue = "Software\MyApp"
Ken
-----------------------------
<gs***@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi!
I have a little problem with the registry function. The function is
supposed to check the registry as the main form is activated. If there
is a key it should not write to the registry, as it does.
Can anybody see what I'm doing wrong?
Private Sub WriteToRegistry()
Dim regKey As RegistryKey = Nothing
Dim regValue As String
Try
regValue = "Software\\MyApp"
regKey = Registry.CurrentUser.CreateSubKey(regValue)
regKey.SetValue("RunOnce", "1")
regKey.SetValue("Date", Now)
regKey.SetValue("CopyRight", "©GSB")
regKey.SetValue("UserAccepted", "Miss Piggy")
regKey.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Write_to_Registry",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function CheckRegistryKey() As Boolean
Dim regVersjon As RegistryKey = Nothing
Dim keyValue As String
Dim bExists As Boolean = False
Try
keyValue = "Software\\MyApp\\UserAccepted\\Miss Piggy"
regVersjon = Registry.CurrentUser.OpenSubKey(keyValue,
False)
If (Not regVersjon Is Nothing) Then
bExists = True
ElseIf (regVersjon Is Nothing) Then
bExists = False
WriteToRegistry()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Check_Registry_Key",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
If (Not regVersjon Is Nothing) Then
regVersjon.Close()
End If
End Try
Return bExists
End Function
Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Static IsActivated As Boolean
Try
If Not IsActivated Then
IsActivated = True
CheckRegistryKey()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "MAIN_ACTIVATED",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Hope the code is readable.
Me.Name
<gs***@hotmail.com> schrieb: regValue = "Software\\MyApp"
[...] keyValue = "Software\\MyApp\\UserAccepted\\Miss Piggy"
Replace the double backslashes ("\\") with single backslashes ("\"). I
assume that the code was based on a sample written in C# where backslashes
must be escaped if the string literal is not a verbatim ('@"bla\bla"')
string literal.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Yes Indeed!
Why did I forget that I moved from C# to VB.NET?
Happy Weekend!
Me.Name This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tongu? Yumruk |
last post by:
I have a little proposal about type checking in python. I'll be glad
if you read and comment on it. Sorry for my bad english (I'm not a
native English speaker)
A Little Stricter Typing in Python...
|
by: GujuBoy |
last post by:
i want to check to see if a certain program is installed on my windows
box using python. how can i do that...(ie, i want to see if "word" is
installed)
please help
|
by: Jeff |
last post by:
Hi -
I'm creating an installation program that will install a VB.NET program and
an instance of MSDE on an unknown desktop (commercial application). The
install will include the MSDE...
|
by: gsb58 |
last post by:
Hi!
I have a little problem with the registry function. The function is
supposed to check the registry as the main form is activated. If there
is a key it should not write to the registry, as it...
|
by: Jozef |
last post by:
Hi folks!
I'm trying to develop a system that will allow users to keep preference
settings in the registry. Is there any way to detect if the user has rights
to write to the registry without...
|
by: jonefer |
last post by:
How can I lookup registry values?
I'd like to check for the existence of this folder in the registry:
HKLM\Software\AcmeCompany\MWIApplications\AutoLogonForSharedWorkstations
so that I can use...
|
by: JOSII |
last post by:
Getting a string of boolean value into and out of the registry is no problem.
Here's the problem:
Although you can place an object into the registry and retreive it, I need
to place an ArrayList...
|
by: Nick 'The Database Guy' |
last post by:
Hi All,
I have writen a value to the registry.
What I want to know is, is there a way that I can check that value?
Thanks in advance.
Nick
|
by: causesdrowsiness |
last post by:
Hi everyone.
Sorry if this is the wrong group for this question, but since it
is .NET and VB, I thought someone may be able to help me here or point
me to the right group for this.
I am...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |