summaryrefslogtreecommitdiff
path: root/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp
diff options
context:
space:
mode:
authorLuke <[email protected]>2017-11-28 00:22:11 -0800
committerGitHub <[email protected]>2017-11-28 00:22:11 -0800
commit79bbbca2f6e37d94fbbbd60d12c5c1e7dde650da (patch)
tree793ff943b8b641f95d05401156badd42da4a0f12 /general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp
parented1df9a8b80b154b71b79635e40af75f4f19001c (diff)
parent2817004092cee784d4aaf36c045fdb5b0bc09f7e (diff)
Merge pull request #1 from Microsoft/master
Updating Local
Diffstat (limited to 'general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp')
-rw-r--r--general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp b/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp
new file mode 100644
index 00000000..d3f70fdf
--- /dev/null
+++ b/general/WinHEC 2017 Lab/Toaster Driver/Service/HsaService.cpp
@@ -0,0 +1,116 @@
+//*********************************************************
+//
+// Copyright (c) Microsoft. All rights reserved.
+// This code is licensed under the MIT License (MIT).
+// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
+// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
+// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
+//
+//*********************************************************
+
+#include "stdafx.h"
+
+#pragma region Includes
+#include <stdio.h>
+#include <windows.h>
+#include "ServiceInstaller.h"
+#include "ServiceBase.h"
+#include "SampleService.h"
+#pragma endregion
+
+//
+// Settings of the service
+//
+
+// Internal name of the service
+#define SERVICE_NAME L"HsaService"
+
+// Displayed name of the service
+#define SERVICE_DISPLAY_NAME L"Hsa Sample Service"
+
+// Service start options.
+#define SERVICE_START_TYPE SERVICE_DEMAND_START
+
+// List of service dependencies - "dep1\0dep2\0\0"
+#define SERVICE_DEPENDENCIES L""
+
+// The name of the account under which the service should run - NULL uses LocalSystem account.
+#define SERVICE_ACCOUNT NULL
+
+// The password to the service account name
+#define SERVICE_PASSWORD NULL
+
+
+//
+// FUNCTION: wmain(int, wchar_t *[])
+//
+// PURPOSE: entrypoint for the application.
+//
+// PARAMETERS:
+// argc - number of command line arguments
+// argv - array of command line arguments
+//
+// RETURN VALUE:
+// none
+//
+// COMMENTS:
+// wmain() either performs the command line task, or run the service.
+//
+int wmain(_In_ int argc, _In_ wchar_t *argv[])
+{
+ bool invalidArgs = false;
+
+ if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
+ {
+ if (_wcsicmp(L"install", argv[1] + 1) == 0)
+ {
+ // Install the service when the command is
+ // "-install" or "/install".
+ InstallService(
+ SERVICE_NAME, // Name of service
+ SERVICE_DISPLAY_NAME, // Name to display
+ SERVICE_START_TYPE, // Service start type
+ SERVICE_DEPENDENCIES, // Dependencies
+ SERVICE_ACCOUNT, // Service running account
+ SERVICE_PASSWORD // Password of the account
+ );
+ }
+ else if (_wcsicmp(L"remove", argv[1] + 1) == 0)
+ {
+ // Uninstall the service when the command is
+ // "-remove" or "/remove".
+ UninstallService(SERVICE_NAME);
+ }
+ else if (_wcsicmp(L"console", argv[1] + 1) == 0)
+ {
+ // Uninstall the service when the command is
+ // "-remove" or "/remove".
+ CSampleService service(SERVICE_NAME);
+ service.ConsoleRun();
+ }
+ else
+ {
+ invalidArgs = true;
+ }
+ }
+ else
+ {
+ invalidArgs = true;
+ CSampleService service(SERVICE_NAME);
+ if (!CServiceBase::Run(service))
+ {
+ wprintf(L"Service failed to run w/err 0x%08lx\n", GetLastError());
+ }
+ }
+
+ if (invalidArgs)
+ {
+ wprintf(L"Parameters:\n");
+ wprintf(L" -install to install the service.\n");
+ wprintf(L" -remove to remove the service.\n");
+ wprintf(L" -console to run in console mode.\n");
+ }
+
+ return 0;
+} \ No newline at end of file