QuestionHelpWhere can be the error?

Posts 1–4 of 4 · Page 1 of 1
Where can be the error?
Good morning to everybody.

I have created I source code, but now there is a problem. It is not working.

The program should insert KEY into registry. But it does not.
I think there are some possibilities what is the error (no error found by Visual Studio).
1. My computer was attacked by a scanner, which has stolen me a registry key and have changed some permissions in it. From REG_BINARY it made in one case REG_SZ, but other registry info seems to be OK. Maybe not everything is broken?
2. Because I am beginner, I have inserted the code somewhere where it should not be. Structure of my project is: Module1, which contains code showing some text in the console (nothing more...), Form1, which contains the source code which should change the registry key and Form, which contains nothing (auto generated...).
3. The source code is wrong. The code has some more functions - I tried to change my own registries values.
Maybe also the adress of KEY is wrong. Somewhere I found it should be
Code:
Software\Bohemia Interactive Studio\Arma 2
, but the real adress (copied from registry) is
Code:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2
.
So what is right?

Code:
[Private Function SetKey() As String
            Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Bohemia Interactive Studio/ArmA 2 REINFORCEMENTS", True)
            If ((key Is Nothing) OrElse Not Enumerable.Contains(Of String)(key.GetValueNames, "KEY")) Then
                Return Me.SetKey64
            End If
            Dim identifier As New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing)
            Dim identity As String = TryCast(identifier.Translate(GetType(NTAccount)),NTAccount).ToString
            Dim registrySecurity As New RegistrySecurity
            registrySecurity.AddAccessRule(New RegistryAccessRule(identity, RegistryRights.ExecuteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
            registrySecurity.AddAccessRule(New RegistryAccessRule(identity, (RegistryRights.ChangePermissions Or (RegistryRights.WriteKey Or RegistryRights.Delete)), InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny))
            key.SetValue("KEY", "0000000000000000")
            key.SetAccessControl(registrySecurity)
            Return Conversions.ToString(1)
        End Function
Thanks !

---------- Post added at 08:04 AM ---------- Previous post was at 07:35 AM ----------

So tried. Now only two possibilities. The code is wrong or it cannot work in changed registry.
? Thanks.
1. Learn to read some value from the registry. Any value. As long as it can read correctly.

2. Learn to write some value to the registry. Any value. As long as it can write correctly.

3. finish this code.


we can't tell you what your registry paths look like If the path is incorrect, it is incorrect. You tell us. It sounds like the problem is the path. ? Do #1 and #2 and you'll know better.

---------- Post added at 08:25 AM ---------- Previous post was at 08:14 AM ----------

Code:
            Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Bohemia Interactive Studio/ArmA 2 REINFORCEMENTS", True)
            If ((key Is Nothing) OrElse Not Enumerable.Contains(Of String)(key.GetValueNames, "KEY")) Then
                Return Me.SetKey64
            End If
aka: if key (PATH) is nothing (doesn't exist), SetKey64

so SetKey64 has another declaration for "path", apparently the registry for 64 bit computers is different so...where is that code?

edit:
Code:
            Dim identifier As New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing)
            Dim identity As String = TryCast(identifier.Translate(GetType(NTAccount)),NTAccount).ToString
            Dim registrySecurity As New RegistrySecurity
            registrySecurity.AddAccessRule(New RegistryAccessRule(identity, RegistryRights.ExecuteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
            registrySecurity.AddAccessRule(New RegistryAccessRule(identity, (RegistryRights.ChangePermissions Or (RegistryRights.WriteKey Or RegistryRights.Delete)), InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny))
^^where did you get this code? It's weird you have TryCast, NTAccount, RegistryAccessRule, but can't get the path ...
Yeah.
For SetKey is the path
Code:
 "Software\Bohemia Interactive Studio\Arma 2"
and for SetKey64 it is
Code:
 "SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2"
.

The code I have found somewhere, so I am not sure if there is not something wrong (there was much more source code, but it was full of errors...) and if because of it the program does not work. I do not want to reboot my PC, but if there is no visible error, I will have to do. Is not missing smth in it? Thanks.
idk, I've never accessed the registry in the same way you are. It's possible, but apparently not with your code.

"I have created I source code..." ---hmmm--- "The code I have found somewhere..."

1. If you have a registry problem, like a missing/incorrect value, use regedit (which apparently you know about) and manually fix it.
2. You copy-pasted instead of understanding how the registry* works.
3. 'The source code is wrong.' Apparently.

4. Do you have 1 specific question?
("Is not missing smth in it?" does not count.)
Quote Originally Posted by abuckau907 View Post
1. Learn to read some value from the registry. Any value. As long as it can read correctly.

2. Learn to write some value to the registry. Any value. As long as it can write correctly.

3. finish this code.

...
^^Until you can do #1 and #2, or, have 1 specific question, idk.
aka. what is ' registrySecurity.AddAccessRule() ' and why do you use it. If you don't know..don't use it.
.
.
---

GetKey(), Upload(), Registry(): what's next, add app to start-up? (?)
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us