Added Constructor to create WinService with an existing Connection to a Service Manager

This commit is contained in:
Jan Kevin Dick 2019-11-18 10:08:11 +01:00
parent d658cc25e7
commit 5a484c1896
9 changed files with 192 additions and 93 deletions

View File

@ -52,6 +52,13 @@ public:
WinService(const std::string& name);
/// Creates the WinService, using the given service name.
WinService(SC_HANDLE scmHandle, const std::string& name);
/// Creates the WinService, using the given connection to
/// a Windows Service Manager and the given service name.
///
/// The class will close the given scmHandle on destruction
~WinService();
/// Destroys the WinService.

View File

@ -47,6 +47,13 @@ WinService::WinService(const std::string& name):
if (!_scmHandle) throw SystemException("cannot open Service Control Manager");
}
WinService::WinService(SC_HANDLE scmHandle, const std::string& name):
_scmHandle(scmHandle),
_name(name),
_svcHandle(0)
{
if (!_scmHandle) throw SystemException("Service Control Manager not connected");
}
WinService::~WinService()
{

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="debug_shared|Win32">
@ -32,7 +32,7 @@
<RootNamespace>TestSuite</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release_static_md|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
@ -63,27 +63,27 @@
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
<ImportGroup Label="ExtensionSettings"/>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='release_static_md|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='debug_static_md|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='release_static_mt|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='debug_static_mt|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='release_shared|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'" Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros"/>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>15.0.27625.0</_ProjectFileVersion>
<TargetName Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'">TestSuited</TargetName>
@ -136,7 +136,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
@ -167,9 +167,9 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat/>
<DebugInformationFormat />
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
@ -196,7 +196,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
@ -227,9 +227,9 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat/>
<DebugInformationFormat />
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
@ -256,7 +256,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
@ -287,9 +287,9 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader/>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat/>
<DebugInformationFormat />
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
@ -304,60 +304,62 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\AbstractConfigurationTest.h"/>
<ClInclude Include="src\ConfigurationMapperTest.h"/>
<ClInclude Include="src\ConfigurationTestSuite.h"/>
<ClInclude Include="src\ConfigurationViewTest.h"/>
<ClInclude Include="src\FilesystemConfigurationTest.h"/>
<ClInclude Include="src\HelpFormatterTest.h"/>
<ClInclude Include="src\IniFileConfigurationTest.h"/>
<ClInclude Include="src\JSONConfigurationTest.h"/>
<ClInclude Include="src\LayeredConfigurationTest.h"/>
<ClInclude Include="src\LoggingConfiguratorTest.h"/>
<ClInclude Include="src\MapConfigurationTest.h"/>
<ClInclude Include="src\OptionProcessorTest.h"/>
<ClInclude Include="src\OptionSetTest.h"/>
<ClInclude Include="src\OptionsTestSuite.h"/>
<ClInclude Include="src\OptionTest.h"/>
<ClInclude Include="src\PropertyFileConfigurationTest.h"/>
<ClInclude Include="src\SystemConfigurationTest.h"/>
<ClInclude Include="src\TimerTest.h"/>
<ClInclude Include="src\TimerTestSuite.h"/>
<ClInclude Include="src\UtilTestSuite.h"/>
<ClInclude Include="src\ValidatorTest.h"/>
<ClInclude Include="src\WinConfigurationTest.h"/>
<ClInclude Include="src\WindowsTestSuite.h"/>
<ClInclude Include="src\WinRegistryTest.h"/>
<ClInclude Include="src\XMLConfigurationTest.h"/>
<ClInclude Include="src\AbstractConfigurationTest.h" />
<ClInclude Include="src\ConfigurationMapperTest.h" />
<ClInclude Include="src\ConfigurationTestSuite.h" />
<ClInclude Include="src\ConfigurationViewTest.h" />
<ClInclude Include="src\FilesystemConfigurationTest.h" />
<ClInclude Include="src\HelpFormatterTest.h" />
<ClInclude Include="src\IniFileConfigurationTest.h" />
<ClInclude Include="src\JSONConfigurationTest.h" />
<ClInclude Include="src\LayeredConfigurationTest.h" />
<ClInclude Include="src\LoggingConfiguratorTest.h" />
<ClInclude Include="src\MapConfigurationTest.h" />
<ClInclude Include="src\OptionProcessorTest.h" />
<ClInclude Include="src\OptionSetTest.h" />
<ClInclude Include="src\OptionsTestSuite.h" />
<ClInclude Include="src\OptionTest.h" />
<ClInclude Include="src\PropertyFileConfigurationTest.h" />
<ClInclude Include="src\SystemConfigurationTest.h" />
<ClInclude Include="src\TimerTest.h" />
<ClInclude Include="src\TimerTestSuite.h" />
<ClInclude Include="src\UtilTestSuite.h" />
<ClInclude Include="src\ValidatorTest.h" />
<ClInclude Include="src\WinConfigurationTest.h" />
<ClInclude Include="src\WindowsTestSuite.h" />
<ClInclude Include="src\WinRegistryTest.h" />
<ClInclude Include="src\WinServiceTest.h" />
<ClInclude Include="src\XMLConfigurationTest.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\AbstractConfigurationTest.cpp"/>
<ClCompile Include="src\ConfigurationMapperTest.cpp"/>
<ClCompile Include="src\ConfigurationTestSuite.cpp"/>
<ClCompile Include="src\ConfigurationViewTest.cpp"/>
<ClCompile Include="src\Driver.cpp"/>
<ClCompile Include="src\FilesystemConfigurationTest.cpp"/>
<ClCompile Include="src\HelpFormatterTest.cpp"/>
<ClCompile Include="src\IniFileConfigurationTest.cpp"/>
<ClCompile Include="src\JSONConfigurationTest.cpp"/>
<ClCompile Include="src\LayeredConfigurationTest.cpp"/>
<ClCompile Include="src\LoggingConfiguratorTest.cpp"/>
<ClCompile Include="src\MapConfigurationTest.cpp"/>
<ClCompile Include="src\OptionProcessorTest.cpp"/>
<ClCompile Include="src\OptionSetTest.cpp"/>
<ClCompile Include="src\OptionsTestSuite.cpp"/>
<ClCompile Include="src\OptionTest.cpp"/>
<ClCompile Include="src\PropertyFileConfigurationTest.cpp"/>
<ClCompile Include="src\SystemConfigurationTest.cpp"/>
<ClCompile Include="src\TimerTest.cpp"/>
<ClCompile Include="src\TimerTestSuite.cpp"/>
<ClCompile Include="src\UtilTestSuite.cpp"/>
<ClCompile Include="src\ValidatorTest.cpp"/>
<ClCompile Include="src\WinConfigurationTest.cpp"/>
<ClCompile Include="src\WindowsTestSuite.cpp"/>
<ClCompile Include="src\WinRegistryTest.cpp"/>
<ClCompile Include="src\XMLConfigurationTest.cpp"/>
<ClCompile Include="src\AbstractConfigurationTest.cpp" />
<ClCompile Include="src\ConfigurationMapperTest.cpp" />
<ClCompile Include="src\ConfigurationTestSuite.cpp" />
<ClCompile Include="src\ConfigurationViewTest.cpp" />
<ClCompile Include="src\Driver.cpp" />
<ClCompile Include="src\FilesystemConfigurationTest.cpp" />
<ClCompile Include="src\HelpFormatterTest.cpp" />
<ClCompile Include="src\IniFileConfigurationTest.cpp" />
<ClCompile Include="src\JSONConfigurationTest.cpp" />
<ClCompile Include="src\LayeredConfigurationTest.cpp" />
<ClCompile Include="src\LoggingConfiguratorTest.cpp" />
<ClCompile Include="src\MapConfigurationTest.cpp" />
<ClCompile Include="src\OptionProcessorTest.cpp" />
<ClCompile Include="src\OptionSetTest.cpp" />
<ClCompile Include="src\OptionsTestSuite.cpp" />
<ClCompile Include="src\OptionTest.cpp" />
<ClCompile Include="src\PropertyFileConfigurationTest.cpp" />
<ClCompile Include="src\SystemConfigurationTest.cpp" />
<ClCompile Include="src\TimerTest.cpp" />
<ClCompile Include="src\TimerTestSuite.cpp" />
<ClCompile Include="src\UtilTestSuite.cpp" />
<ClCompile Include="src\ValidatorTest.cpp" />
<ClCompile Include="src\WinConfigurationTest.cpp" />
<ClCompile Include="src\WindowsTestSuite.cpp" />
<ClCompile Include="src\WinRegistryTest.cpp" />
<ClCompile Include="src\WinServiceTest.cpp" />
<ClCompile Include="src\XMLConfigurationTest.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
<ImportGroup Label="ExtensionTargets"/>
</Project>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -138,6 +138,9 @@
<ClInclude Include="src\TimerTestSuite.h">
<Filter>Timer\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\WinServiceTest.h">
<Filter>Windows\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\UtilTestSuite.cpp">
@ -218,5 +221,8 @@
<ClCompile Include="src\TimerTestSuite.cpp">
<Filter>Timer\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\WinServiceTest.cpp">
<Filter>Windows\Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,43 @@
#include "WinServiceTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Util/WinService.h"
using Poco::Util::WinService;
WinServiceTest::WinServiceTest(const std::string& name) : CppUnit::TestCase(name) {
}
WinServiceTest::~WinServiceTest() {
}
void WinServiceTest::testServiceCouldCreatedWithExistingConnection() {
SC_HANDLE scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
assertTrue(scmHandle);
WinService spoolerService{ scmHandle, "Spooler" };
assertTrue(spoolerService.isRegistered());
}
void WinServiceTest::setUp() {
}
void WinServiceTest::tearDown() {
}
CppUnit::Test* WinServiceTest::suite() {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinServiceTest");
CppUnit_addTest(pSuite, WinServiceTest, testServiceCouldCreatedWithExistingConnection);
return pSuite;
}

View File

@ -0,0 +1,25 @@
#ifndef WinServiceTest_INCLUDED
#define WinServiceTest_INCLUDED
#include "Poco/Util/Util.h"
#include "CppUnit/TestCase.h"
class WinServiceTest : public CppUnit::TestCase {
public:
WinServiceTest(const std::string& name);
~WinServiceTest();
void testServiceCouldCreatedWithExistingConnection();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // WinServiceTest_INCLUDED

View File

@ -11,6 +11,7 @@
#include "WindowsTestSuite.h"
#include "WinRegistryTest.h"
#include "WinConfigurationTest.h"
#include "WinServiceTest.h"
CppUnit::Test* WindowsTestSuite::suite()
@ -19,6 +20,7 @@ CppUnit::Test* WindowsTestSuite::suite()
pSuite->addTest(WinRegistryTest::suite());
pSuite->addTest(WinConfigurationTest::suite());
pSuite->addTest(WinServiceTest::suite());
return pSuite;
}

View File

@ -4,22 +4,4 @@ Encodings
XML
JSON
Util
Net
Crypto
NetSSL_OpenSSL
NetSSL_Win
Data
Data/SQLite
Data/ODBC
Data/MySQL
Data/PostgreSQL
Zip
PageCompiler
PageCompiler/File2Page
JWT
PDF
CppParser
MongoDB
Redis
PocoDoc
ProGen
Net

25
components - Kopie Normal file
View File

@ -0,0 +1,25 @@
CppUnit
Foundation
Encodings
XML
JSON
Util
Net
Crypto
NetSSL_OpenSSL
NetSSL_Win
Data
Data/SQLite
Data/ODBC
Data/MySQL
Data/PostgreSQL
Zip
PageCompiler
PageCompiler/File2Page
JWT
PDF
CppParser
MongoDB
Redis
PocoDoc
ProGen