Skip to content

Commit

Permalink
Fixed D-09804
Browse files Browse the repository at this point in the history
  • Loading branch information
Acey Bunch committed Sep 8, 2015
1 parent c3ca1f1 commit f1570a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 6 additions & 7 deletions VersionOne.ServiceHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*(c) Copyright 2012, VersionOne, Inc. All rights reserved. (c)*/
using System;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -32,28 +31,28 @@ private static void UninstallService() {
} catch { }

if(ServiceUtil.UnInstallService(Config.ShortName))
Console.WriteLine("Service Uninstall Successful");
Console.WriteLine("Service uninstall successful");
else
Console.WriteLine("Service Uninstall Failed");
Console.WriteLine("Service uninstall failed");
} catch(Exception ex) {
throw new ApplicationException("Uninstall Failed - " + ex.Message);
throw new ApplicationException("Uninstall failed - " + ex.Message);
}
}

private static void InstallService() {
try {
if(ServiceUtil.InstallService("\"" + Assembly.GetEntryAssembly().Location + "\" --service",
Config.ShortName, Config.LongName, ServiceUtil.LocalService, null)) {
Console.WriteLine("Service Installation Successful");
Console.WriteLine("Service installation successful!");
} else {
Console.WriteLine("Service Installation Failed");
Console.WriteLine("Service installation failed");
}

try {
ServiceUtil.StartService(Config.ShortName);
} catch { }
} catch(Exception ex) {
throw new ApplicationException("Install Failed - " + ex.Message);
throw new ApplicationException("Install failed - " + ex.Message);
}
}

Expand Down
11 changes: 6 additions & 5 deletions VersionOne.ServiceHost/ServiceUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*(c) Copyright 2012, VersionOne, Inc. All rights reserved. (c)*/
using System;
using System.Runtime.InteropServices;
using System.ServiceProcess;
Expand Down Expand Up @@ -71,11 +70,12 @@ private static extern IntPtr CreateService(IntPtr scHandle, string lpSvcName, st
public static bool InstallService(string svcPath, string svcName, string svcDispName, string svcUsername, string svcPassword) {
var scm = OpenSCManager(null, null, ScManagerCreateService);

if (scm.ToInt32() != 0) {
// 09-08-2015 Fixed D-09804. Changed from scm.ToInt32() to scm.ToInt64().
if (scm.ToInt64() != 0) {
var svc = CreateService(scm, svcName, svcDispName, ServiceAllAccess, ServiceWin32OwnProcess,
ServiceAutoStart, ServiceErrorNormal, svcPath, null, 0, null,
svcUsername, svcPassword);
var installed = svc.ToInt32() != 0;
var installed = svc.ToInt64() != 0;
CloseServiceHandle(scm);
return installed;
}
Expand All @@ -98,10 +98,11 @@ public static void StopService(string svcName) {
public static bool UnInstallService(string svcName) {
var scHandle = OpenSCManager(null, null, GenericWrite);

if(scHandle.ToInt32() != 0) {
// 09-08-2015 Fixed D-09804. Changed from scm.ToInt32() to scm.ToInt64().
if(scHandle.ToInt64() != 0) {
var svcHandle = OpenService(scHandle, svcName, Delete);

if (svcHandle.ToInt32() != 0) {
if (svcHandle.ToInt64() != 0) {
var i = DeleteService(svcHandle);
CloseServiceHandle(scHandle);
return i != 0;
Expand Down

0 comments on commit f1570a1

Please sign in to comment.