2

Basically, I had just use some coding to convert all the password to hash and have save these hash into a textfile.

The next thing that I wanted to do is to read the textfile and saved it into the application. I have already do some research on how to read a textfile and add it into my code, but my main concern is where do I save it into so that it will be stored into the application?

Eilson
  • 21
  • 4
  • Possible duplicate of [Losing VB.NET "My.Settings" with each new ClickOnce deployment release](http://stackoverflow.com/questions/1702260/losing-vb-net-my-settings-with-each-new-clickonce-deployment-release) – MicroVirus Nov 18 '15 at 02:08
  • I have tried the coding there but does not work – Eilson Nov 18 '15 at 02:17
  • Another question/answer that might be clearer (second answer): [Can I control the location of .NET user settings to avoid losing settings on application upgrade?](http://stackoverflow.com/questions/621265/can-i-control-the-location-of-net-user-settings-to-avoid-losing-settings-on-app?lq=1) – MicroVirus Nov 18 '15 at 02:21
  • I'm sorry to hear that. To help you further along, we might need some more details. How are you deploying your app? It seems there might be issues with ClickOnce deployment and this route. – MicroVirus Nov 18 '15 at 02:23
  • I reedited my question:) – Eilson Dec 08 '15 at 02:20

1 Answers1

2

The problem that you are facing is simply this; Each time that you 'release' a version of your program the settings stored in My.Settings are tied to the version number of that release. Typically they'll be stored in the AppData|Local|[Your CompanName]|[Your Application Name]|[Application Version Number].

Every time you release a new version a new settings folder gets created and it will typically use the default settings that you placed in My.Settings, so everything that your end user set in the last version gets lost on upgrade.

Now on the face of it you'd think that that would render My.Settings pretty useless, and indeed if you don't allow for that it does, but fortunately there is a little trick you can employ that gets around this. My.Settings has a special little method to help you with this called Upgrade

So how do you use this little trick?

  1. Create a new setting under My.Settings. Name it SettingsUpdateRequired. This setting should be a user setting of type Boolean and it's default value should be set to True. Once set you DO NOT change this from program version release to release.
  2. Now in your main start-up routine (wherever that is) and fairly close to the top of the tasks that you carry out at start up you add the following code:

enter image description here

NB: I've had to add the code snippet as a picture because for some reason the code formatter that SO uses doesn't like the # symbol.

So essentially what you are doing here is only calling this routine when your application is running in release mode. If it's a brand new version of your application it see's (from the fact that your special setting 'SettingsUpdateRequired' that an upgrade is required. The old settings that your end user had in the last version are then transferred over to the new version and the 'SettingsUpdateRequired' value is then set to false and saved. My.Settings.Upgrade won't run again until you release a new version and your end user has their own personalised settings retained.

Community
  • 1
  • 1
Dom Sinclair
  • 2,458
  • 1
  • 30
  • 47
  • Now i got another issue, the setting value in the application is now gone when i copied it to another folder location on my desktop. Is there any solution to make the setting value retained in the app after i copied? – Eilson Nov 18 '15 at 07:39
  • Why would you copy the settings value to another folder? By default My.Settings is always going to write to a specific location. You shouldn't be trying to change that. The whole point of the Upgrade method is that it knows where to look, if you move the goal posts how do you then expect it to work? – Dom Sinclair Nov 18 '15 at 08:23
  • I am sorry but i don't quite understand, did u mean that i cannot copy the application to somewhere else in the desktop?? The application need to be at the location where i published? – Eilson Nov 18 '15 at 08:51
  • Sorry I didn't quite follow you either. You can have the application wherever you want or more specifically wherever then end user wants to install it. However once installed you can't just 'move' it to another folder and expect that everything will work as before. In circumstances like that you are better uninstalling and re-installing. Installation of applications is every bit as important as the building of them and you need to be prepared to spend time (and quite possibly money) getting that bit right. – Dom Sinclair Nov 18 '15 at 09:34
  • I am sorry, I posted a bit wrong and have edited, what I meant was that if I were to updated myproject.exe.config and run the project.exe without the config file in the same directory, is there a way for me to get the updated value that I had made in the config file? – Eilson Dec 08 '15 at 03:33
  • The obvious question to your edit is Why? The Project.exe and the projeject.exe.config are meant to be together and it's difficult to envisage how they wouldn't be unless separated deliberately (which comes back to why would you or someone else do that, and for what gain or purpose). If you can produce a proper answer to that question it might be possible to devise a strategy to combat it. – Dom Sinclair Dec 08 '15 at 06:30
  • I guess I understood what you mean. The whole issue that I am currently facing is actually from the above project(re-edited question). Perhaps you can assist me with the above project and we will have another solution? – Eilson Dec 09 '15 at 02:02
  • Off the top of my head I can think of no bona fide reason as to why you would want, or need to change the local administrators password on an end users machine. So, assuming for the sake of argument that you are creating a legitimate programme then you need to rethink what you're actually doing and learn to work within the confines of what you find when your programme gets to where it is going. Secondly this sort of thing (not unlike the need to reconfigure database access) is what you typically do in installation routines, which is where you should be concentrating your research now. – Dom Sinclair Dec 09 '15 at 06:40
  • The main reason is basically this is my school project work and that is the requirement "create an application that can change the local administrator password". But anyway, as times passes, I had already done some improvement to this project and now I have another issues – Eilson Dec 09 '15 at 08:34
  • I am sorry for re-editing the question again. Thanks for any assistance provided:) – Eilson Dec 09 '15 at 08:41