I wrote this simple console program (writeTxt.exe
):
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *fileName = "test.txt";
ofstream outStream(fileName, ios::out);
outStream << "This is a very simple test." << endl;
return 0;
}
Then I run it on the console of Windows Server 2008 using runas
command (I logged-in as a different user from User1
):
runas /user:User1 writeTxt.exe
But the program doesn't produce the file test.txt
. If I log-in to the server as User1
and run the program, it works correctly. Do I have to set something for this to run correctly?
I believe that runas
always launches programs with their working directory set to C:\Windows\System32
(or moral equivalent) rather than whatever your current working directory is when you invoke runas
.
If User1
has permissions to write to that directory, that's where the file will be. If they don't have such a permission, then the program will fail.