Exception Access Violation on Vista

BlitzMax Forums/BlitzMax Programming/Exception Access Violation on Vista

ImaginaryHuman(Posted 2011) [#1]
I'm trying to somehow get a new image file into the C:\Windows\Web\Wallpaper\ folder, with User Account Control switched on on Vista. I understand the whole UAC thing - turning it off is not an option in this case, nor is using a manifest to get admin rights or using certain filenames, it has to run in user mode not admin.

I find that at least I can read the folder and open files that are already there without any problem.

When I try to open a stream to write a file in that folder I get an exception access violation.

When I use SavePixmapPNG to save a file there it does not throw an exception but the file is not written (there, anyway).

When I use CopyFile to copy an existing file into the folder it does not get copied (there, anyway) and no exception is thrown.

What I hope to do is at least try to write or copy the image to the folder and then check if it exists there and if not put it in a personal or public folder instead - I set the wallpaper via the registry.

My question is, is the above behavior typical/consistent for other people? Do you get no exception window pop up when you do a copyfile or savepixmappng, but you do when writing a stream?

Last edited 2011


ImaginaryHuman(Posted 2011) [#2]
I guess the pixmap and copyfile are working but it's being virtualized...

From another thread... "Attempting to create or write a file or directory under a folder which does not grant write permission to the process will fail under Windows Vista if the application does not have administrative privileges. If your 32-bit game executable is running in legacy mode, because it did not declare a requested execution level, its write operations will succeed, but they will be subjected to virtualization as described in the section "UAC Compatibility with Older Games" later in this article."

So long as it does this and I check if the file exists in C:\Windows\Web\Wallpaper\ after I write it, and if it's not in that folder, then I can just write it to common data or personal data folders and go from there.

I just want to make sure it isn't going to throw an exception violation, or wondering why it does one when you try to make a write stream?


ziggy(Posted 2011) [#3]
well, you should never be writting to the windows fodler, unless your program is an installer of some kind and has the appropriate permissions. That's not allowed in windows any more.


GfK(Posted 2011) [#4]
I don't know about getting an EAV when attempting to create a stream and in all honest I can't be bothered to turn on UAC, reboot, and try it myself - are you just using WriteFile or using Try/Catch etc?

Programs should never be writing to system folders anyway - its always been that way. The only difference is that Microsoft really began to insist on that from Vista onwards. You're much better off complying with standards and using either the user's appdata folder, or common app data. Code in the code archives to get either.


ImaginaryHuman(Posted 2011) [#5]
Understood.

The folder I'm writing to is the one where standard wallpapers are kept - C:\Windows\Web\Wallpaper.

I know Microsoft's policy but it's a bit strange they would put non-threatening image files in a protected part of the system where you can't even write new images. So when people go to set their wallpaper they're not going to see their wallpaper collection. It's kinda goofy.

I think what I'll do is try to either SavePixmapPNG or CopyFile to the folder, then read the folder to see if the file was virtualized (ie not there), then if so put the wallpaper in a public/personal folder and refer to it from there. That part is not a problem.

My only concern is really whether I can rely on there not being an exception access violation message box pop up when I do this.


Grey Alien(Posted 2011) [#6]
I just store the image to be wallpaper in my game's shared data folder then call SystemParametersInfo which sets it. Don't know if that makes a copy of it in there too.

btw, have you found a way to set wallpaper on MacOS?


GfK(Posted 2011) [#7]
btw, have you found a way to set wallpaper on MacOS?
Me? No. Wanted that feature in Magicville (its in the PC version) but I ended up taking it out for Mac because I had no idea how to do it.


BlitzSupport(Posted 2011) [#8]

have you found a way to set wallpaper on MacOS?



The second post here seems to suggest a way. Don't know the first thing about direct OS X programming or the horrible ObjectiveC!


ImaginaryHuman(Posted 2011) [#9]
No idea about OSX wallpaper, yet.


Muttley(Posted 2011) [#10]
On Windows Vista and 7 you should be storing it in the user's Pictures folder I think:

%USERPROFILE%\Pictures


Grey Alien(Posted 2011) [#11]
Thanks James, my OSX programming skills are next to none to so that post doesn't make any sense sadly.


ImaginaryHuman(Posted 2011) [#12]
Yes, I plan to store it in MyPictures (CSIDL_MYPICTURES?) if it gets virtualized when storing it in Web/Wallpaper.