MkParseDisplayName returns invalid syntax - mfc

I'm struggling with something that should be simple, I want to create a moniker with a specific display name (e.g. "MyApplicationMnk")
I need this moniker to bind it to an EXE application registered in the Windows registry as LOCAL SERVER type to register it in the Running Object Table (aka. ROT)
the COM function MkParseDisplayName returns invalid syntax error, the only source I found that mentioned a solution to this issue doesn't work with me.
The code is as simple as the following
IMoniker* appmnk;
HRESULT hr;
CComPtr<IBindCtx> bct;
DWORD wctx = 0;
ULONG ulng = 0L;
CreateBindCtx(wctx, &bct);
OLECHAR dspnm = (wchar_t)"MyApplicationMnk";
LPCOLESTR dspnmptr = &dspnm;
hr = MkParseDisplayName(bct, dspnmptr, &ulng, &appmnk); // returns invalid syntax
.
.
//some code
.
.
appmnk->Release();
I've tried to insert the value directly like this
hr = MkParseDisplayName(bct, OLESTR("MyApplicationMnk"), &ulng, &appmnk);
and with the above-mentioned proposed solution like this
hr = MkParseDisplayName(bct, (wchar_t *)(_bstr_t)(char *)"MyApplicationMnk", &ulng, &appmnk);
I don't know what's wrong!, all the supplied types match what's said in the documentation.
Any help will be definitely appreciated.

Related

How to create IADsUser Object and get the Users details like Email

I'm Using LDAP and ADSI.
IADsContainer* padsCont = NULL;
hr = ADsGetObject(CONVERTCSTR(szAdsServer), IID_IADsContainer,(LPVOID*)&padsCont);
CoUninitialize();
IADs* pADs;
hr = padsCont->QueryInterface(IID_IADs, (void**)&pADs);
//IADs Interface does not have email but IADsUser has email method/Property which I required. If I pass IADsUser pointer to QueryInterface like
IADsUser* pADsUser;
hr = padsCont->QueryInterface(IID_IADsUser, (void**)&pADsUser);
Getting an error E_Interface not Supported.
Could any one help on this. Please ask if need anything to understand clearly
Thanks in advance.
umar

How do I use the WIC API to read/write custom EXIF data?

I have gone through the documentation at:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee719799(v=vs.85).aspx
As context, I am trying to encode in the JPEG-XR format and I want to emulate GDI+'s SetPropertyItem, GetPropertyItem functionality.
I basically have 3 questions:
If I want to add a custom property to the exif header what is the correct query path?
Can I use a custom ID, say {ushort=1111} to identify it and how do I verify if an ID is already defined?
Is this the same as the id field of GdiPlus::PropertyItem?
For example, is the following valid:
PROPVARIANT value;
value.vt = VT_LPWSTR;
value.pwszVal= L"Metadata Test";
hr = piFrameQWriter->SetMetadataByName(L"/ifd/exif/{ushort=1111}");
This code block succeeds, but when I try to read back the same metadata using:
IWICMetadataQueryReader *pQueryReader = NULL;
if(SUCCEEDED(hr))
{
hr = piFrame->GetMetadataQueryReader(&pQueryReader);
}
if (SUCCEEDED(hr))
{
PROPVARIANT value;
hr = pQueryReader->GetMetadataByName(L"/ifd/exif/{ushort=1111}", &value);
}
This returns E_INVALIDARG error.
I'd appreciate some help in understanding how this works. I feel like I have not understood the documentation correctly.
Thank you.

How to convert this LDAP code from VBS to C++

I'm trying to come up with a C++ code to enumerate groups that the current workstation is a member of in an Active Directory set-up. I was able to come up with the following Visual Basic script that does exactly what I need:
'DN for the workstation
cCN = "CN=WorkstationName,CN=Computers,DC=mydomain,DC=local"
Set objComputer=GetObject("LDAP://" & cCN)
Dim strAll
Dim colGroups, objGroup
strAll = ""
Set colGroups = objComputer.Groups
For Each objGroup In colGroups
strAll = strAll & objGroup.distinguishedName & vbLf
Next
Wscript.Echo strAll
and I receive the output as such:
CN=Group1,OU=SomeOU,DC=mydomain,DC=local
CN=Group2,OU=SomeOU,DC=mydomain,DC=local
The issue is that I can't seem to convert the LDAP stuff to C++.
I'd really appreciate if someone can help me out?
EDIT: The following is as much as I can glean from my C++ knowledge and COM:
// Initialize COM.
CoInitialize(NULL);
LPCTSTR pwszContainerDN = L"CN=WorkstationName,CN=Computers,DC=mydomain,DC=local";
CComBSTR strADsPath = L"LDAP://";
strADsPath += pwszContainerDN;
IADs *objComputer;
HRESULT hr;
hr = ADsGetObject(strADsPath,
IID_IADs,
(void**) &objComputer);
if(SUCCEEDED(hr))
{
//Now how do you do "objComputer.Groups"?
//Then later "For Each" enumeration, etc.?
}
// Uninitialize COM.
CoUninitialize();
You can also use WinLDAP library. See this LDAP Search with winldap.h on AD Server.

C++ Win32 Schedule Task Fails because of bad XML

I am fiddling with the Windows Task Scheduler & attempting to schedule a task to execute when I log in.
So I have copied & pasted the exact example code from MSDN on how to do this - http://msdn.microsoft.com/en-us/library/aa381911(v=VS.85).aspx - I have specified my user name & my password in the code example. When I run it I get the error "Failed to save task: 80041318"
Thanks to people in another question I made I now know this error means:
The task XML contains a value which is incorrectly formatted or out of range
Now I dont know what this means, what am I doing incorrectly in my code, especially when 99% is a direct copy of the example MSDN code?
Maybe I need to format my username & password correctly because they are BSTR or VARIANT's?
I will post only the changes I made to the code but to see the whole code go to http://msdn.microsoft.com/en-us/library/aa381911(v=VS.85).aspx:
hr = pLogonTrigger->put_UserId( _bstr_t( L"soribo" ) ); // soribo is my username
pLogonTrigger->Release(); // line 221
hr = pRootFolder->RegisterTaskDefinition( // line 289
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(L"soribo"), // put in my windows username again (I'm the admin)
_variant_t(L"XXXXXX"), // put in my user password & no its not really XXXXXX :P
TASK_LOGON_GROUP,
_variant_t(L""),
&pRegisteredTask);
I dont understand where XML comes in because this is C++ Win32 code?
EDIT: Showing pTask related code: note I didn't change any of this, so its the example code from MSDN
// Create the task builder object to create the task.
ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );
pService->Release(); // COM clean up. Pointer is no longer used.
if (FAILED(hr))
{
printf("Failed to create a task definition: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}
I am not sure if this is the cause of your error, but looking at the documentation of ITaskFolder::RegisterTaskDefinition and your code:
hr = pRootFolder->RegisterTaskDefinition( // line 289
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(L"soribo"), // put in my windows username again (I'm the admin)
_variant_t(L"XXXXXX"), // put in my user password & no its not really XXXXXX :P
TASK_LOGON_GROUP,
_variant_t(L""),
&pRegisteredTask);
I see you are using TASK_LOGON_GROUP, but pass an username password. If you use TASK_LOGON_GROUP, you should probably use a name of a group (like L"Builtin\\Administrators" or L"S-1-5-32-545") and VT_NULL for the password.

How to delete IE addressbar history on Vista/Win7?

First, here is a picture of what I see
http://img713.imageshack.us/img713/4797/iedrop.png
I need an solution to clear addressbar dropdawn, but not using ClearMyTracksByProcess or IE dialogs. I need to delete only a specific URL and all his traces.
I deleted manually all traces of that URL in:
Users\\AppData\Local\Microsoft\Windows\Temporary Internet Files*
Users\\AppData\Local\Microsoft\Windows\History*
Users\\Recent*
also that URL can be found in:
4) Users\\AppData\Local\Microsoft\Internet Explorer\Recovery\High
Now I made an BootTime program that searches for 8 and 16 bit charsets string in all my system disc files. URL wasn't found anywhere, but after logging and starting IE, the URL is still there. I suspect this is related to 4), but can't understand how.
Finally I found solution.
HRESULT CreateCatalogManager(ISearchCatalogManager **ppSearchCatalogManager)
{
*ppSearchCatalogManager = NULL;
ISearchManager *pSearchManager;
HRESULT hr = CoCreateInstance(CLSID_CSearchManager, NULL, CLSCTX_SERVER, IID_PPV_ARGS(&pSearchManager));
if (SUCCEEDED(hr))
{
hr = pSearchManager->GetCatalog(L"SystemIndex", ppSearchCatalogManager);
pSearchManager->Release();
}
return hr;
}
{
ISearchCatalogManager *pCatalogManager;
HRESULT hr = CreateCatalogManager(&pCatalogManager);
if (SUCCEEDED(hr))
{
pCatalogManager->Reset();
pCatalogManager->Release();
}
}
Address bar urls are stored in the TypedUrls registry key. See this project which claims to enum and delete them (I haven't tested it).
The History items in the dropdown are stored in the Url History database. Use IUrlHistoryStg::DeleteUrl().