A
amitmane82@gmail.com
Guest
Hi All
I want to programmatically publish a remote application on
longhorn terminal server.
To do this I have used "Win32_TSPublishedApplication" class of latest
WMI.
But PutInstance() method of IWbemServices fails for this class with
errors "The parameter is incorrect".
I don't have any idea why it fails.
Below is the code
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED (hr))
return 0;
CComPtr<IWbemLocator> pLoc = NULL;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hr))
{
return 0;
}
IWbemServices *pSvc = NULL;
hr = pLoc->ConnectServer(
_bstr_t(L"root\\cimv2\\TerminalServices"),
NULL,
NULL,
0,
NULL,
0,
0,
&pSvc
);
if (FAILED (hr))
return 0;
hr = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED (hr))
return 0;
IWbemClassObject *pclsObj = NULL; //SMS_ST_RecurInterval class
IWbemClassObject *pclsInstObj = NULL; //Instance of
SMS_ST_RecurInterval
hr = pSvc->GetObject(_bstr_t(L"Win32_TSPublishedApplication"), 0,
NULL, &pclsObj, 0);
hr = pclsObj->SpawnInstance(0, &pclsInstObj);
pclsObj->Release();
VARIANT v;
VariantInit(&v);
//Set the name property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"Calculator");
LPCWSTR strClassProp = L"Name";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"calc");
strClassProp = L"Alias";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the path property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"C:\\Windows\\System32\\calc.exe");
strClassProp = L"Path";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the Vpath property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"%SYSTEMDRIVE%\\Windows\\System32\
\calc.exe");
strClassProp = L"VPath";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the Iconpath property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"%SYSTEMDRIVE%\\Windows\\System32\
\calc.exe");
strClassProp = L"IconPath";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the IconIndex property
V_VT(&v) = VT_I4;
v.intVal = 0;
strClassProp = L"IconIndex";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the commandline settings
V_VT(&v) = VT_UINT;
v.uintVal = 0;
strClassProp = L"CommandLineSetting";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the RequiredCommandLine property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"");
strClassProp = L"RequiredCommandLine";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias ShowInPortal settings
V_VT(&v) = VT_BOOL;
v.boolVal = true;
strClassProp = L"ShowInPortal";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias ShowInPortal settings
V_VT(&v) = VT_BOOL;
v.boolVal = true;
strClassProp = L"PathExists";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
hr = pSvc->PutInstance(pclsInstObj, WBEM_FLAG_CREATE_ONLY, NULL,
NULL);
//Here is failes with error "The parameter is incorrect".
if (FAILED (hr))
{
MessageBox (NULL, _T("Failed"),NULL,NULL);
return 0;
}
pclsInstObj->Release();
MessageBox (NULL, _T("Success"),NULL,NULL);
// Clean up.
VariantClear(&v);
Can any one guide me to solve this problem.
Or please tell me if there is any alternative way to programmatically
publish application on Longhorn Terminal server.
Any help will be appreciated
Thanks,
Amit..
I want to programmatically publish a remote application on
longhorn terminal server.
To do this I have used "Win32_TSPublishedApplication" class of latest
WMI.
But PutInstance() method of IWbemServices fails for this class with
errors "The parameter is incorrect".
I don't have any idea why it fails.
Below is the code
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED (hr))
return 0;
CComPtr<IWbemLocator> pLoc = NULL;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hr))
{
return 0;
}
IWbemServices *pSvc = NULL;
hr = pLoc->ConnectServer(
_bstr_t(L"root\\cimv2\\TerminalServices"),
NULL,
NULL,
0,
NULL,
0,
0,
&pSvc
);
if (FAILED (hr))
return 0;
hr = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED (hr))
return 0;
IWbemClassObject *pclsObj = NULL; //SMS_ST_RecurInterval class
IWbemClassObject *pclsInstObj = NULL; //Instance of
SMS_ST_RecurInterval
hr = pSvc->GetObject(_bstr_t(L"Win32_TSPublishedApplication"), 0,
NULL, &pclsObj, 0);
hr = pclsObj->SpawnInstance(0, &pclsInstObj);
pclsObj->Release();
VARIANT v;
VariantInit(&v);
//Set the name property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"Calculator");
LPCWSTR strClassProp = L"Name";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"calc");
strClassProp = L"Alias";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the path property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"C:\\Windows\\System32\\calc.exe");
strClassProp = L"Path";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the Vpath property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"%SYSTEMDRIVE%\\Windows\\System32\
\calc.exe");
strClassProp = L"VPath";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the Iconpath property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"%SYSTEMDRIVE%\\Windows\\System32\
\calc.exe");
strClassProp = L"IconPath";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the IconIndex property
V_VT(&v) = VT_I4;
v.intVal = 0;
strClassProp = L"IconIndex";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the commandline settings
V_VT(&v) = VT_UINT;
v.uintVal = 0;
strClassProp = L"CommandLineSetting";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the RequiredCommandLine property
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = SysAllocString(L"");
strClassProp = L"RequiredCommandLine";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias ShowInPortal settings
V_VT(&v) = VT_BOOL;
v.boolVal = true;
strClassProp = L"ShowInPortal";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
//Set the alias ShowInPortal settings
V_VT(&v) = VT_BOOL;
v.boolVal = true;
strClassProp = L"PathExists";
hr = pclsInstObj->Put(strClassProp, 0, &v, 0);
hr = pSvc->PutInstance(pclsInstObj, WBEM_FLAG_CREATE_ONLY, NULL,
NULL);
//Here is failes with error "The parameter is incorrect".
if (FAILED (hr))
{
MessageBox (NULL, _T("Failed"),NULL,NULL);
return 0;
}
pclsInstObj->Release();
MessageBox (NULL, _T("Success"),NULL,NULL);
// Clean up.
VariantClear(&v);
Can any one guide me to solve this problem.
Or please tell me if there is any alternative way to programmatically
publish application on Longhorn Terminal server.
Any help will be appreciated
Thanks,
Amit..