rootElement->FindFirst(...) fails to find element seen by Inspect - c++

I'm trying to locate a list item contained within the Services window (Start->Run->Services.msc) on Windows. The list item is named "Arc Service" and is easily found using Inspect, but my code fails to locate it. This being a relatively simple case, I feel I must be doing something wrong.
The code in question is:
VARIANT arcServiceNameVariant;
VariantInit(&arcServiceNameVariant);
arcServiceNameVariant.vt = VT_BSTR;
arcServiceNameVariant.bstrVal = L"Arc Service";
CComPtr<IUIAutomationCondition> arcServiceNameCondition;
hr = g_pAutomation->CreatePropertyCondition(UIA_NamePropertyId, arcServiceNameVariant, &arcServiceNameCondition.p);
if(SUCCEEDED(hr)) {
CComPtr<IUIAutomationElement> arcServiceElement;
hr = rootElement->FindFirst(TreeScope_Descendants, arcServiceNameCondition, &arcServiceElement.p);
if(SUCCEEDED(hr)) {
if(arcServiceElement.p) {
logInfo(L"Arc Service element found!");
}
} else {
logInfo(L"FindFirst failed!");
}
} else {
logInfo(L"Failed to create property condition!");
}
The "Arc Service element found!" branch is never entered.
Here are the details from Inspect describing the element:
Any assistance would be greatly appreciated. Thanks!

Quizzically it turns out that running my UIA client as Administrator sees the component, but running as the logged in user does not. For now I can elevate my process, but I'll continue to research the issue for a more detailed explanation.

Related

TgBot doesn't find owner ban power

I've started programming my own telegram-bot in cpp with tgbot-cpp and I've done the code for the ban. When the code checks if the user has the power to ban, it finds the needed power for admins, but not for the owner of the group. I looked in the documentation if there was a way to find the owner of the group, but I couldn't find it. This is the code section that checks the power.
/* Checks if the client has the permission to ban */
bool hasPermission = false;
for (unsigned i = 0; i < admins.size(); i++) {
if (admins[i]->user->id == message->from->id) {
printf("Admin username: %s\n", admins[i]->user->username.c_str());
printf("Can Restrict: %d\n", admins[i]->canRestrictMembers);
if (admins[i]->canRestrictMembers) {
hasPermission = true;
}
break;
}
}
if (!hasPermission) {
return;
}
When an admin uses the ban command, I get a Can Restrict: 1 in the console, but when the owner uses the command I get a Can Restrict: 0.
Is there a reason why the bot doesn't see the owner's power? Is there a way to look for the owner?
After looking better in the documentations, there is a value status for ChatMember that is setted to creator for the owner of the group. That seems to be the way for checking if someone is the owner or not, avoiding the permission issue

Sitecore poll module sample code

I installed and configured the Poll Module to work fine. The website I am working on will have a Poll instance on a page either as a left rail or a right rail item. The Polls would be setup in a separate folder. On the page item there will be a multilist field which will point to the Polls folder and the user can select whichever poll they choose to. The folder will also contain different sublayouts which will could be selected to be displayed on the rail. I have some custom code which will look at the above mentioned multilist field and show these rail items.
I don't know how to display a Poll programmatically. I haven't found any code samples and also not sure where to set the sublayout. Should I set it on the Poll template itself and then let use code to display it? How can I achieve this in code? Any code samples would be helpful.
Hoping that you will this time accept the answer, I wrote the following for you (based on the OMS Poll module:
Read out the field on your item:
Sitecore.Data.Fields.ReferenceField selectedPoll = (Sitecore.Data.Fields.ReferenceField)Sitecore.Context.Item.Fields["Poll"];
Get the pollItem:
if (selectedPoll.TargetItem != null)
{
Item pollItem = selectedPoll.TargetItem;
if (pollItem != null)
{
Check if the poll is opened or closed and place:
Sitecore.Data.Fields.CheckboxField pollClosed = (Sitecore.Data.Fields.CheckboxField)pollItem.Fields["Closed"];
if (pollClosed.Checked == false)
{
// Set the header of the snippetBlock
ltPollHeader.Text = pollItem.Name;
PollVotingSublayout pollSublayout = (PollVotingSublayout)LoadControl("/sitecore modules/Shell/Poll Module/Controls/PollVotingSublayout.ascx");
pollSublayout.Attributes.Add("sc_parameters", "PollPath=" + pollItem.Paths.FullPath);
pollSublayout.CurrentPoll = (PollItem)pollItem;
this.pollRegion.Controls.Add(pollSublayout);
phPollSnippet.Visible = true;
int blockPos = 0;
if (snippetField != null)
{
if (snippetField.GetItems().Any())
{
blockPos = 1;
}
}
string cssClass = String.Empty;
if (blockPos == 0)
{
cssClass = "snippetColHomeFirst";
}
this.SetClass("snippetColHome", cssClass);
}
Hope that you can make up something using this snippets. Good luck!
There should be a user account called "poll" on the sitecore domain. This account is normally used internal by the poll. In the comment of this account is stated: "Please do not remove this account". the account should have the Sitecore Minimal Page Editor role. I don't know the poll user credentials, but you might find that by either using reflector or opening cs files that you can get by downloading the source.

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

MAPI_E_NOT_FOUND on OpenMsgStore

I'm trying to open the MessageStore of a user using MAPI. The weird thing is, when I run this a console application, while I'm logged with the user, everything works fine.
But when I run this as a Windows Service I get MAPI_E_NOT_FOUND when trying to open the MessageStore.
I already configured the service to run as the user.
MapiLogonEx seems to work fine and GetMsgStoreTables also gives me the correct results (I verfied that the EntryID of the MessageStore is correct).
Here's my code:
LPMAPITABLE pStoresTbl = NULL;
m_lpMAPISession->GetMsgStoresTable(0, &pStoresTbl);
// Query Collumns
LPSPropTagArray pTags = NULL;
LPSRowSet pRows = NULL;
pStoresTbl->SeekRow(BOOKMARK_BEGINNING,0,NULL);
pStoresTbl->QueryRows(
LONG_MAX,
NULL,
&pRows);
LPSBinary lpEntryID = NULL;
ULONG iprops;
for (iprops = 0; iprops < pRows->aRow[0].cValues; iprops++)
{
SPropValue sProp = pRows->aRow[0].lpProps[iprops];
if (PROP_ID(sProp.ulPropTag) == PROP_ID(PR_ENTRYID))
{
lpEntryID = &sProp.Value.bin;
break;
}
}
lpMDB = NULL;
HRESULT hres = m_lpMAPISession->OpenMsgStore(NULL,
lpEntryID->cb,
(LPENTRYID) lpEntryID->lpb,
NULL,
MDB_NO_DIALOG |
MDB_NO_MAIL | // spooler not notified of our presence
MDB_TEMPORARY | // message store not added to MAPI profile
MAPI_BEST_ACCESS,
&lpMDB);
Is that an Exchange profile? Are you sure you are opening the primary mailbox rather than the PF store?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Do you pass in the MAPI_NT_SERVICE flag in the MAPIINIT_0 structure when calling MAPIInitialize? I've never not passed it in when running in a service, so I'm not exactly sure what happens if you don't. The MSDN docs say it is required.
MAPI_NT_SERVICE
The caller is
running as a Windows service. Callers
that are not running as a Windows
service should not set this flag;
callers that are running as a service
must set this flag.

Check if process user is an administrator c++

I want to get the process's user name and check if it is a local administrator . Or check directly if the current procees user is a local administrator
Get the current username with GetUserName(), then call NetUserGetInfo() with the server name (NULL for local) and username you just got. Pass it a USER_INFO_1 structure, and then access usri1_priv in the structure. If the value is USER_PRIV_ADMIN, then you'll know that the username is an admin.
Tested on Windows XP SP3, Windows 7 32 bit and 64 bit with admin user and non-admin user.
Code ported from equivalent C# and uses ATL windows security wrapper classes.
#include <atlbase.h>
#include <atlsecurity.h>
// The function returns true if the user who is running the
// application is a member of the Administrators group,
// which does not necessarily mean the process has admin privileges.
bool IsAdministrator(HRESULT &rHr)
{
bool bIsAdmin = false;
try
{
// Open the access token of the current process.
ATL::CAccessToken aToken;
if (!aToken.GetProcessToken(TOKEN_QUERY))
{
throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
::GetLastError());
}
// Query for the access token's group information.
ATL::CTokenGroups groups;
if (!aToken.GetGroups(&groups))
{
throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
::GetLastError());
}
// Iterate through the access token's groups
// looking for a match against the builtin admins group.
ATL::CSid::CSidArray groupSids;
ATL::CAtlArray<DWORD> groupAttribs;
groups.GetSidsAndAttributes(&groupSids, &groupAttribs);
for (UINT i = 0; !bIsAdmin && i < groupSids.GetCount(); ++i)
{
bIsAdmin = groupSids.GetAt(i) == ATL::Sids::Admins();
}
rHr = S_OK;
}
catch (HRESULT hr)
{
rHr = hr;
}
return bIsAdmin;
}
Presuming you're on a Window OS there's a shell function: IsUserAnAdmin
See MSDN article
This article does suggest rolling your own function though, use CheckTokenMembership. There is even a code example to help you along.