cl.exe when launched via CreateProcess does not seem to have write permissions

倖福魔咒の 提交于 2020-01-24 11:27:04

问题


I'm calling CreateProcess to launch cl.exe (VS2010 on Win7 64 bit). I get the following error..

cl : Command line error D8037 : cannot create temporary il file; clean temp directory of old il files

Calling the same command line with the same environment variables in a cmd window succeeds. I've checked the temp directory and there are no old files. It seems like the process that is created does not have write permissions. I've been trying different approaches.. CreateProcessAsUser, Set the security attributes to grant all standard permissions to the Everyone user group, with and without inheriting handles, etc. None of them seem to fix it.

And here's the basic code...

SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof( SECURITY_ATTRIBUTES );
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;

const char* _szSourceFile = "c:\\temp\\test\\src\\foo.cpp";

char szOptions[ 2048 ];
sprintf_s( szOptions, 
    "c:\\temp\\compile\\cl.exe "
    "/Gd "
    "/Fo\"c:\\temp\\test\\out\\\" "
    "/Fe\"c:\\temp\\test\\out\\\" "
    "/Fd\"c:\\temp\\test\\out\\\" "
    "/D \"WIN32\" "
    "/D \"_DEBUG\" "
    "/D \"_WINDOWS\" "
    "/D \"_USRDLL\" "
    "/D \"_WINDLL\" "
    "/D \"_MBCS\" "
    "/I\"c:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Include\" "
    "/MDd "
    "/I\"c:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\" "
    "/LDd "
    "%s "
    "c:\\temp\\test\\lib\\Uuid.Lib "
    "c:\\temp\\test\\lib\\oldnames.lib "
    "c:\\temp\\test\\lib\\msvcrtd.lib"
    , _szSourceFile );


STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof( STARTUPINFO ) );
ZeroMemory( &pi, sizeof( PROCESS_INFORMATION ) );
si.cb = sizeof( STARTUPINFO );

BOOL bSucceeded = CreateProcess( "c:\\temp\\compile\\cl.exe", szOptions, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, "PATH=c:\\temp\\Compile;%PATH%\0TEMP=c:\\temp\\test\\tmp\0\0", "c:\\temp\\test\\", &si, &pi );

In case you're wondering about the weird paths, I copied over the most minimal set of required tools, libs, etc to build a dll directly from a cpp file. The command in the code works on a regular command line with the path that is set in the enviroment variables block.

Also, in case you're wondering what this is for, I'm trying to have an app that can dynamically reload a dll. The app is being used for debugging/visualization and the idea is to be able to tweak the visualization code on the fly and have the app reload the dll.

I've been at this for 4 days googling and trying out different things. Any ideas?


回答1:


Found the issue.

I used the Process Monitor to monitor cl.exe to see what was failing. Process monitor can be downloaded from http://technet.microsoft.com/en-us/sysinternals/bb896645.

Turns out that it was failing to load rsaenh.dll in the windows system folder. cl.exe could not resolve %SystemRoot% environment variable. Since I was overriding the environment variables, it got reset. Adding SystemRoot=c:\Windows to the environment variables fixed it. The proper fix would be to get the environment variables for the current process, parse and modify it to make your path additions and then pass that in. That way you inherit all the environment variables.



来源:https://stackoverflow.com/questions/10560779/cl-exe-when-launched-via-createprocess-does-not-seem-to-have-write-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!