通过CreateProcess启动时,cl.exe似乎没有写权限 [英] cl.exe when launched via CreateProcess does not seem to have write permissions

查看:329
本文介绍了通过CreateProcess启动时,cl.exe似乎没有写权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用CreateProcess来启动cl.exe(在Win7 64位上为VS2010).我收到以下错误.

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

cl:命令行错误D8037:无法创建临时il文件;不能创建临时文件.清除旧il文件的临时目录

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

在cmd窗口中使用相同的环境变量成功调用相同的命令行.我已经检查了temp目录,没有旧文件.似乎创建的进程没有写权限.我一直在尝试不同的方法.CreateProcessAsUser,设置安全属性以将所有标准权限授予Everyone用户组,带有或不带有继承句柄,等等.它们似乎都无法修复它.

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.

这是基本代码...

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 );

如果您想知道奇怪的路径,我复制了最少量的必需工具,库等,以直接从cpp文件构建dll.代码中的命令在常规命令行上工作,并且具有在环境变量块中设置的路径.

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.

此外,如果您想知道这是做什么用的,我正在尝试开发一个可以动态重新加载dll的应用程序.该应用程序正在用于调试/可视化,其想法是能够即时调整可视化代码并让该应用程序重新加载dll.

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.

我已经在这里进行了4天的谷歌搜索,并尝试了其他不同的方法.有什么想法吗?

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

推荐答案

发现了问题.

我使用了进程监视器来监视cl.exe,以查看失败的原因. 可以从 http://technet.microsoft.com/zh-cn/sysinternals下载过程监视器/bb896645 .

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.

原来,它无法在Windows系统文件夹中加载rsaenh.dll. cl.exe无法解析%SystemRoot%环境变量.由于我覆盖了环境变量,因此重置了它. 将SystemRoot = c:\ Windows添加到修复它的环境变量中.正确的解决方法是获取当前进程的环境变量,对其进行解析和修改以添加路径,然后将其传递.这样,您将继承所有环境变量.

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.

这篇关于通过CreateProcess启动时,cl.exe似乎没有写权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆