Zulake
Zulake

Reputation: 149

Visual Basic, How to modify text inside a file in the Resources

I added a file to my resources called Test.txt. Inside the Test.txt I wrote the word "boo".

How to replace the text "boo" inside the app resource with another word for example "Bah"?

Upvotes: 1

Views: 3639

Answers (4)

Jim Billig
Jim Billig

Reputation: 344

While I agree that it's best not to edit resources after compiling, for changing strings it can be done with just about any hex editor.

Make a copy of your binary in case something goes wrong. Open the file in a hex editor (like free HxD Hex Editor), search for the value to replace, and then change the individual characters. Save your changes and see if it worked.

The trick is to not change anything outside of the string, as well as to not change the length of the string. If you alter the size of the file, it may no longer work. Also, any CRC or MD5 hashing will be wrong, so if something validates that, be aware.

For example-

boo -> bah is ok
boo -> baha is not ok
boo -> ba is not ok
boo -> ba_ is ok (use space)

Upvotes: 0

Gary Walker
Gary Walker

Reputation: 9134

There are Resource function calls to update a resource file in place http://msdn.microsoft.com/en-us/library/windows/desktop/ff468902(v=vs.85).aspx , but they are ugly, ugly, ugly. Vista added a number of security restrictions too. Have fun if you just want to play around, but in production code as your boss I would either make you rewrite, fire you, or amuse myself by listening to your "justification" for doing this -- maybe do all 3.

Upvotes: 0

Dennis
Dennis

Reputation: 1547

If you want to store a text, and change it during run time, it's better to use my.settings.

It is saved, and contained the next time your run your program.

http://social.msdn.microsoft.com/Forums/en-US/ed1491b4-65ed-4a06-a770-d37d863ec24e/how-do-i-persiststore-user-settings-using-mysettings-in-vbnet

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564851

You shouldn't try to modify the resources at runtime. If you need to change this, a good option is to extract the resources and save them on disk (ie: in the user's AppData folder). You can then use (and modify) the file as needed.

Trying to modify the resource in the assembly itself will likely 1) fail due to permission issues at deployment, and 2) get your program flagged as a virus by nearly every virus scanner.

Upvotes: 1

Related Questions