SOL9 Sample: SWbemQueryAsAdminApplet
|
1 Screenshot
2 Source code
/*
* SWbemQueryAsAdminApplet.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// 2009/12/23 Modified to save query results to a text file ".\SWbemQueryAsAdminResult.txt"
//
// This application need the following Query.Properties file:
// If needed, please change WQL Query property to
/*
; SWbemQueryAsAdminApplet.Query.properties
Server = .
Namespace = root\cimv2
; If LogFile were 'Application', OK.
;Query = SELECT * FROM Win32_NTLogEvent Where LogFile='Application' AND TimeWritten > '20091214163612.000000-000'
; But, how about LogFile were 'Security'? Probably you need a right of the administrator, namely a manifest file to allow it.
Query = SELECT * FROM Win32_NTLogEvent Where LogFile='Security' AND TimeWritten > '20091201000000.000000-000'
*/
#include <sol/wmi/SWbemQueryApplet.h>
namespace SOL {
class SWbemQueryAsAdminApplet: public SWbemQueryApplet {
public:
/**
* Constructor
*/
SWbemQueryAsAdminApplet()
{
}
public:
virtual void display(SWbemObjectSet& objectSet)
{
SWbemQueryProperties& properties = getQueryProperties();
_bstr_t query = properties.getQuery();
printf("ExecQuery %S\n", (const wchar_t*)query);
const wchar_t* reportFile = L".\\SWbemQueryAsAdminResult.txt";
FileWriter writer(reportFile);
writer.writeln(L"<SWbemQueryAsAdminResult/>");
LocalDateTime ldt;
StringT<wchar_t> now;
writer.writeln(L"<Generated dateTime=\"%s\"/>", ldt.nowToSeconds(now));
writer.writeln(L"<Query>\r\n%s\r\n</Query>", (const wchar_t*)query);
long count = objectSet.getCount();
writer.writeln(L"<ResultSet Count=\"%d\" />", count);
for (long i = 0; i<count; i++) {
try {
SWbemObject object = objectSet.itemIndex(i);
_bstr_t text = object.getObjectText(0);
//printf("\n\nNo:%d ObjectText=%S\n", i, (const wchar_t*)text);
writer.writeln(L"<ObjectText No=\"%d\">\r\n%s\r\n</ObjectText>\r\n",
i, (const wchar_t*)text);
} catch (HRESULT hr) {
WbemErrors errors;
printf("Exception: HRESULT=%0x %s\n", hr, errors.getName(hr));
} catch (Exception ex) {
ex.printf();
} catch (...) {
printf("Unknown Exception\n");
}
}
printf("Saved qurey reult to a file %S\n", reportFile);
}
};
}
void _tmain(int argc, const TCHAR ** argv)
{
printf("SWbemQueryAsAdminApplet started\n");
try {
Locale locale;
SWbemQueryAsAdminApplet applet;
//Start the thread of ServiceQuery
applet.start();
applet.wait();
} catch (HRESULT hr) {
printf("Exception hr=%0x\n", hr);
} catch (Exception& ex) {
printf("Exception \n");
} catch (...) {
printf("Unknown Exception\n");
}
printf("\nOK. Please hit return key\n");
getchar();
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.