无法使用Visual Studio 2005附加到创建的进程 [英] Unable to attach to created process with Visual Studio 2005

查看:300
本文介绍了无法使用Visual Studio 2005附加到创建的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题附加到从我自己的进程产生的进程。当我尝试使用Visual Studio 2005(调试 - >附加到进程)附加到进程时,我收到错误消息:无法附加到进程。系统找不到指定的文件。

I'm having problems attaching to a process spawned from one of my own processes. When I attempt to attach to the process using Visual Studio 2005 (Debug -> Attach to process) I receive the error message: "Unable to attach to the process. The system cannot find the file specified."

在我的程序中,我使用命令生成了我以后要附加到的进程。

In my program, I spawned the process that I later want to attach to using the command

BOOL res = CreateProcess(exe, cmdLine, NULL, NULL, FALSE, 0, NULL,
                         workingDir, &startupInfo, &procInfo);

如果我从命令提示符手动启动第二个进程,我可以附加到它没有任何问题。我也可以使用WinDbg,只是不是Visual Studio 2005附加到它。没有什么区别,是否已从VS启动第一个进程(因此作为管理员运行)或如果我从命令提示符启动它作为普通用户。我在Vista下运行Visual Studio作为管理员64位和可执行文件都是64位。

If I manually start the second process from the command prompt, I can attach to it without any problems. I am also able to attach to it using WinDbg, just not Visual Studio 2005. There is no difference whether I've started the first process from within VS (thus running as an administrator) or if I've started it from the command prompt as a regular user. I am running Visual Studio as an administrator under Vista 64 bit and the executables are all 64-bit.

有没有人看过这个或有什么我可能是做错了?

Has anyone seen this before or have any ideas of what I might be doing wrong? Any help is appreciated.

更新:
我还尝试使用以下代码设置新进程和线程的安全属性:

Update: I've also tried to set the security attributes for the new process and thread using the following code:

DWORD dwRes, dwDisposition;
PSID pEveryoneSID = NULL, pAdminSID = NULL;
PACL pACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;
EXPLICIT_ACCESS ea[2];
SID_IDENTIFIER_AUTHORITY SIDAuthWorld =
    SECURITY_WORLD_SID_AUTHORITY;
SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY;
SECURITY_ATTRIBUTES sa;
LONG lRes;
HKEY hkSub = NULL;

// Create a well-known SID for the Everyone group.
if(!AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID,
    0, 0, 0, 0, 0, 0, 0, &pEveryoneSID))
{...}

// Initialize an EXPLICIT_ACCESS structure for an ACE.
// The ACE will allow Everyone read access to the key.
ZeroMemory(&ea, 2 * sizeof(EXPLICIT_ACCESS));
ea[0].grfAccessPermissions = GENERIC_ALL;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName  = (LPTSTR) pEveryoneSID;

// Create a SID for the BUILTIN\Administrators group.
if(! AllocateAndInitializeSid(&SIDAuthNT, 2, SECURITY_BUILTIN_DOMAIN_RID,
    DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdminSID)) 
{...}

// Initialize an EXPLICIT_ACCESS structure for an ACE.
// The ACE will allow the Administrators group full access to
// the key.
ea[1].grfAccessPermissions = GENERIC_ALL;
ea[1].grfAccessMode = SET_ACCESS;
ea[1].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;
ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
ea[1].Trustee.ptstrName  = (LPTSTR) pAdminSID;

// Create a new ACL that contains the new ACEs.
dwRes = SetEntriesInAcl(2, ea, NULL, &pACL);
if (ERROR_SUCCESS != dwRes) 
{...}

// Initialize a security descriptor.  
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); 
if (NULL == pSD) 
{...} 

if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) 
{...} 

// Add the ACL to the security descriptor. 
if (!SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE))
{...} 

// Initialize a security attributes structure.
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;

    CreateProcess(exe, cmdLine, &sa, &sa, ...


$ b b

没有运气。

with no luck.

更新:我也可以使用Visual Studio 2008附加到进程),这解决了我的迫切需要。由于这是在Vista x64,可以有一些形式的Vista魔术在这里玩,在这里VS2005不玩Vista漂亮吗?为什么这种情况只有我的从我的代码构建和启动我不能真正理解...

Update: I am also able to attach to the process using Visual Studio 2008 (still compiled using VS2005), which solves my immediate needs. Since this is under Vista x64, could there be some form of "Vista magic" at play here, where VS2005 does not play nice with Vista? Why this is the case only for processes that I've built and started from my code I cannot really understand...

推荐答案

好的,我终于找到了什么导致这个问题如果任何人遇到这种情况(从稀缺的答案,我想这不是很常见,但嘿...)。

Ok, I finally found out what caused this problem. I'll post it here in case anyone else encounters this (from the scarcity of answers I guess it ain't that common, but hey...).

问题是用于启动可执行文件的路径包含由单个点组成的路径元素,如下所示:

The problem was that the path used to launch the executable contained a path element consisting of a single dot, like this:

c:\dir1\.\dir2\program.exe

这显然使VS2005去寻找可执行文件

which apparently made VS2005 go look for an executable at

c:\dir1\dir1\dir2\program.exe

当然不存在...谢谢Mark为 Process Monitor !删除。按照预期再次进行过程工作。

that of course does not exist... Thank you Mark for Process Monitor! Removing the . made attaching to the process work as expected again.

这篇关于无法使用Visual Studio 2005附加到创建的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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