Solved

CreateFile call failing in Vista C++

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
SqlDataBase 7 48
Graphics 2 30
C# 2008 (3.5 Framework) An object reference is required for the non-static field, method, or property 3 31
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…

809 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