472,965 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

My windows giveth xml and it taketh away! Include path!

I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser
choice for me was to use an xml file to save my configs. Btw: I wonder if
this is why every bit of documentation I've found for saving configuration
info in an xml file speak of only doing this for web programming in fact, I
get the impression that they have been slipped a mickey that made them
forget that there are programs out there that are not web based, but I
digress ...

I could have done a regular config files be just a regular text file, but I
figured, I might as well do it with xml like everyone else is doing, so
remove all my registry config saving stuff and replace it with a simple
class that uses an in-memory only dataset and table tries to read the xml
file named "SwarmIni.xml" and if it doesn't exist, create one by building
the config schema on the in-memory table, and then populating a row or rows
with my config data and create the file. WriteXml over-writes the xml file,
so I didn't have to worry about deleting the file.

It worked fine as long as I named the file swarm.exe, the file and the
config screen would track. However, when I renamed the exe to .scr all kinds
of strange things would happen. First, I would watch it create the xml
values, I would bring up config and change a value, shut down the
screensaver, reload it and see that the new values were there, and then I'd
get curious and open up the xml with notepad and find the OLD values there!!
Notice I say that it worked normally as long as it ended in exe but seemed
to be working with some sort of ghost-xml file with new values AND create a
visible xml file that did not track with my config changes. It was not a
case of different names, the file name was a constant, in only ONE place in
the program.

It was as if windows was kidnapping the xml file!! Despite doing a search
telling it to include system32 and all system subdirectories, it would find
any file except xml files, even non-xml files in system32 but it would not
find that file I was seeing right there in front of my face! Now ain't this
strange??

I solved it! I simply included the application path so that the config.xls
file created was SwarmIni.scr.config.xls and then no matter how I named the
extention, the data in the config screen, and that in the xml file would
track.

So, while I never ever did find out what was happening, I did cure it by
specifying the path. I suspect that windows is kidnapping a copy of the xml
file and redirecting things some how. I still can't get search to find my
xml files tho. I have show hidden and show system files turned on.

I learned three important rules of xml programming ....

1. Always specify a path, never just give it a name and trust it to create a
file in the location you expect, without this bizarre non-tracking behavior
cropping up.

2. Never, ever copy your write method to the read method and change the name
of the method and the code to do the reading. What I did by accident, was
that I had the read method, callling the write method IF the file did not
exist, which was fine and dandy, but in the branch I executed when the file
already existed, I had a read early on and a spurious DataTable.WriteXml
call, but writing an xml file while my xml helper class was supposed to be
reading, and hadn't disposed of the table doing the reading yet, caused some
strange feedback loop to start. My program would appear to execute, but some
process would end up looping, and my hard drive light would start thrashing
like crazy. There was no visible process, and the every time I ran my saver,
everything looked ok, but my computer would flash, lag, the hard drive would
do more and more thrashing, creating nothing that I could see and all kinds
of strange things would happen which are too many to list ...

3. It is unfortunate that xml is so similar to xls - excel's spreadsheet
extention. I have to be extremely careful not to accidentally name something
as xls instead of xml. In C++ I would have created a global #define in one
place and forget about it, but in C# there isn't such a thing as a global
constant visible throughout all the projects in a solution, so be careful
out there!

4. I am a bit wary about this saving config info in xml format tho. Sure,
it's portable, and its nice to read it and locate values, but it's also
portable to malware that might be able to read those value and change them,
and perhaps cause some sort of havoc by trying buffer over-runs and other
stuff. In other words, I worry about this, that it might create a security
hole here. An ini file I write, could have been in any format, and could
have anything in it in any order, but an xml file, is predicable, and
standard, and makes it an easy pickins target. Don't get me wrong, I don't
dislike xml format. It's great for moving data and sharing it, but I wonder
if it's such a great place to store config info. I think more security needs
to be put into place. Perhaps xml with encrypted contents?

RambleMode = Off.

--
To reply to this message take off the .NoJunkSpam off of the end of
ga******@pacbell.net.NoJunkSpam
Nov 12 '05 #1
2 1511
Nope Windows will not touch the file. My guess is your screen saver is
writing to the file on shutdown and clobbering the updated values that way?

If you just call it .xml then you won't conflict with the special magic
..config files. .config files are meant for management of the deployment of
an app, it's for the IT guys to mess with and your app usually just reads
them. So settings that your app actually saves would be in a separate file.

"Garry Freemyer" <ga******@pacbell.net.byespam> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser
choice for me was to use an xml file to save my configs. Btw: I wonder if
this is why every bit of documentation I've found for saving configuration
info in an xml file speak of only doing this for web programming in fact, I
get the impression that they have been slipped a mickey that made them
forget that there are programs out there that are not web based, but I
digress ...

I could have done a regular config files be just a regular text file, but
I figured, I might as well do it with xml like everyone else is doing, so
remove all my registry config saving stuff and replace it with a simple
class that uses an in-memory only dataset and table tries to read the xml
file named "SwarmIni.xml" and if it doesn't exist, create one by building
the config schema on the in-memory table, and then populating a row or
rows with my config data and create the file. WriteXml over-writes the xml
file, so I didn't have to worry about deleting the file.

It worked fine as long as I named the file swarm.exe, the file and the
config screen would track. However, when I renamed the exe to .scr all
kinds of strange things would happen. First, I would watch it create the
xml values, I would bring up config and change a value, shut down the
screensaver, reload it and see that the new values were there, and then
I'd get curious and open up the xml with notepad and find the OLD values
there!! Notice I say that it worked normally as long as it ended in exe
but seemed to be working with some sort of ghost-xml file with new values
AND create a visible xml file that did not track with my config changes.
It was not a case of different names, the file name was a constant, in
only ONE place in the program.

It was as if windows was kidnapping the xml file!! Despite doing a search
telling it to include system32 and all system subdirectories, it would
find any file except xml files, even non-xml files in system32 but it
would not find that file I was seeing right there in front of my face! Now
ain't this strange??

I solved it! I simply included the application path so that the config.xls
file created was SwarmIni.scr.config.xls and then no matter how I named
the extention, the data in the config screen, and that in the xml file
would track.

So, while I never ever did find out what was happening, I did cure it by
specifying the path. I suspect that windows is kidnapping a copy of the
xml file and redirecting things some how. I still can't get search to find
my xml files tho. I have show hidden and show system files turned on.

I learned three important rules of xml programming ....

1. Always specify a path, never just give it a name and trust it to create
a file in the location you expect, without this bizarre non-tracking
behavior cropping up.

2. Never, ever copy your write method to the read method and change the
name of the method and the code to do the reading. What I did by accident,
was that I had the read method, callling the write method IF the file did
not exist, which was fine and dandy, but in the branch I executed when the
file already existed, I had a read early on and a spurious
DataTable.WriteXml call, but writing an xml file while my xml helper class
was supposed to be reading, and hadn't disposed of the table doing the
reading yet, caused some strange feedback loop to start. My program would
appear to execute, but some process would end up looping, and my hard
drive light would start thrashing like crazy. There was no visible
process, and the every time I ran my saver, everything looked ok, but my
computer would flash, lag, the hard drive would do more and more
thrashing, creating nothing that I could see and all kinds of strange
things would happen which are too many to list ...

3. It is unfortunate that xml is so similar to xls - excel's spreadsheet
extention. I have to be extremely careful not to accidentally name
something as xls instead of xml. In C++ I would have created a global
#define in one place and forget about it, but in C# there isn't such a
thing as a global constant visible throughout all the projects in a
solution, so be careful out there!

4. I am a bit wary about this saving config info in xml format tho. Sure,
it's portable, and its nice to read it and locate values, but it's also
portable to malware that might be able to read those value and change
them, and perhaps cause some sort of havoc by trying buffer over-runs and
other stuff. In other words, I worry about this, that it might create a
security hole here. An ini file I write, could have been in any format,
and could have anything in it in any order, but an xml file, is
predicable, and standard, and makes it an easy pickins target. Don't get
me wrong, I don't dislike xml format. It's great for moving data and
sharing it, but I wonder if it's such a great place to store config info.
I think more security needs to be put into place. Perhaps xml with
encrypted contents?

RambleMode = Off.

--
To reply to this message take off the .NoJunkSpam off of the end of
ga******@pacbell.net.NoJunkSpam

Nov 12 '05 #2
Nope, I wasn't writing on shutdown. If it did write, it would be the new
values.

I suspect, that somewhere, I had it saving to a different area and never
noticed while fixing. I read about the .config stuff, so I named mine
Swarm.scr.config.xml, and haven't had a single issue since. It could also be
because I had that extraneous write in the read operation, it was setting up
some sort of loop, the read, caused a write, while trying to read I suspect,
but it's all working perfectly now.
"Chris Lovett" <so*****@nospam.please> wrote in message
news:h7********************@comcast.com...
Nope Windows will not touch the file. My guess is your screen saver is
writing to the file on shutdown and clobbering the updated values that
way?

If you just call it .xml then you won't conflict with the special magic
.config files. .config files are meant for management of the deployment
of an app, it's for the IT guys to mess with and your app usually just
reads them. So settings that your app actually saves would be in a
separate file.

"Garry Freemyer" <ga******@pacbell.net.byespam> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser
choice for me was to use an xml file to save my configs. Btw: I wonder if
this is why every bit of documentation I've found for saving configuration
info in an xml file speak of only doing this for web programming in fact,
I get the impression that they have been slipped a mickey that made them
forget that there are programs out there that are not web based, but I
digress ...

I could have done a regular config files be just a regular text file, but
I figured, I might as well do it with xml like everyone else is doing, so
remove all my registry config saving stuff and replace it with a simple
class that uses an in-memory only dataset and table tries to read the xml
file named "SwarmIni.xml" and if it doesn't exist, create one by building
the config schema on the in-memory table, and then populating a row or
rows with my config data and create the file. WriteXml over-writes the
xml file, so I didn't have to worry about deleting the file.

It worked fine as long as I named the file swarm.exe, the file and the
config screen would track. However, when I renamed the exe to .scr all
kinds of strange things would happen. First, I would watch it create the
xml values, I would bring up config and change a value, shut down the
screensaver, reload it and see that the new values were there, and then
I'd get curious and open up the xml with notepad and find the OLD values
there!! Notice I say that it worked normally as long as it ended in exe
but seemed to be working with some sort of ghost-xml file with new values
AND create a visible xml file that did not track with my config changes.
It was not a case of different names, the file name was a constant, in
only ONE place in the program.

It was as if windows was kidnapping the xml file!! Despite doing a search
telling it to include system32 and all system subdirectories, it would
find any file except xml files, even non-xml files in system32 but it
would not find that file I was seeing right there in front of my face!
Now ain't this strange??

I solved it! I simply included the application path so that the
config.xls file created was SwarmIni.scr.config.xls and then no matter
how I named the extention, the data in the config screen, and that in the
xml file would track.

So, while I never ever did find out what was happening, I did cure it by
specifying the path. I suspect that windows is kidnapping a copy of the
xml file and redirecting things some how. I still can't get search to
find my xml files tho. I have show hidden and show system files turned
on.

I learned three important rules of xml programming ....

1. Always specify a path, never just give it a name and trust it to
create a file in the location you expect, without this bizarre
non-tracking behavior cropping up.

2. Never, ever copy your write method to the read method and change the
name of the method and the code to do the reading. What I did by
accident, was that I had the read method, callling the write method IF
the file did not exist, which was fine and dandy, but in the branch I
executed when the file already existed, I had a read early on and a
spurious DataTable.WriteXml call, but writing an xml file while my xml
helper class was supposed to be reading, and hadn't disposed of the table
doing the reading yet, caused some strange feedback loop to start. My
program would appear to execute, but some process would end up looping,
and my hard drive light would start thrashing like crazy. There was no
visible process, and the every time I ran my saver, everything looked ok,
but my computer would flash, lag, the hard drive would do more and more
thrashing, creating nothing that I could see and all kinds of strange
things would happen which are too many to list ...

3. It is unfortunate that xml is so similar to xls - excel's spreadsheet
extention. I have to be extremely careful not to accidentally name
something as xls instead of xml. In C++ I would have created a global
#define in one place and forget about it, but in C# there isn't such a
thing as a global constant visible throughout all the projects in a
solution, so be careful out there!

4. I am a bit wary about this saving config info in xml format tho. Sure,
it's portable, and its nice to read it and locate values, but it's also
portable to malware that might be able to read those value and change
them, and perhaps cause some sort of havoc by trying buffer over-runs and
other stuff. In other words, I worry about this, that it might create a
security hole here. An ini file I write, could have been in any format,
and could have anything in it in any order, but an xml file, is
predicable, and standard, and makes it an easy pickins target. Don't get
me wrong, I don't dislike xml format. It's great for moving data and
sharing it, but I wonder if it's such a great place to store config info.
I think more security needs to be put into place. Perhaps xml with
encrypted contents?

RambleMode = Off.

--
To reply to this message take off the .NoJunkSpam off of the end of
ga******@pacbell.net.NoJunkSpam


Nov 12 '05 #3

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

Similar topics

35
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another...
4
by: mrw | last post by:
I was wondering how you create that default error beep that you dear when say you go to start, then run, and type in a bad filename. You here a specific sound. It must be some type of API or...
22
by: Stan Weiss | last post by:
I have a program writeen in Microsoft QC 2.5 for DOS which has a very simple interface of using printf and sscanf also gets and puts. Is there an easy way to convert this to Window? Thanks Stan
4
by: timb | last post by:
Hi, I have windows service, in the event of an exception calling (which is important enough to write away to a customer event log) i would like to write away the software version as part of the...
8
by: Comics | last post by:
Does Microsoft remove Win32 from Windows in next Windows release? Does .NET cover low lovel API too?
9
by: Karthikeyan.T.S | last post by:
Hi, I am getting a error when I try to start a Windows Service. The error is "The XYZ service on local computer started and then stopped.Some services stop automatically if they have no work to...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
10
by: deathtospam | last post by:
My employer is starting to take the first steps towards migrating its Classic ASP codebase to ASP.NET v2.0. We have a copy of our existing website on the new Windows Server 2003 R2 test server,...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
30
by: diane | last post by:
I've got an application running with table-based security: i capture the user's windows login with fOsusername, then have them enter a password checked against their username/login in my own table....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.