Solved

CreateFile call failing in Vista C++

Posted on 2009-07-16
5
683 Views
Last Modified: 2013-11-17
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

0
Comment
Question by:acilug
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
Gideon7 earned 250 total points
ID: 24875301
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
 

Author Comment

by:acilug
ID: 24880953
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
 
LVL 12

Expert Comment

by:Gideon7
ID: 24881472
No.
0
 
LVL 2

Expert Comment

by:etking
ID: 25065976
%USERPROFILE%/AppData/Temp might be a problem if user login using guest  account. Try use AllUsers/AppData/Temp file path.

Hope this helps.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now