2010-01-20 64 views

回答

1

原來是兩種方式。微軟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) 
+0

您有沒有任何參考資料如何使用「連接字符串2」來啓動遠程連接?你發佈到MSDN的鏈接有很好的信息,但它很難直接。 – Philip 2012-02-09 15:57:46

+0

查看[遠程協助啓動協議規範](http://msdn.microsoft.com/en-us/library/cc240115(v = prot.10).aspx)從查看我爲此所做的代碼,我提取出ID和KH,並使用它們製作XP樣式的請求字符串。 – 2012-02-15 17:35:39