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

查看:304
本文介绍了无法使用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中启动了第一个进程(因此以管理员身份运行),或者我是从命令提示符启动的作为普通用户。我正在运行Visual Studio作为Vista 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 $

with no luck.

更新:我也可以使用Visual Studio 2008附加到该进程(仍然使用VS2005编译),这可以解决我的迫切需求,因为这是Vista x64,在这里玩VS2005可能会有某种形式的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

当然不存在...谢谢马克过程监视器!删除。根据预期再次附加到流程工作。

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天全站免登陆