Solved

CreateFile call failing in Vista C++

Posted on 2009-07-16
5
681 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now