Win2000 file writing?

Started by
5 comments, last by BliGH 22 years, 3 months ago
Hello, I have a report of a problem running my game on Windows 2000 and was wondering if anyone had run into something like this. Heres the low down: A user logs in (not with administration rights) installs and plays the game with no problems when they double click on the exe in explorer but, if they try to make a shortcut on the desktop and run it from there - the machine reboots at the point in the game when the scores are read and updated. I don''t have WIN2000 handy so it''s hard for me to test any solutions. I have a hunch it might have something to do with file-writing priviledges? I made a few untested changes so far: - Manually change the directory path with GetModuleFileName() and _chdir(). I don''t think this will help as the path seems right when I''m reading files. - Checking to make sure the file is open properly before writing to it, I know I should always do this - it might stop the reboots but the scores still won''t work properly. If anyone has any insight into why this could be happening it would be greatly appreciated.
Advertisement
Were you making the (incorrect) assumption that the place the .exe is run from is the currently set directory ?

The GetModuleFilename() and _chdir() should fix that, although generally you shouldn''t make that assumption about what the "current" directory is - as soon as someone tries to run it from a "virtual" directory you''re screwed. *

What you should do is GetModuleFilename(), strip the .exe name from that path and prepend that path to ALL file reads you do. If you''ve wrapped your file access it''s a 2 minute job and ensures your game will load from anywhere (e.g. we''ve had our stuff running from a shortcut to a shared folder over the network).

As for writing files, because of different user privelages and accounts, normal users often won''t be allowed to write to the Program Files folder, also the names of those folders can''t be assumed. What you should do is call SHGetFolderPath()/SHGetSpecialFolderLocation() to find out where data can be stored for this user. This stuff gets even more important under XP where you have fast user switching etc.

The reset is what NT kernels are configured to do instead of a blue screen (imagine the unattended server - sat there at a blue screen leaves it a tad vunerable and unavailable, at least the reset leaves it on the "safe" login prompt). This can be changed by the adminstrator.


[*]I wrote the menu for the Vector OEM games compendium CD which went out with a few mobos and GeForce cards - one game in particular was *very* annoying because its custom installer assumed that the current directory was the same as the running process directory - what it didn''t account for was that the running process was my launcher menu which lived elsewhere on the CD, and that it was a child process. The equivilent of GetModuleFilename and _chdir() in the menu did indeed fix the problem. <br><br>–<br>Simon O''''Connor<br>Creative Asylum Ltd<br><A HREF="http://www.creative-asylum.com">www.creative-asylum.com</A>

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Damn I hate that! - I wrote out a big reply but had my password wrong and the whole thing was erased - oh well here goes again ( in notepad first

Thanks for your reply, that''s a good point about appending the filenames to a full path, I had to do that on a previous program that had both a ''full'' and a ''lite with cd'' install type. I added that to my current program but am not convinced that it''s the culprit. All of my other files load properly with a local path ie: images\boobies.jpg, so I would reason (dangerous I know that the current directory is correct. For the file-writing priviledges , I find it mysterious how if the game is executed from the start menu folder or the explorer the writing works properly but, from a user-made shortcut it will kill the system?
Here''s an added twist to the story: I named the score file that I''m writing to with a ''scary'' name (sys.dat) with the hopes that a user would be scared to mess with it, could the system somehow not like me accessing a file with that name? I''m going to change it just in case

Thanks,
RaLpH

PS: If anyone wants to check out the game it''s available at : www.connectorb.com
sys.dat is very close to the name of quite an important hidden file system.dat which contains the registry for HKEY_LOCAL_MACHINE and HKEY_CLASSES.

You could always register a filetype for any non-editable datatypes and give the filetype the icon from your game. You can then set up the "open" and "edit" verbs for that type to launch your game. Then it''d also be safe to use SHGetFolderPath and bung the files in the users My Documents folder.

That''s what MS were advising developers to do with user data files such as saved games etc for maximum compatibility on current and future OSes at Meltdown. They cited Max Payne as an example of a game which does it right.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

That''s a good idea about using the documents folder - I remember now seeing my Max Payne saved games there I guess it would be safe to create my own subfolder in there? I just want to make sure that people don''t erase my files by mistake and then wonder what happened to their scores. Thanks for your help.

Ralph Povilaitis
http://www.connectorb.com
Check out the slides from Meltdown, in particular the Windows XP talk from Mike Burrows (I was at the UK one, someone else may have presented the US/Japanese ones).

The slides with the details of how to register your own file type and the correct way to use the users document folder are at:

http://www.microsoft.com/mscorp/corpevents/meltdown2001/presentations.asp





--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Thanks for the info. I made the changes but, now I have another problem on another tester''s machine! It''s running the original win95 and I guess it doesn''t have IE4+ installed so the program returns an error:
file is linked to missing
export SHELL32.DLL:SHGetSpecialFolderPathA.

I read up on this function and on win95 it only gets installed when you upgrade to IE4. What a lot of problems just to make a simple thing like this work!

This topic is closed to new replies.

Advertisement