C++ Win32 Schedule Task Fails because of bad XML - c++

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.

Related

MkParseDisplayName returns invalid syntax

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.

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.

Password Expiry Date using c++?

i want to display the password expiry dialogbox using c++ win32 API...
i done it using System.directoryservice namespace...
But now i need in Win32 API..
Any functions there for get password expiry date?
Thanks in advance
You can use the following function to get the password expiration date:
HRESULT GetPasswordExpirationDate(LPTSTR lpszPathName, LPSYSTEMTIME lpExpirationDate)
{
HRESULT hr;
IADsUser *pUser;
hr = ADsGetObject(lpszPathName, IID_IADsUser, (void**) &pUser);
if(SUCCEEDED(hr))
{
DATE expirationDate;
hr = pUser->get_PasswordExpirationDate(&expirationDate);
if (SUCCEEDED(hr))
VariantTimeToSystemTime(expirationDate, lpExpirationDate);
pUser->Release();
}
return hr;
}
Where lpszPathNameis a LDAP or WinNT path and lpExpirationDate is a pointer to SYSTEMTIME structure.
Note, that you must include Windows.h, Iads.h and Adshlp.h and link with ADSIid.Lib and ActiveDS.Lib to get it work.
Example usage:
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
SYSTEMTIME expirationDate;
HRESULT hr = GetPasswordExpirationDate(_T("WinNT://ComputerName/UserName,user"),
&expirationDate);
if (SUCCEEDED(hr))
{
//TODO: do whatever you want with the expirationDate here
}
CoUninitialize();
You may want to use one of the following API calls to retrieve current user and computer/domain names: GetUserName, GetComputerName GetUserNameEx, NetWkstaUserGetInfo
If you need to retrieve password expiration dates for multiple domain users, it might be better to use ADsBuildEnumerator instead of ADsGetObject (see example on MSDN).

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().