Page 1 of 1

windows file i/o startup

Posted: Sun Feb 23, 2003 9:46 pm
by fstream
ok, so i have written 2 programs now that both start up when windows starts up, however, they both need file i/o on startup, they both work PERFECTLY cept for the file i/o bit. Ok so here is how it works. I place in HKEY_LOCAL_MACHINE software\microsoft\windows\currentversion\run (the usual place) my key, and the value to where my program is. The problem is not wiht that, the program does start when windows starts, HOWEVER, when it looks for the files, it cannot find them. But when it closes, and i go to the folder where my program is and run it, it runs fine. After some messing around i found that no matter where i specify my program to find the files, .//filename, C:\\Program Files\\folder\\filename, it would no matter what save and read from c:documents and settings\username. but when it closed and i ran the program from the folder it is in, it works fine and does the file i/o from the folder itself. so far i have tried doing the API file io (the CreateFile() function) and any little thing i can find. i open a file with ifstream in; in.open("name.txt"); and if i check to see if the file is loaded, unless it is in C:\documents and settings\username, it doesnt load. Any reason why (is it so simple its in front of my nose?)

Re:windows file i/o startup

Posted: Mon Feb 24, 2003 4:30 pm
by Tim
Unless you specify a full path in your open call, you're unlikely to find the file. The Run key doesn't give you any way of specifying the current working directory for a program, as far as I know.

Re:windows file i/o startup

Posted: Mon Feb 24, 2003 10:35 pm
by fstream
i did try that, like i did ifstream in; in.open("C:\\Program Files\\init.ini") and even put my program in C: and did in.open("C:\\init.ini"); and it would still look in C:\documents and settings\username. even in.open(".\\init.ini"). i just get soo frustrated because when i open it without having it open when windows starts, it works 100% fine.

Re:windows file i/o startup

Posted: Mon Feb 24, 2003 10:54 pm
by fstream
ok well i dont know what in the world i did, i just got home after a 10hr day at work, booted up the prog, and it works 100%. :-\ well thanx for the help. sorry to waste ur time. lol