I am using Windows XP SP II and Visual Studio 2008. I've created a little program that I'd like to run when the computer boots. Here is the code:
// dummy1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include "Windows.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Sleep(5000);
ifstream ins;
ins.open("HelloWorld.txt");
string textToDisplay, outFileName;
getline(ins, outFileName);
getline(ins, textToDisplay);
ins.close();
ofstream outs;
outs.open(outFileName.c_str());
outs << "hello\n";
outs << textToDisplay << endl;
outs.close();
while (true)
{
cout << "hello\n";
cout << textToDisplay << endl;
Sleep(1000);
}
return 0;
}
HelloWorld.txt is a little two line text file:
HelloWorldOutput.txt
Hello World!
I have put the dummy1.exe file into the Windows registry so that it runs at startup time. i get the following results:
hello
hello
hello
etc...
No new file is created and "Hello World!" is not displayed, so it looks like the input file was not successfully opened or read from. However, when I run the program normally (i.e. double click it after the computer has already started up, it runs correctly. The new file is created and the output to the screen is:
hello
Hello World!
hello
Hello World!
hello
Hello World!
etc...
Is there some type of permissions problem? Can a program not use ifstream or ofstream in a Startup program or read or write files or something? If so, is there a way to fix that?
Thanks.