Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, all!
I find a question about the CStdioFile & "Run".
I registered my application to "Run" which allowed the application implemented automatically after turning on the computer.
It works till I added the file read/write through the CStdioFile class...
My application cannot implement automatically when I turn on computer, but the register is still exist inside the "run" table:(

my snippet code:

C++
BOOL CShutdownTurnOnEventDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			
	SetIcon(m_hIcon, FALSE);		

	// TODO:  My code
    //register the computer to "Run"(If anyone interested, I can provide it:))
	AutoRunApp(true); 

	//Write file
	CStdioFile file;
	file.Open(_T("ActionLog.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
	file.WriteString(_T("Computer Turn On\n"));
	file.Close();

	return TRUE;
}


Would anyone provides some suggestion?

Appreciated!!
Posted
Comments
Richard MacCutchan 18-Nov-15 4:21am    
Most likely you do not have access to the startup directory for this application when automatically started. You should use a fixed location that allows you to create files.
Member 10307999 18-Nov-15 23:02pm    
MacCutchan, Thanks for your reply and it give me a inspiration! Finally, I set the path of the ActionLog.txt to C:\ProgramData and it works!! Thank you again!!

1 solution

MacCutchan, Thanks for your reply and it give me a inspiration! Finally, I set the path of the ActionLog.txt to C:\ProgramData and it works!! Thank you again!!
 
Share this answer
 
Comments
Dave Kreskowiak 18-Nov-15 23:20pm    
Running your application out of the Run key in the Registry does not start your application on startup. It starts your application when a user logs into the console. The application is then executed as the person who logged in.

Normal users cannot write files to certain locations in the directory structure, such as anything under Program Files or the root of the drives. The ProgramData folder is a "public" folder that allows users to write stuff that all users on the machine can access. That's why your app suddenly works when you changed the filepath to something under ProgramData.
Member 10307999 19-Nov-15 1:49am    
Thank you, Kreskowiak! Your explanation let me understand more clearer!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900