CreateFile call failing in Vista C++

Hi all,

I have a call in an old C++ application calling the CreateFile API command to create a temporary file on the drive.
This command works fine up until Vista.
I have also tried chaning the TMP environment variable to c or c/temp and then this call fails
StgCreateDocfile

do you have any ideas which directory I can get my old code to write to without making many changes?
BEFORE CHANGE OF TMP ENVIRONMENT VARIABLE
 
	 HANDLE OLE2FileHandle = CreateFile(fileBuf,
									 GENERIC_READ|GENERIC_WRITE,
									 FILE_SHARE_READ|FILE_SHARE_WRITE,
									 NULL,
									 CREATE_ALWAYS,
									 FILE_ATTRIBUTE_NORMAL, //| FILE_FLAG_DELETE_ON_CLOSE,
									 NULL);
	 if (OLE2FileHandle == INVALID_HANDLE_VALUE)
	 {
 error message comes here
 
 
 
SECOND ERROR AFTER CHANGE OF TMP
 
  //       easier to do error handling in case the call fails.
HRESULT hresult = StgCreateDocfile(getFileStr.getsUnicode(), // OLE2 API Call
						 	  STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE,
							  0,
							  &lpStorage);

Open in new window

acilugAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gideon7Commented:
Beginning with Vista, ordinary non-privileged users can no longer write willy-nilly into the root C:\ folder on NTFS.   Ditto administrators w/o UAC elevation.
The %TEMP% and %TMP% environment variables should point to a private per-user folder that is writable for temporary files.  Use that.
A manually-created C:\TEMP will not be writable to normal users unless you change permissions.  Dont do that -- it is bad security practice to share writable public folders between users.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
acilugAuthor Commented:
Hi Gideon and all,

TMP and TEMP are already point to %USERPROFILE%/AppData/Temp (Vista standard), so this should be okay. Would you have any other ideas?

Thanks,
Thomas
0
Gideon7Commented:
No.
0
etkingCommented:
%USERPROFILE%/AppData/Temp might be a problem if user login using guest  account. Try use AllUsers/AppData/Temp file path.

Hope this helps.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.