Index: /trunk/src/VBox/Installer/win/VBoxMergeApp.wxi
===================================================================
--- /trunk/src/VBox/Installer/win/VBoxMergeApp.wxi	(revision 70227)
+++ /trunk/src/VBox/Installer/win/VBoxMergeApp.wxi	(revision 70228)
@@ -82,11 +82,32 @@
         <?include $(env.PATH_TARGET)\VirtualBox_TypeLib.wxi ?>
 <?endif?>
+    </Component>
 
 <?if $(env.VBOX_WITH_SDS) = "yes" ?>
-        <File Id="VBoxSDS" Name="VBoxSDS.exe"
-              Source="$(env.PATH_OUT)\bin\VBoxSDS.exe">
-        </File>
-<?endif?>
-    </Component>
+    <Component Id="cp_VBoxSDS" Guid="{3DC151E0-CA53-4213-8711-D983FDA28132}" >
+        <File Id="VBoxSDS" Name="VBoxSDS.exe" Vital="yes" KeyPath="yes"
+                    Source="$(env.PATH_OUT)\bin\VBoxSDS.exe">
+        </File>
+        <!-- 
+            The Name of windows service is referenced in different places.
+            Don't forget to change it in other places too If you change it here :
+                VirtualBox.idl (module name),
+                VBoxSDS.cpp and VBoxProxyStub.cpp
+            -->
+        <ServiceInstall Id="VBoxSDSInstall"
+                    Account="LocalSystem"
+                    Type="ownProcess"
+                    Name="VBoxSDS"
+                    DisplayName="VirtualBox system service"
+                    Description="Used as a COM server for VirtualBox API."
+                    Start="demand"
+                    Interactive="no"
+                    ErrorControl="normal"
+                    Vital="yes">
+            <ServiceDependency Id="RPCSS" />
+        </ServiceInstall>
+        <ServiceControl Id="VBoxSDSControl" Name="VBoxSDS" Stop="both" Remove="uninstall" />
+    </Component>
+<?endif?>
 
 <?if $(env.VBOX_WITH_MIDL_PROXY_STUB) = "yes" ?>
Index: /trunk/src/VBox/Installer/win/VirtualBox.wxs
===================================================================
--- /trunk/src/VBox/Installer/win/VirtualBox.wxs	(revision 70227)
+++ /trunk/src/VBox/Installer/win/VirtualBox.wxs	(revision 70228)
@@ -234,9 +234,4 @@
     <CustomAction Id="ca_UninstallBrandingArgs" Property="ca_UninstallBranding" Value="[INSTALLDIR]" Execute="immediate"/>
 
-<?if $(env.VBOX_WITH_SDS) = "yes" ?>
-    <CustomAction Id="ca_InstallVBoxSDS" Directory="INSTALLDIR" ExeCommand='"[INSTALLDIR]\VBoxSDS.exe" --regservice' Return="check" Impersonate="no" />
-    <CustomAction Id="ca_UninstallVBoxSDS" Directory="INSTALLDIR" ExeCommand='"[INSTALLDIR]\VBoxSDS.exe" --unregservice' Return="check" Impersonate="no" />
-<?endif?>
-
 <?if $(env.VBOX_WITH_MSM_INSTALL) = "no" ?>
     <?include VBoxMergeAppCA.wxi ?>
@@ -460,4 +455,8 @@
         <!-- unattended template component -->
         <ComponentRef Id="cp_UnattendedTemplates" />
+<?endif ?>
+
+<?if $(env.VBOX_WITH_SDS) = "yes" ?>
+        <ComponentRef Id="cp_VBoxSDS" />
 <?endif ?>
 
@@ -578,9 +577,4 @@
         <Custom Action="ca_UninstallBranding" Before="InstallFinalize" ><![CDATA[(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")]]></Custom>
 
-<?if $(env.VBOX_WITH_SDS) = "yes" ?>
-        <Custom Action="ca_InstallVBoxSDS" After="InstallFinalize" ><![CDATA[NOT REMOVE]]></Custom>
-        <Custom Action="ca_UninstallVBoxSDS" Before="InstallFinalize" ><![CDATA[(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")]]></Custom>
-<?endif ?>
-
 <?if $(env.VBOX_WITH_MSM_INSTALL) = "no" ?>
         <?include VBoxMergeAppSeq.wxi ?>
Index: /trunk/src/VBox/Installer/win/VirtualBox_TypeLib.xsl
===================================================================
--- /trunk/src/VBox/Installer/win/VirtualBox_TypeLib.xsl	(revision 70227)
+++ /trunk/src/VBox/Installer/win/VirtualBox_TypeLib.xsl	(revision 70228)
@@ -28,5 +28,5 @@
 
 <xsl:param name="a_sTarget">all</xsl:param>
-<xsl:param name="a_sWithSDS">no</xsl:param>
+<xsl:param name="a_sWithSDS" select="no"/>
 
 
@@ -79,5 +79,5 @@
 -->
     <xsl:template match="application[@uuid='ec0e78e8-fa43-43e8-ac0a-02c784c4a4fa']">
-        <xsl:if test="a_sWithSDS='yes'" >
+        <xsl:if test="$a_sWithSDS='yes'" >
             <xsl:call-template name="application_template" />
         </xsl:if>
@@ -95,4 +95,13 @@
                 <xsl:value-of select="@name"/> Application
             </xsl:attribute>
+            <!--
+                The name of windows service should be defined as module name in .xidl.
+                It's viable for correct registration of COM windows service.
+            -->
+            <xsl:if test="module/@context = 'LocalService'">
+                <xsl:attribute name="LocalService" >
+                    <xsl:value-of select="module/@name"/>
+                </xsl:attribute>
+            </xsl:if>
             <xsl:choose>
                 <xsl:when test="$a_sTarget = 'VBoxClient-x86'">
@@ -118,5 +127,6 @@
       <xsl:choose>
         <xsl:when test="../@context='InprocServer'">InprocServer32</xsl:when>
-        <xsl:when test="../@context='LocalServer'">LocalServer32</xsl:when>
+        <xsl:when test="../@context='LocalServer'" >LocalServer32</xsl:when>
+        <xsl:when test="../@context='LocalService'">LocalServer32</xsl:when>
         <xsl:otherwise>
           <xsl:message terminate="yes">
Index: /trunk/src/VBox/Installer/win/VirtualBox_TypeLibWithInterfaces.xsl
===================================================================
--- /trunk/src/VBox/Installer/win/VirtualBox_TypeLibWithInterfaces.xsl	(revision 70227)
+++ /trunk/src/VBox/Installer/win/VirtualBox_TypeLibWithInterfaces.xsl	(revision 70228)
@@ -27,4 +27,5 @@
 
 <xsl:param name="a_sTarget">all</xsl:param>
+<xsl:param name ="a_sWithSDS" select="no"/>
 <xsl:param name="a_sProxyStubClsid">{0BB3B78C-1807-4249-5BA5-EA42D66AF0BF}</xsl:param>
 <xsl:variable name="g_sProxyStubClsid" select="translate($a_sProxyStubClsid,'abcdef','ABCDEF')"/>
@@ -67,5 +68,5 @@
 -->
     <xsl:template match="application[@uuid='ec0e78e8-fa43-43e8-ac0a-02c784c4a4fa']">
-        <xsl:if test="a_sWithSDS='yes'" >
+        <xsl:if test="$a_sWithSDS='yes'" >
             <xsl:call-template name="application_template" />
         </xsl:if>
@@ -93,5 +94,5 @@
 Applications.
 -->
-<xsl:template match="application">
+<xsl:template match="application" name="application_template">
     <AppId>
         <xsl:attribute name="Id">
@@ -101,4 +102,13 @@
             <xsl:value-of select="@name"/> Application
         </xsl:attribute>
+        <!--
+            The name of windows service should be defined as module name in .xidl.
+            It's viable for correct registration of COM windows service.
+        -->
+        <xsl:if test="module/@context = 'LocalService'">
+            <xsl:attribute name="LocalService" >
+                <xsl:value-of select="module/@name"/>
+            </xsl:attribute>
+        </xsl:if>
         <xsl:choose>
             <xsl:when test="$a_sTarget = 'VBoxClient-x86'">
@@ -131,6 +141,6 @@
       <xsl:choose>
         <xsl:when test="../@context='InprocServer'">InprocServer32</xsl:when>
-        <xsl:when test="../@context='LocalServer'">LocalServer32</xsl:when>
-          <xsl:when test="../@context='LocalService'">LocalServer32</xsl:when>
+        <xsl:when test="../@context='LocalServer'" >LocalServer32</xsl:when>
+        <xsl:when test="../@context='LocalService'">LocalServer32</xsl:when>
         <xsl:otherwise>
           <xsl:message terminate="yes">
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 70227)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 70228)
@@ -24473,4 +24473,13 @@
 </if> <!-- bird: shouldn't this if-element at leat include the VBoxSDS module, if not the whole system service application? -->
 
+<!-- Warning: the name of module should coincide with real windows service name.
+     VirtualBox_Typelib.xsl and VirtualBox_TypeLibWithInterfaces.xsl uses this name to make list of COM registration
+     actions in Wix. Installer will not able to register COM windows service properly if the name of module
+     differs from SCM windows service name.
+     The Name of windows service is referenced in different places.
+     Don't forget to change it in other places too If you change it here :
+         VBoxMergeApp.wxi (cp_VBoxSDS component),
+         VBoxSDS.cpp and VBoxProxyStub.cpp
+     -->
   <module name="VBoxSDS" context="LocalService">
     <class name="VirtualBoxSDS" uuid="74ab5ffe-8726-4435-aa7e-876d705bcba5"
Index: /trunk/src/VBox/Main/src-all/win/VBoxProxyStub.c
===================================================================
--- /trunk/src/VBox/Main/src-all/win/VBoxProxyStub.c	(revision 70227)
+++ /trunk/src/VBox/Main/src-all/win/VBoxProxyStub.c	(revision 70228)
@@ -1316,4 +1316,10 @@
     const char *pszLocalServer      = "VBoxSVC.exe";
 #ifdef VBOX_WITH_SDS
+    /**
+    * The Name of windows service is referenced in different places.
+    * Don't forget to change it in other places too If you change it here :
+    *      VBoxMergeApp.wxi (cp_VBoxSDS component),
+    *      VBoxSDS.cpp and VirtualBox.xidl
+    */
     const char *pszSdsAppId         = "{EC0E78E8-FA43-43E8-AC0A-02C784C4A4FA}";
     const char *pszSdsExe           = "VBoxSDS.exe";
@@ -2420,5 +2426,5 @@
         if (fDeleteIt)
         {
-            hService = OpenServiceW(hSCM, pwszServiceName, SERVICE_STOP | DELETE);
+            hService = OpenServiceW(hSCM, pwszServiceName, SERVICE_STOP);
             if (hService)
             {
@@ -2462,5 +2468,5 @@
         {
             Assert(pState->fUpdate);
-            hSCM = OpenSCManagerW(NULL, NULL, SC_MANAGER_CREATE_SERVICE | SC_MANAGER_CONNECT);
+            hSCM = OpenSCManagerW(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
             if (hSCM)
             {
@@ -2468,5 +2474,5 @@
                                           pwszServiceName,
                                           pwszDisplayName,
-                                          SERVICE_ALL_ACCESS /* dwDesiredAccess */,
+                                          SERVICE_CHANGE_CONFIG  /* dwDesiredAccess */,
                                           uServiceType,
                                           uStartType,
@@ -2545,4 +2551,10 @@
 
 #ifdef VBOX_WITH_SDS
+        /**
+        * The Name of windows service is referenced in different places.
+        * Don't forget to change it in other places too If you change it here :
+        *      VBoxMergeApp.wxi (cp_VBoxSDS component),
+        *      VBoxSDS.cpp and VirtualBox.xidl
+        */
         vbpsUpdateWindowsService(&State, wszVBoxDir, L"VBoxSDS.exe", L"VBoxSDS",
                                  L"VirtualBox system service", L"Used as a COM server for VirtualBox API.");
