SOL9 Sample: NetFwAuthorizedApplicationsAddApplication
|
1 Screenshot
2 Source code
/*
* NetFwAuthorizedApplicationsAddApplication.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
//2012/08/29
#include <sol\Locale.h>
#include <sol\com\ApartmentThreadedModel.h>
#include <sol\COMInitializer.h>
#include <sol\netfw\NetFwMgr.h>
#include <sol\netfw\NetFwPolicy.h>
#include <sol\netfw\NetFwProfile.h>
#include <sol\netfw\NetFwAuthorizedApplication.h>
void _tmain(int argc, const TCHAR* argv[])
{
Locale locale;
if (argc != 3) {
_tprintf(_T("Usage: %s name imageFileName\n"), argv[0]);
_tprintf(_T("Ex. %s SolApplication \"C:\\sample\\SolApplication.exe\"\n"), argv[0]);
return;
}
try {
ApartmentThreadedModel model;
SOL::NetFwMgr mgr;
NetFwPolicy policy = mgr.getLocalPolicy();
//NetFwProfile profile = policy.getCurrentProfile();
NetFwProfile profile = policy.getStandardProfile();
NetFwAuthorizedApplications authorizedApplications = profile.getAuthorizedApplications();
authorizedApplications.display();
//Create an instance of NetFwAuthorizedApplication.
SOL::NetFwAuthorizedApplication application;
//Put properties to the application.
_bstr_t imageFileName = "C:\\sample\\SolTrustVerifier.exe";
_bstr_t name = "Application";
application.putName(name);
application.putName(imageFileName);
application.putIpVersion(NET_FW_IP_VERSION_ANY);
application.putScope(NET_FW_SCOPE_ALL);
application.putRemoteAddresses(L"*");
application.putEnabled(true);
printf("Add an application to authorizedApplications\n");
//Add the application to the authorizedApplications.
authorizedApplications.add((INetFwAuthorizedApplication*)application);
printf("OK. Added\n");
//Find an application from authorizedApplications.
//Get an authorized app from the authorizedApplications by imageFileName.
SOL::NetFwAuthorizedApplication app = authorizedApplications.item(imageFileName);
//Display app
app.display();
//authorizedApplications.remove(imageFileName);
} catch (Exception& ex) {
ex.printf();
} catch (HRESULT hr) {
_tprintf(_T("Exception: HRESULT=%x\n"), hr);
if (hr == E_ACCESSDENIED) {
printf("AccessDenied\n");
}
if (hr == E_INVALIDARG) {
printf("Invalid\n");
}
if (hr == E_UNEXPECTED) {
printf("Unexpected\n");
}
}
getchar();
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.