在Vista中利用远程协助

时间:2010-01-20 16:23:34

标签: windows-7 windows-vista remote-desktop

在Windows XP上,有一种已知的方法可以创建远程协助票证。

http://msdn.microsoft.com/en-us/library/ms811079.aspx

但在Vista上,这似乎不起作用。如何在Vista或Windows 7上执行此操作?

1 个答案:

答案 0 :(得分:1)

原来有两种方式。 Microsoft API称为IRASrv,并在此处记录:

http://msdn.microsoft.com/en-us/library/cc240176(PROT.10).aspx

另一种方法是简单地调用msra.exe。使用密码和新手参数(例如msra.exe / saveasfile testfile thepassword)。但是,这会使用密码对话框提示用户。

以下是调用IRASrv接口并生成远程协助连接字符串的示例代码。

COSERVERINFO            si; ::ZeroMemory( &si, sizeof( si ) );
MULTI_QI                qi; ::ZeroMemory( &qi, sizeof( qi ) );

HRESULT hr = S_OK;

BSTR bstrUserName     = SysAllocString(L"jon");
BSTR bstrDomainName   = SysAllocString(L"");
BSTR bstrPasswordStr     = SysAllocString(L"testpass");

// Get the security information entered by the user
_bstr_t bstrUser(bstrUserName);
_bstr_t bstrDomain(bstrDomainName);
_bstr_t bstrPassword(bstrPasswordStr);

// Set AuthIdentity
SEC_WINNT_AUTH_IDENTITY_W AuthIdentity = {
    (unsigned short*)bstrUserName,
    bstrUser.length(),
    (unsigned short*)bstrDomainName,
    bstrDomain.length(),
    (unsigned short*)bstrPasswordStr,
    bstrPassword.length(),
    SEC_WINNT_AUTH_IDENTITY_UNICODE 
};
COAUTHINFO AuthInfo = {
    RPC_C_AUTHN_WINNT, 
    RPC_C_AUTHZ_DEFAULT, 
    NULL, 
    RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // The authentication level used
    RPC_C_IMP_LEVEL_IMPERSONATE, 
    (COAUTHIDENTITY*)&AuthIdentity,
    EOAC_NONE 
};

si.pAuthInfo = &AuthInfo;
si.pwszName = bstrMachineName;
qi.pIID     = &(__uuidof(RAServerLib::IRASrv));

hr = ::CoCreateInstanceEx(
    __uuidof(RAServerLib::RASrv), NULL, CLSCTX_REMOTE_SERVER, 
    &si, 1, &qi );
if (FAILED(hr))
{
    return hr;
}
CComPtr<RAServerLib::IRASrv> prasrv;
hr = qi.pItf->QueryInterface(__uuidof(RAServerLib::IRASrv), (void**)&prasrv);
if (FAILED(hr))
{
    return hr;
}

LPWSTR pstr=NULL;

hr = prasrv->raw_GetNoviceUserInfo(&pstr);
if (FAILED(hr))
{
    return hr;
}
    pstr contains the Remote Assistance Connection String (type 2)