Reversing a registry change?
-
I am in the middle of making an application that tweaks the registry like this, (This one just places the admin account on the windows XP startup screen) Dim reg As RegistryKey Dim intNumber As Integer = 1 Dim strKey As String = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" reg = Registry.LocalMachine.CreateSubKey(strKey) reg.SetValue("Administrator", intNumber) If Not reg Is Nothing Then reg.Close() But when you check the box on my application to make this happen, how can i get it so that when the box is unchecked it will reverse the change instead of me manually going into the registry and changing the value back to 0? also how would i make it so that my application will save the checkboxes states when it is closed and then re-opend? :confused: I really need help with this as microsoft are not much help :(
-
I am in the middle of making an application that tweaks the registry like this, (This one just places the admin account on the windows XP startup screen) Dim reg As RegistryKey Dim intNumber As Integer = 1 Dim strKey As String = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" reg = Registry.LocalMachine.CreateSubKey(strKey) reg.SetValue("Administrator", intNumber) If Not reg Is Nothing Then reg.Close() But when you check the box on my application to make this happen, how can i get it so that when the box is unchecked it will reverse the change instead of me manually going into the registry and changing the value back to 0? also how would i make it so that my application will save the checkboxes states when it is closed and then re-opend? :confused: I really need help with this as microsoft are not much help :(
You can't, you'd have to store the old value first, and put it in with the same sort of code. There is no 'undo' in the registry.
SLRGrant wrote:
also how would i make it so that my application will save the checkboxes states when it is closed and then re-opend?
Then write the states to the registry, or to a config file
SLRGrant wrote:
as microsoft are not much help
Well, the first functionality you want does not exist, and the second is widely documented, so I'm not sure where you're having trouble.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
You can't, you'd have to store the old value first, and put it in with the same sort of code. There is no 'undo' in the registry.
SLRGrant wrote:
also how would i make it so that my application will save the checkboxes states when it is closed and then re-opend?
Then write the states to the registry, or to a config file
SLRGrant wrote:
as microsoft are not much help
Well, the first functionality you want does not exist, and the second is widely documented, so I'm not sure where you're having trouble.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
What I ment is MS dont seem to explain things properly to people, I myself have browsed the MSDN library and what I have found is not explanatory and I have also googled quite allot and it keeps leading me here so i thought i might aswell ask, I dont normally ask on how to do things but what i mainly need right now is samples of code to guide me through it. All i really know about VB at the moment is how to write values to the registry. Soo, sorry to be a pain but how would I store the 'original' value and then recall it when needed?
-
What I ment is MS dont seem to explain things properly to people, I myself have browsed the MSDN library and what I have found is not explanatory and I have also googled quite allot and it keeps leading me here so i thought i might aswell ask, I dont normally ask on how to do things but what i mainly need right now is samples of code to guide me through it. All i really know about VB at the moment is how to write values to the registry. Soo, sorry to be a pain but how would I store the 'original' value and then recall it when needed?
SLRGrant wrote:
Soo, sorry to be a pain but how would I store the 'original' value and then recall it when needed?
With respect, MSDN assumes a level of prior knowledge, which is fairly basic. If a registry key contains 0, and you stuff 1 in there, the 0 is lost. So, your best bet is probably to write registry values when the app closes. Otherwise, you need to store the 0 in a local variable, and then set it back to 0 ( or whatever ) from that variable when the box is unchecked. If you don't store it locally, it has been overwritten and is lost.
SLRGrant wrote:
All i really know about VB at the moment is how to write values to the registry.
It's highly disfunctional for you to know that, and nothing else. I recommend abandoning this project if this is true, and instead working through a VB.NET book to get some basic skills happening.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
SLRGrant wrote:
Soo, sorry to be a pain but how would I store the 'original' value and then recall it when needed?
With respect, MSDN assumes a level of prior knowledge, which is fairly basic. If a registry key contains 0, and you stuff 1 in there, the 0 is lost. So, your best bet is probably to write registry values when the app closes. Otherwise, you need to store the 0 in a local variable, and then set it back to 0 ( or whatever ) from that variable when the box is unchecked. If you don't store it locally, it has been overwritten and is lost.
SLRGrant wrote:
All i really know about VB at the moment is how to write values to the registry.
It's highly disfunctional for you to know that, and nothing else. I recommend abandoning this project if this is true, and instead working through a VB.NET book to get some basic skills happening.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Look, I have bought books and have been reading allot off of the internet I am trying to learn this language and as you should know learning a programming lang is just not easy and I am not going to give up so please dont just put me down like this, all I want is some help really and also if you look at the MSDN library quite allot of the articles listed are very low rated by people like me that are trying to learn it because Microsoft just dont explain where or how to insert the code into it, like MS even says "Visual Basic is a program designed for hobbiest and beginners" so please if all you are gong to say is " MSDN assumes a level of prior knowledge, which is fairly basic" please dont reply because MSDN in most places is not 'fairly basic' to most newbie programmers.
-
Look, I have bought books and have been reading allot off of the internet I am trying to learn this language and as you should know learning a programming lang is just not easy and I am not going to give up so please dont just put me down like this, all I want is some help really and also if you look at the MSDN library quite allot of the articles listed are very low rated by people like me that are trying to learn it because Microsoft just dont explain where or how to insert the code into it, like MS even says "Visual Basic is a program designed for hobbiest and beginners" so please if all you are gong to say is " MSDN assumes a level of prior knowledge, which is fairly basic" please dont reply because MSDN in most places is not 'fairly basic' to most newbie programmers.
SLRGrant wrote:
Look, I have bought books and have been reading allot off of the internet
OK - I was taking you at your word. I assume you actually know a lot more than how to save a registry value ?
SLRGrant wrote:
also if you look at the MSDN library quite allot of the articles listed are very low rated by people like me that are trying to learn it because Microsoft just dont explain where or how to insert the code into it
They are low rated mostly because a lot of people have unrealistic expectations of how easy it is to program. I blame Microsoft marketing for this. If you don't know where to put the code, no website can tell you that. Like I said, MSDN expects some knowledge of how to program. It's like an encyclopedia, ( which has lots of info, but if you can't read, it's not much good ). The knowledge is there, you need to know how to use it.
SLRGrant wrote:
"Visual Basic is a program designed for hobbiest and beginners"
This is true, the main thing is that VB has English like syntax. It's still programming tho, you still need to be able to learn to program, and that doesn't happen overnight, as you said.
SLRGrant wrote:
because MSDN in most places is not 'fairly basic' to most newbie programmers.
I taught myself C++ mostly from MSDN. Anyhow, I've answered your question, I *am* trying to help. But, based on your comments, 'read a book' was the best help I could offer, as well as the specific answer I gave. So, have you solved your problem ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
SLRGrant wrote:
Look, I have bought books and have been reading allot off of the internet
OK - I was taking you at your word. I assume you actually know a lot more than how to save a registry value ?
SLRGrant wrote:
also if you look at the MSDN library quite allot of the articles listed are very low rated by people like me that are trying to learn it because Microsoft just dont explain where or how to insert the code into it
They are low rated mostly because a lot of people have unrealistic expectations of how easy it is to program. I blame Microsoft marketing for this. If you don't know where to put the code, no website can tell you that. Like I said, MSDN expects some knowledge of how to program. It's like an encyclopedia, ( which has lots of info, but if you can't read, it's not much good ). The knowledge is there, you need to know how to use it.
SLRGrant wrote:
"Visual Basic is a program designed for hobbiest and beginners"
This is true, the main thing is that VB has English like syntax. It's still programming tho, you still need to be able to learn to program, and that doesn't happen overnight, as you said.
SLRGrant wrote:
because MSDN in most places is not 'fairly basic' to most newbie programmers.
I taught myself C++ mostly from MSDN. Anyhow, I've answered your question, I *am* trying to help. But, based on your comments, 'read a book' was the best help I could offer, as well as the specific answer I gave. So, have you solved your problem ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Ok well, im sorry for going a bit nasty then but what mainly gets me in VB is when they present you with a code that looks like this: Dim valueNames As String() = rk.GetValueNames() Dim s As String For Each s In valueNames Dim rvk As RegistryValueKind = rk.GetValueKind(s) Select Case rvk Case RegistryValueKind.MultiString Dim values As String() = CType(rk.GetValue(s), String()) Console.Write(vbCrLf & " {0} ({1}) =", s, rvk) For i As Integer = 0 To values.Length - 1 If i <> 0 Then Console.Write(",") Console.Write(" ""{0}""", values(i)) Next i Console.WriteLine() I actually know most of that (after hours of reading a crappy book i paid £40 for) now but when i just started out, I was like W T F is this and wandered where to put it.
-
Ok well, im sorry for going a bit nasty then but what mainly gets me in VB is when they present you with a code that looks like this: Dim valueNames As String() = rk.GetValueNames() Dim s As String For Each s In valueNames Dim rvk As RegistryValueKind = rk.GetValueKind(s) Select Case rvk Case RegistryValueKind.MultiString Dim values As String() = CType(rk.GetValue(s), String()) Console.Write(vbCrLf & " {0} ({1}) =", s, rvk) For i As Integer = 0 To values.Length - 1 If i <> 0 Then Console.Write(",") Console.Write(" ""{0}""", values(i)) Next i Console.WriteLine() I actually know most of that (after hours of reading a crappy book i paid £40 for) now but when i just started out, I was like W T F is this and wandered where to put it.
the snippet probably should not be used verbatim, it should be read and understood as one example of how the class being documented can be used. The question is, where do you WANT to put it ( that is, where do you want your code to perform the action being documented ) ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
the snippet probably should not be used verbatim, it should be read and understood as one example of how the class being documented can be used. The question is, where do you WANT to put it ( that is, where do you want your code to perform the action being documented ) ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Im sorry you dont understand what I am trying to say, Im trying to say 'if i clicked on a button to make this code run' where would i put this code in the button click event, in the middle, at then end? or maybe this goes at the very start of the program (obviously not in most cases). anyhow this is starting to put me off of coding now since i cant get a straight answer from anyone... I came here to get straight answers like everyone else who posts. not to start a war.
-
Im sorry you dont understand what I am trying to say, Im trying to say 'if i clicked on a button to make this code run' where would i put this code in the button click event, in the middle, at then end? or maybe this goes at the very start of the program (obviously not in most cases). anyhow this is starting to put me off of coding now since i cant get a straight answer from anyone... I came here to get straight answers like everyone else who posts. not to start a war.
SLRGrant wrote:
'if i clicked on a button to make this code run' where would i put this code in the button click event, in the middle, at then end?
It plain does not matter. Parts of this code, you don't want, they just print to the console. Other parts go where-ever, in the event, you want the registry entry to be written. As I said before, if you want to go back and forth, you're better off writing the values in the close event of the form, and not every time a check box is changed.
SLRGrant wrote:
anyhow this is starting to put me off of coding now since i cant get a straight answer from anyone
I am trying desperately to help you, but your questions make no sense to me. I don't know what else you're doing in your event handler, or why you think it matters what order you do things in, but can't work out which order is correct. I don't know if you realise that some of that code isn't about writing to the registry, or if you understand what any of it does, line by line, or just have an idea of what it does as a block.
SLRGrant wrote:
I came here to get straight answers like everyone else who posts. not to start a war.
I'm not trying to start any war, I am trying to help. Since the release of the Express Editions, I find often the best help I can give people is to recommend they start over and try to learn some basics. I'm sorry if that offended you, I was only trying to give good advice.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog