NO

Author Topic: How to read a "LargeInteger" value of an AD object's property  (Read 2810 times)

liut

  • Guest
Hi, I just have a problem: I don't know how to read a "LargeInteger" in a VARIANT coming from AD object (user) property. As my purpose, I want to get the information of lastLogonTimestamp instead the lastLogon (this can be read by get_LastLogin() easily).

My code below:
Code: [Select]
HRESULT hr7;
VARIANT var_lastlogon_timestamp;
SYSTEMTIME lastlogon_timestamp_st;

hr7=p_user->lpVtbl->Get(p_user,L"lastLogonTimestamp",&var_lastlogon_timestamp);
if(hr7==S_OK){
//LONGLONG ll=131406647934745516;  // This is the actual value in the system showing in AD user tool
LONGLONG ll;
ll=V_I8(&var_lastlogon_timestamp);

memset((void *)&lastlogon_timestamp_st,0,sizeof(SYSTEMTIME));
FileTimeToSystemTime((FILETIME *)&ll,&lastlogon_timestamp_st);

sprintf(date_text,"Last logon timestamp:\t\t%04d-%02d-%02d\n",lastlogon_timestamp_st.wYear,lastlogon_timestamp_st.wMonth,lastlogon_timestamp_st.wDay);
strcat(output_user,date_text);

VariantClear(&var_lastlogon_timestamp);
}
I think I misunderstand the complicated struct VARIANT and wrongly use V_I8(). And the official example code confuses me too:

https://msdn.microsoft.com/en-us/library/aa705925(v=vs.85).aspx

I also try to set breakpoint and see the runtime value, but it's too complex to get the actual value directly. If the property value type is string or date, it's easy for me to get it...

Anybody have such experience to show me the correct and simply way?
« Last Edit: June 09, 2017, 12:18:58 PM by frankie »

liut

  • Guest
Re: How to read a "LargeInteger" value of an AD object's property
« Reply #1 on: June 12, 2017, 08:15:43 AM »
I have found out the solution :):

Code: [Select]
hr7=p_user->lpVtbl->Get(p_user,L"lastLogonTimestamp",&var_lastlogon_timestamp);
if(hr7==S_OK){
ULONGLONG ll;

const IID iads_largeinteger={0x9068270b,0x0939,0x11d1,{0x8b,0xe1,0x00,0xc0,0x4f,0xd8,0xd5,0x03}};  // 9068270b-0939-11d1-8be1-00c04fd8d503
IADsLargeInteger *p_i8=NULL;

hr8=IADsLargeInteger_QueryInterface(V_DISPATCH(&var_lastlogon_timestamp),&iads_largeinteger,(void **)&p_i8);
if(hr8==S_OK){
ULONG h=0,l=0;
p_i8->lpVtbl->get_HighPart(p_i8,&h);
p_i8->lpVtbl->get_LowPart(p_i8,&l);

ll=(ULONGLONG)h*0x100000000+l;

p_i8->lpVtbl->Release(p_i8);
}
« Last Edit: June 12, 2017, 12:33:50 PM by frankie »