Results 1 to 19 of 19

Thread: Windows Service

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Windows Service

    I'm trying to run the service I just created, but I get an error.

    I folowed the instructions here:
    http://www.developerfusion.co.uk/show/3441/3/

    And I get this:
    Code:
    C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705>installutil C:\Documents and Settin
    gs\******\My Documents\Visual Studio 2005\Projects\DriveMonitor\DriveMonitor\bin\
    Release\DriveMonitor.exe
    Microsoft (R) .NET Framework Installation utility Version 1.0.3705.0
    Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
    
    Exception occurred while initializing the installation:
    System.IO.FileNotFoundException: File or assembly name Documents, or one of its
    dependencies, was not found..
    Anyone knows what's wrong ?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Anyone ?

  3. #3
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: Windows Service

    Well it looks like it's saying there is a file that it needs, in order to be installed (a dependancy), that wasn't included in the setup package.
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    I'm not making a setup package, I just want to run my service on my own computer...

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: Windows Service

    You gotta create a setup package. You have to make sure all dependances are installed and all files included, even to run it on your own computer.
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Quote Originally Posted by warrenayen
    You gotta create a setup package.
    OK, and how do I do that ?

  7. #7
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: Windows Service

    Start a new project, go to "Setup And Deployment Projects", and create a new one. Add the Service's EXE to the project, and it'll add all the dependancies. Build and distribute.
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Thanks, I'll try it as soon as I get home (tonight)

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Quote Originally Posted by warrenayen
    Start a new project, go to "Setup And Deployment Projects", and create a new one. Add the Service's EXE to the project, and it'll add all the dependancies. Build and distribute.
    I tried, but I have no idea how to make the setup... I need i'll need a link with a tutorial or something

    Anyways, i've been reading around the net about that error, and I read that it may be because it cannot find the file, so I copied the whole \Release directory in the C drive, and now I get a diferent error:
    Code:
    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322>installutil C:\Release\DriveMonitor
    .exe
    Microsoft (R) .NET Framework Installation utility Version 1.1.4322.573
    Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
    
    Exception occurred while initializing the installation:
    System.BadImageFormatException: The format of the file 'DriveMonitor.exe' is inv
    alid..

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Bump...

    ANYONE

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Looks like i'm on my own on this one...

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    Quote Originally Posted by craigreilly
    Why would you have to install it on your OWN machine? Is it not the same as the Devleopment machine?
    How else am I supposed to test it ?

    I made the program, I just want to test it !

    If something is not working, then I have to fix it, then test again, and so on...

    And as I was saying in post #9, I copied and pasted the whole Release directory in the C drive, because then it won't be any spaces, and tried to run it from there.

    And from the error: "System.BadImageFormatException: The format of the file 'DriveMonitor.exe' is invalid.."
    it does not seem like that is the problem, because it does tell me that 'DriveMonitor.exe' is invalid, so it knows where the file is...

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Windows Service

    Wouldnt the framework version be 2.0 and not 1.1?

    From your path...
    v1.1.4322
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Windows Service

    I'm using Microsoft.NET 2005, is that Framework 2.0 ?

    I just folowed the instructions in that link... it's my first time to do this...

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Windows Service

    Yes, 2005 is framework 2.0 so the path will be different and contain different files.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Windows Service

    Heya,
    If you are still interested about windows services have a look at this link:

    The tutorial creates a windows services and also installs it in a very easy way. Mind you Im no expert but I have been looking for one lately and think its a very good tutorial.

    Good Luck.

    If you can help me one this Im looking for a windows services on giving permissions on folders... Any idea please where I can find tutorials?

  17. #17
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: Windows Service

    Hi,

    Here is C# code to install and uninstall Windows Service.

    VB Code:
    1. using System;
    2. using System.Runtime.InteropServices;
    3.  
    4. namespace McoreSystem
    5. {
    6.     /// <summary>
    7.     /// Summary description for ServiceInstaller.
    8.     /// </summary>
    9.     public class ServiceAdmin
    10.     {
    11.         #region Private Variables
    12.  
    13. //      private string _servicePath;
    14. //      private string _serviceName;
    15. //      private string _serviceDisplayName;
    16.  
    17.         #endregion Private Variables
    18.  
    19.         #region DLLImport
    20.  
    21.         [DllImport("advapi32.dll")]
    22.         private static extern IntPtr OpenSCManager(string lpMachineName,string lpSCDB, int scParameter);
    23.         [DllImport("Advapi32.dll")]
    24.         private static extern IntPtr CreateService(IntPtr SC_HANDLE,string lpSvcName,string lpDisplayName,
    25.             int dwDesiredAccess,int dwServiceType,int dwStartType,int dwErrorControl,string lpPathName,
    26.             string lpLoadOrderGroup,int lpdwTagId,string lpDependencies,string lpServiceStartName,string lpPassword);
    27.         [DllImport("advapi32.dll")]
    28.         private static extern void CloseServiceHandle(IntPtr SCHANDLE);
    29.         [DllImport("advapi32.dll")]
    30.         private static extern int StartService(IntPtr SVHANDLE,int dwNumServiceArgs,string lpServiceArgVectors);
    31.  
    32.         [DllImport("advapi32.dll",SetLastError=true)]
    33.         private static extern IntPtr OpenService(IntPtr SCHANDLE,string lpSvcName,int dwNumServiceArgs);
    34.         [DllImport("advapi32.dll")]
    35.         private static extern int DeleteService(IntPtr SVHANDLE);
    36.  
    37.         [DllImport("kernel32.dll")]
    38.         private static extern int GetLastError();
    39.  
    40.         #endregion DLLImport
    41.  
    42.  
    43.         /// <summary>
    44.         /// The main entry point for the application.
    45.         /// </summary>
    46.         #region Main method + testing code
    47.         [STAThread]
    48.         static void Main(string[] args)
    49.         {
    50.      
    51.             // TODO: Add code to start application here
    52.      
    53.    
    54.             #region Testing
    55.             //  Testing --------------
    56.             string ServicePath;
    57.             string ServiceName;
    58.             string ServiceDisplayName;
    59.      
    60.             //path to the service that you want to install
    61.             ServicePath = @"C:\build\service\Debug\Service.exe";
    62.             ServiceName= "Service Name";
    63.             ServiceDisplayName="Service Display Name";  
    64.             ServiceAdmin c = new ServiceAdmin();
    65.             c.InstallService(ServicePath, ServiceName, ServiceDisplayName);
    66.             Console.Read();
    67.             // Testing --------------
    68.             #endregion Testing
    69.             }
    70.         #endregion Main method + testing code - Commented
    71.  
    72.  
    73.         /// <summary>
    74.         /// Adds the service description to the registry.
    75.         /// </summary>
    76.         /// <param name="serviceName"></param>
    77.         /// <param name="description"></param>
    78.         public virtual void AddServiceDescriptionToRegistry(string serviceName, string description)
    79.         {
    80.             Microsoft.Win32.RegistryKey system;
    81.             Microsoft.Win32.RegistryKey    currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet
    82.             Microsoft.Win32.RegistryKey services; //...\Services
    83.             Microsoft.Win32.RegistryKey service; //...\<Service Name>
    84.             Microsoft.Win32.RegistryKey config; //...\Parameters - this is where you can put service-specific configuration
    85.             try
    86.             {
    87.                 //Open the HKEY_LOCAL_MACHINE\SYSTEM key
    88.                 system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
    89.                 //Open CurrentControlSet
    90.                 currentControlSet = system.OpenSubKey("CurrentControlSet");
    91.                 //Go to the services key
    92.                 services = currentControlSet.OpenSubKey("Services");
    93.                 //Open the key for your service, and allow writing
    94.                 service = services.OpenSubKey(serviceName, true);
    95.                 //Add your service's description as a REG_SZ value named "Description"
    96.                 service.SetValue("Description", description);
    97.                 //(Optional) Add some custom information your service will use...
    98.                 config = service.CreateSubKey("Parameters");
    99.             }
    100.             catch(Exception)
    101.             {
    102.                 //Log.Error("Error occurred while attempting to add a service description to the registry.", e);
    103.             }
    104.         }
    105.         /// <summary>
    106.         /// Removes the service description from the registry.
    107.         /// </summary>
    108.         /// <param name="serviceName"></param>
    109.         public virtual void RemoveServiceDescriptionFromRegistry(string serviceName)
    110.         {
    111.             Microsoft.Win32.RegistryKey system;
    112.             Microsoft.Win32.RegistryKey    currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet
    113.             Microsoft.Win32.RegistryKey services; //...\Services
    114.             Microsoft.Win32.RegistryKey service; //...\<Service Name>
    115.             // Microsoft.Win32.RegistryKey config; //...\Parameters - this is where you can put service-specific configuration
    116.             try
    117.             {
    118.                 //Drill down to the service key and open it with write permission
    119.                 system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
    120.                 currentControlSet = system.OpenSubKey("CurrentControlSet");
    121.                 services = currentControlSet.OpenSubKey("Services");
    122.                 service = services.OpenSubKey(serviceName, true);
    123.                 //Delete any keys you created during installation (or that your service created)
    124.                 service.DeleteSubKeyTree("Parameters");
    125.                 //...
    126.             }
    127.             catch(Exception)
    128.             {
    129.                 //Log.Error("Error occurred while trying to remove the service description from the registry.", e);
    130.             }
    131.         }
    132.  
    133.         /// <summary>
    134.         /// This method installs and runs the service in the service conrol manager.
    135.         /// </summary>
    136.         /// <param name="ServicePath">The complete path of the service.</param>
    137.         /// <param name="ServiceName">Name of the service.</param>
    138.         /// <param name="ServiceDisplayName">Display name of the service.</param>
    139.         /// <returns>True if the process went thro successfully. False if there was any error.</returns>
    140.         public bool InstallService(string ServicePath, string ServiceName, string ServiceDisplayName)
    141.         {
    142.             #region Constants declaration.
    143.             int SC_MANAGER_CREATE_SERVICE = 0x0002;
    144.             int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
    145.             //int SERVICE_DEMAND_START = 0x00000003;
    146.             int SERVICE_ERROR_NORMAL = 0x00000001;
    147.  
    148.             int STANDARD_RIGHTS_REQUIRED = 0xF0000;
    149.             int SERVICE_QUERY_CONFIG       =    0x0001;
    150.             int SERVICE_CHANGE_CONFIG       =   0x0002;
    151.             int SERVICE_QUERY_STATUS           =  0x0004;
    152.             int SERVICE_ENUMERATE_DEPENDENTS   = 0x0008;
    153.             int SERVICE_START                  =0x0010;
    154.             int SERVICE_STOP                   =0x0020;
    155.             int SERVICE_PAUSE_CONTINUE         =0x0040;
    156.             int SERVICE_INTERROGATE            =0x0080;
    157.             int SERVICE_USER_DEFINED_CONTROL   =0x0100;
    158.  
    159.             int SERVICE_ALL_ACCESS             =  (STANDARD_RIGHTS_REQUIRED     |
    160.                 SERVICE_QUERY_CONFIG         |
    161.                 SERVICE_CHANGE_CONFIG        |
    162.                 SERVICE_QUERY_STATUS         |
    163.                 SERVICE_ENUMERATE_DEPENDENTS |
    164.                 SERVICE_START                |
    165.                 SERVICE_STOP                 |
    166.                 SERVICE_PAUSE_CONTINUE       |
    167.                 SERVICE_INTERROGATE          |
    168.                 SERVICE_USER_DEFINED_CONTROL);
    169.             int SERVICE_AUTO_START = 0x00000002;
    170.             #endregion Constants declaration.
    171.  
    172.             try
    173.             {
    174.                 IntPtr  sc_handle = OpenSCManager(null,null,SC_MANAGER_CREATE_SERVICE);
    175.  
    176.                 if (sc_handle.ToInt32() != 0)
    177.                 {
    178.                     IntPtr sv_handle = CreateService(sc_handle,ServiceName,ServiceDisplayName,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,ServicePath,null,0,null,null,null);
    179.  
    180.                     if(sv_handle.ToInt32() ==0)
    181.                     {
    182.  
    183.                         CloseServiceHandle(sc_handle);
    184.                         return false;
    185.                     }
    186.                     else
    187.                     {
    188.                         //now trying to start the service
    189.                         int i = StartService(sv_handle,0,null);
    190.                         // If the value i is zero, then there was an error starting the service.
    191.                         // note: error may arise if the service is already running or some other problem.
    192.                         if(i==0)
    193.                         {
    194.                             //Console.WriteLine("Couldnt start service");
    195.                             return false;
    196.                         }
    197.                         //Console.WriteLine("Success");
    198.                         CloseServiceHandle(sc_handle);
    199.                         return true;
    200.                     }
    201.                 }
    202.                 else
    203.                     //Console.WriteLine("SCM not opened successfully");
    204.                     return false;
    205.  
    206.             }
    207.             catch(Exception e)
    208.             {
    209.                 throw e;
    210.             }
    211.         }
    212.  
    213.  
    214.         /// <summary>
    215.         /// This method uninstalls the service from the service conrol manager.
    216.         /// </summary>
    217.         /// <param name="ServiceName">Name of the service to uninstall.</param>
    218.         public bool UnInstallService(string ServiceName)
    219.         {
    220.             int GENERIC_WRITE = 0x40000000;
    221.             IntPtr sc_hndl = OpenSCManager(null,null,GENERIC_WRITE);
    222.  
    223.             if(sc_hndl.ToInt32() !=0)
    224.             {
    225.                 int DELETE = 0x10000;
    226.                 IntPtr svc_hndl = OpenService(sc_hndl,ServiceName,DELETE);
    227.                 //Console.WriteLine(svc_hndl.ToInt32());
    228.                 if(svc_hndl.ToInt32() !=0)
    229.                 {
    230.                     int i = DeleteService(svc_hndl);
    231.                     if (i != 0)
    232.                     {
    233.                         CloseServiceHandle(sc_hndl);
    234.                         return true;
    235.                     }
    236.                     else
    237.                     {
    238.                         CloseServiceHandle(sc_hndl);
    239.                         return false;
    240.                     }
    241.                 }
    242.                 else
    243.                     return false;
    244.             }
    245.             else
    246.                 return false;
    247.         }
    248.     }
    249.  
    250. }

  18. #18
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: Windows Service

    Here is a higher level VB.NET code that uses the above C# code to extend functionality.

    VB Code:
    1. Imports System.IO
    2. Imports System.ServiceProcess
    3.  
    4. Public Class cAdminService
    5.  
    6.     Private m_SvcAdmin As New McoreSystem.ServiceAdmin
    7.  
    8.     Public Sub startServiceInternally(ByVal ServiceName As String)
    9.  
    10.         Dim controller As New ServiceController
    11.         controller.MachineName = "."
    12.         If isInstalledService(ServiceName) Then
    13.             If Not isRunningService(ServiceName) Then
    14.                 controller.ServiceName = ServiceName
    15.                 controller.Start()
    16.             End If
    17.         End If
    18.  
    19.     End Sub
    20.  
    21.     Public Sub startServiceExternally(ByVal ServiceName As String)
    22.  
    23.         Dim proc As New System.Diagnostics.Process
    24.         Dim psi As New ProcessStartInfo("net", "start " + Chr(34) + ServiceName + Chr(34))
    25.         proc.StartInfo = psi
    26.         proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    27.         proc.Start()
    28.         proc.WaitForExit()
    29.  
    30.     End Sub
    31.  
    32.     Public Sub stopServiceExternally(ByVal ServiceName As String)
    33.  
    34.         Dim proc As New System.Diagnostics.Process
    35.         Dim psi As New ProcessStartInfo("net", "stop " + Chr(34) + ServiceName + Chr(34))
    36.         proc.StartInfo = psi
    37.         proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    38.         proc.Start()
    39.         proc.WaitForExit()
    40.  
    41.     End Sub
    42.  
    43.     Public Sub stopServiceInternally(ByVal ServiceName As String)
    44.  
    45.         Dim controller As New ServiceController
    46.         controller.MachineName = "."
    47.         controller.ServiceName = ServiceName
    48.         If isInstalledService(ServiceName) Then
    49.             If isRunningService(ServiceName) Then
    50.                 controller.Stop()
    51.             End If
    52.         End If
    53.  
    54.     End Sub
    55.  
    56.     Public Function isInstalledService(ByVal ServiceName As String) As Boolean
    57.  
    58.         'BUG: 1.2.6.1 Incorrectly determined McoreIndexer installed state
    59.         Dim regMcoreIndexerRoot As Microsoft.Win32.RegistryKey = _
    60.           Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services")
    61.         Dim strServices() As String = regMcoreIndexerRoot.GetSubKeyNames
    62.         For Each svc As String In strServices
    63.             If svc = ServiceName Then
    64.                 Return True
    65.             End If
    66.         Next
    67.         Return False
    68.     End Function
    69.  
    70.     Public Function isRunningService(ByVal ServiceName As String) As Boolean
    71.  
    72.         If isInstalledService(ServiceName) Then
    73.             Dim controller As New ServiceController
    74.             controller.MachineName = "."
    75.             controller.ServiceName = ServiceName
    76.             Dim status As String = controller.Status.ToString
    77.             Console.WriteLine(status)
    78.             Return (status = "Running")
    79.         End If
    80.  
    81.     End Function
    82.  
    83.     Public Sub InstallAndRunService(ByVal ServicePath As String, ByVal ServiceName As String)
    84.  
    85.         InstallService(ServicePath, ServiceName)
    86.         startServiceExternally(ServiceName)
    87.  
    88.     End Sub
    89.  
    90.     Public Sub InstallService(ByVal ServicePath As String, ByVal ServiceName As String)
    91.         If Not isInstalledService(ServiceName) Then
    92.             m_SvcAdmin.InstallService(ServicePath, ServiceName, ServiceName)
    93.             m_SvcAdmin.AddServiceDescriptionToRegistry(ServiceName, "Directory Indexing service for TreeGUI")
    94.         End If
    95.     End Sub
    96.  
    97.     Public Sub StopAndUninstallService(ByVal ServiceName As String)
    98.         stopServiceExternally(ServiceName)
    99.         uninstallService(ServiceName)
    100.     End Sub
    101.  
    102.     Private Sub uninstallService(ByVal ServiceName As String)
    103.         If isInstalledService(ServiceName) Then
    104.             m_SvcAdmin.RemoveServiceDescriptionFromRegistry(ServiceName)
    105.             m_SvcAdmin.UnInstallService(ServiceName)
    106.         End If
    107.     End Sub
    108.  
    109.     Public Function isProperlyInstalledService(ByVal TreeGuiPath As String, ByVal ServiceName As String) As Boolean
    110.         Return Me.getProperServicePath(TreeGuiPath, ServiceName) = Me.getCurrentServicePath(ServiceName)
    111.     End Function
    112.  
    113.     Public Function getProperServicePath(ByVal TreeGuiPath As String, ByVal ServiceName As String) As String
    114.         Return TreeGuiPath + "\" + ServiceName + ".exe"
    115.     End Function
    116.  
    117.     Public Function getCurrentServicePath(ByVal ServiceName As String) As String
    118.         Dim regMcoreIndexerRoot As Microsoft.Win32.RegistryKey = _
    119.           Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services")
    120.         Dim strServices() As String = regMcoreIndexerRoot.GetSubKeyNames
    121.         For Each svc As String In strServices
    122.             If svc = ServiceName Then
    123.                 Dim regMcoreIndexer As Microsoft.Win32.RegistryKey = _
    124.                 Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\" + svc)
    125.                 Return regMcoreIndexer.GetValue("ImagePath", "")
    126.             End If
    127.         Next
    128.         Return Nothing
    129.     End Function
    130.  
    131.     Public Function setProperServicePath(ByVal TreeGuiPath As String, ByVal ServiceName As String) As Boolean
    132.  
    133.         stopServiceExternally(ServiceName)
    134.         Dim regMcoreIndexerRoot As Microsoft.Win32.RegistryKey = _
    135.             Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services")
    136.         Dim strServices() As String = regMcoreIndexerRoot.GetSubKeyNames
    137.         For Each svc As String In strServices
    138.             If svc = ServiceName Then
    139.                 Dim regMcoreIndexer As Microsoft.Win32.RegistryKey = _
    140.                 Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\" + svc, True)
    141.                 regMcoreIndexer.SetValue("ImagePath", getProperServicePath(TreeGuiPath, ServiceName))
    142.                 startServiceExternally(ServiceName)
    143.                 Return True
    144.             End If
    145.         Next
    146.  
    147.         Return False
    148.     End Function
    149.  
    150.  
    151. End Class

    Cheers,
    McoreD

  19. #19
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Windows Service

    Hi ~*McoreD*~,


    Ive been trying hard to get somebody who knows how to handle Windows Services, do you have any sample code for creating one. It starts up on boot system and gets the login name ???

    many many thanks !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width