-2

I have a C++ program I created in visual studio and has issues when I save it on the server (to run as an .exe. The server doesn't have VS, so I tried it as an .exe. The program creates .txt file (or if one exists, it will overwrite it) and emails that new file as an attachment. Here's where it goes haywire: I can double click on the program and it will create a .txt and send the email off, but if I have the task scheduler do it, it will not overwrite the .txt file (or even create a new .txt file if I delete the current one). If the old .txt file is there, the program will attach that file and send the email off.

So, I'm wondering if there's another way to have this program work?

The server is Microsoft Sql Server 2008

Charles
  • 48,924
  • 13
  • 96
  • 136

2 Answers2

2

You probably don't have permission to overwrite an existing file. Make sure the directory you are reading and writing to isn't protected. For example, don't have it in Program Files unless you give your program higher privileges.

Jamin Grey
  • 8,807
  • 4
  • 35
  • 48
  • I can double click on the file and create a new one or overwrite one. If I delete the file, the task scheduler will not create a new .txt file. – vendetta1 May 02 '13 at 20:16
  • 2
    You, as the administrator, can create/delete/overwrite the file. You as the administrator, can manually run a program that can create/delete/overwrite the file. But are you sure the Task Scheduler executing your program as a different "user" allows your program to create/delete/overwrite the file? – Jamin Grey May 02 '13 at 21:05
  • 2
    My knowledge of user access privileges is very very slight... but isn't the task scheduler executing programs as a different user (i.e. not running every program as admin by default)? **Case A**: You can create the files manually. **Case B**: You can run the program and the files get created. **Case C**: The Task Scheduler is running the program and the fjles aren't getting created. – Jamin Grey May 02 '13 at 21:05
  • Well, the folder allows read/write access for everybody. I don't know about "who" the task scheduler is though. – vendetta1 May 02 '13 at 22:01
1

Most probably you don't have the working directory of the program set correctly. Your file is probably created, but somewhere else in the FileSystem, not where your program is located.

This question deals with the issue

Community
  • 1
  • 1
Eric
  • 18,532
  • 17
  • 78
  • 138
  • did you see the part about if I double click on the program the file is created? It appears right next to the program when I double click on it. – vendetta1 May 02 '13 at 20:08
  • When you double click, it executes from the current directory, when it is called by another program it is not as certain – Eric May 02 '13 at 20:15
  • The save path is written inside the program. The scheduler is the task scheduler that is part of the server in case you were thinking another program I wrote is doing the scheduling. – vendetta1 May 02 '13 at 20:19
  • You have the full path written in the program? Is the file writing the only part of the program that fails? Also the task scheduler has a run as option, are you sure this is set correctly? – Eric May 02 '13 at 20:30
  • Yep, the full path is written in the program. And yes, the file writing is the only part that fails. If a previous file is already there, the email will send no problem. I don't see run as an option anywhere. There are actions available: Start a program, Send an email, and Display a message. – vendetta1 May 02 '13 at 21:52