Write to Special Folders [C++/CLI]

How do I write files to special folders such as the Program Files.
?? Just the same way you would with other folders, except that your program needs the special rights: Either the folder allows regular users write access, or your program runs as admin.
I'm on and Admin account and it won't write to Program Files.
Running elevated?
What does "GetLastError()" return to you?

Are you actually entering "C:\Program Files"?

Can we see a section of code?
1
2
3
4
5
6
7
8
			    String^ szGuest_GetFileName = txtbGuestName->Text;                                               //Name the name of the person
				String^ szGuest_FileName = szGuest_GetFileName + ".txt";
				String^ szPath           =  "C:\\Program Files\\Grace_Assembly_Of_God\\";
				
				
				String^ szGuest_FilePath = szPath + szGuest_FileName;
				StreamWriter^ Guest_Records = gcnew StreamWriter(szGuest_FilePath);
		


I know that above it says makes the file, but I tried to remove it on here, but it won't. It's actually the last line that makes the file.
Last edited on
C# != C++
closed account (z05DSL3A)
but that is not c#...its C++/CLI...that is still not C++. :0)

Drue, you have not answered webJoses question, are you running with elevated privileges?

Why are you writing into the program files directory? Would it be better to write to CommonApplicationData or ApplicationData?

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
Last edited on
Sorry, my mistake the first few search results for "StreamWritter()" came back as C#.
Sorry, I was out fishing. I don't know how to use elevated privliges. The reason I need it to write to Program Files, is because, I'm going to end up making an Admin thing for it, and I need to be able to write to a solid spot. I'm thinking of writing the output to my documents.
Right click - run as administrator or use a manifest to require administrator privileges execution level.
I added this line to my manifest

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />


The problem is, even with that enabled, and when i click run as administrator, it still brings up an error box. Right now I have it so you all you need to do is click the work administrator in the menu bar and it creates a file

C:\Program Files\Grace_Assembly_Deployment\Administrator
or something like that.

It makes the file, but it still pulls up the error message. I know there has to be a way to fix this, because some viruses don't even prompt you.

This is the program I'm making.

http://www.megaupload.com/?d=3ZG3T6N8

[EDIT]
It was a stupid, little coding error that the debugger never picked up.
Last edited on
Topic archived. No new replies allowed.