Solved

CreateFile call failing in Vista C++

Posted on 2009-07-16
5
686 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…

756 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