473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Write to Manifest Resource

Hi,

I embedded some configuration XML-File into my assembly. Everything goes
fine if I want to read these Properties. But if I want to change a property,
the runtime says me that this stream is not writable.

How can I write to a ManifestResourceStream? Is this impossible?

Regards Alexander
Nov 16 '05 #1
2 5664
Alexander Wehrli wrote:
How can I write to a ManifestResourceStream? Is this impossible?


This is not possible.

The manifest resource stream is a part of your EXE (or DLL.) EXEs and DLLs
are not modifiable at runtime. There are many reasons for this. One is that
the OS demand-loads binaries, i.e. it only fetches data from the EXE or DLL
as it needs it, rather than necessarily loading everything into memory at
once. If the file can change on disk at runtime, that defeats this
mechanism.

Another reason is that if you give a component a strong name, a signature is
generated at compile time. If you change the contents of the file, the
signature will no longer be valid. To be able to regenerate a valid
signature, you need to have the private key corresponding to the string
name. Distributing the private key with the application would defeat the
whole purpose of code signing because then anyone would be able to generate
a valid-looking signature.

Another reason is that normal users won't have write-access permission to
your EXE. Programs are usually installed in the Program Files directory,
and normal users are not granted write access to that directory. Only
Administrators and Power Users have that privilege, and with good reason -
it means that normal users can't mess up installed programs.

(Sadly, today most users run as administrators. But Microsoft is trying
hard to change that particular culture. And it's good that they are - an
awful lot of viruses in the wild today don't actually work if the logged in
user is not an administrator. Writing to a file in the program directory is
going to become an increasingly less useful practice.)

Another reason is that many viruses work by modifying program files. Virus
scanners sometimes detect and block attempts to modify program files because
of this.

So all in all, you really don't want to do this.

The usual way of solving the problem you state is to embed the default
settings as a resource in your assembly, but if the user changes the
settings, write the modified version out into their profile directory.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/
Nov 16 '05 #2
Hi Ian,

Thanks for your fast reply. Lots of information =D I usually did the
properties stuff as you described. But in this small application I've only
got two nasty property values. So I thought it would be a great thing to drop
all the Config file stuff and just embedd it in my assembly.

Anyway - thanks for helping me.

Regards Alexander

"Ian Griffiths [C# MVP]" wrote:
Alexander Wehrli wrote:
How can I write to a ManifestResourceStream? Is this impossible?


This is not possible.

The manifest resource stream is a part of your EXE (or DLL.) EXEs and DLLs
are not modifiable at runtime. There are many reasons for this. One is that
the OS demand-loads binaries, i.e. it only fetches data from the EXE or DLL
as it needs it, rather than necessarily loading everything into memory at
once. If the file can change on disk at runtime, that defeats this
mechanism.

Another reason is that if you give a component a strong name, a signature is
generated at compile time. If you change the contents of the file, the
signature will no longer be valid. To be able to regenerate a valid
signature, you need to have the private key corresponding to the string
name. Distributing the private key with the application would defeat the
whole purpose of code signing because then anyone would be able to generate
a valid-looking signature.

Another reason is that normal users won't have write-access permission to
your EXE. Programs are usually installed in the Program Files directory,
and normal users are not granted write access to that directory. Only
Administrators and Power Users have that privilege, and with good reason -
it means that normal users can't mess up installed programs.

(Sadly, today most users run as administrators. But Microsoft is trying
hard to change that particular culture. And it's good that they are - an
awful lot of viruses in the wild today don't actually work if the logged in
user is not an administrator. Writing to a file in the program directory is
going to become an increasingly less useful practice.)

Another reason is that many viruses work by modifying program files. Virus
scanners sometimes detect and block attempts to modify program files because
of this.

So all in all, you really don't want to do this.

The usual way of solving the problem you state is to embed the default
settings as a resource in your assembly, but if the user changes the
settings, write the modified version out into their profile directory.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Werner Merkl | last post by:
Hi, Python is really great, for small to big programs. For my colleagues and some circumstances I sometimes need to "compile" a script using py2exe. Cause I use Windows, I like to use the...
5
by: anthony.duerr | last post by:
I have encountered a problem (most certainly a .NET bug), that, for the life of me, I cannot figure out how to work around. Using Visual Studio 2003, with enabled XP Visual Styles. There are...
3
by: Jonathan Payne | last post by:
Hi, I am interested in adding a manifest file to the resources for a MFC application. When I create an AppWizard MFC app with a manifest file it adds the following lines to the .rc file: ...
3
by: Tom wilson | last post by:
Resources 'Beneficiary.aspx.resx' and 'OveraAge.aspx.resx' have the same manifest resource name 'Enroll.Beneficiary.resources'. Umm... what's this mean? The first two are aspx page resource...
11
by: RossettoeCioccolato | last post by:
Is there any way to coax the VC8 linker into generating an application manifest with a trust level section suitable for an administrative application? Or do I have to add this manually each time...
1
by: Steve Teeples | last post by:
Can an application manifest document be added to a C# application? If so, can it be done from within the IDE of Visual Studio 2005? I want to customize my application's security level...
1
by: Bern McCarty | last post by:
I know how with VC8 you embed your linker generated manifest into an exe with a resource ID of #1 and into a dll with resource ID #2. But what do you do with the linker generated manifest for a...
3
by: Dinsdale | last post by:
I must be totally missing something. I am trying to use DirectX to play an AVI file that is stored as a Manifest Resource. Apperently the Video class only takes a string path as a parameter, so...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.