Czy ktoś wie, czy istnieje sposób, aby zainstalować usługę systemu Windows utworzone w języku C# bez instalatora?Jak zainstalować usługę C# Windows bez tworzenia instalatora?
Odpowiedz
Można użyć installutil.
Z wiersza poleceń:
installutil YourWinService.exe
Narzędzie to jest z zainstalowanym .NET Framework
można spróbować okna sc command
C:\WINDOWS\system32>sc create
OPIS: SC jest programem wiersza poleceń używanym do komunikacji z kontrolerem usług i usługami NT.
Dołączam klasę, która wykonuje instalację dla mnie. Wywołuję aplikację przy użyciu parametrów wiersza polecenia, aby zainstalować lub odinstalować aplikację. W przeszłości zawierałem również monit dla użytkownika, czy chciał, aby ta usługa była instalowana po uruchomieniu bezpośrednio z wiersza poleceń.
Oto klasa używam:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.Win32;
namespace [your namespace here]
{
class IntegratedServiceInstaller
{
public void Install(String ServiceName, String DisplayName, String Description,
System.ServiceProcess.ServiceAccount Account,
System.ServiceProcess.ServiceStartMode StartMode)
{
System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
ProcessInstaller.Account = Account;
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
string processPath = Process.GetCurrentProcess().MainModule.FileName;
if (processPath != null && processPath.Length > 0)
{
System.IO.FileInfo fi = new System.IO.FileInfo(processPath);
//Context = new System.Configuration.Install.InstallContext();
//Context.Parameters.Add("assemblyPath", fi.FullName);
//Context.Parameters.Add("startParameters", "Test");
String path = String.Format("/assemblypath={0}", fi.FullName);
String[] cmdline = { path };
Context = new System.Configuration.Install.InstallContext("", cmdline);
}
SINST.Context = Context;
SINST.DisplayName = DisplayName;
SINST.Description = Description;
SINST.ServiceName = ServiceName;
SINST.StartType = StartMode;
SINST.Parent = ProcessInstaller;
// http://bytes.com/forum/thread527221.html
// SINST.ServicesDependedOn = new String[] {};
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
SINST.Install(state);
// http://www.dotnet247.com/247reference/msgs/43/219565.aspx
using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true))
{
try
{
Object sValue = oKey.GetValue("ImagePath");
oKey.SetValue("ImagePath", sValue);
}
catch (Exception Ex)
{
// System.Console.WriteLine(Ex.Message);
}
}
}
public void Uninstall(String ServiceName)
{
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null);
SINST.Context = Context;
SINST.ServiceName = ServiceName;
SINST.Uninstall(null);
}
}
}
A oto jak ja to nazywam:
const string serviceName = "service_name";
const string serviceTitle = "Service Title For Services Control Panel Applet";
const string serviceDescription = "A longer description of what the service does. This is used by the services control panel applet";
// Install
IntegratedServiceInstaller Inst = new IntegratedServiceInstaller();
Inst.Install(serviceName, serviceTitle, serviceDescription,
// System.ServiceProcess.ServiceAccount.LocalService, // this is more secure, but only available in XP and above and WS-2003 and above
System.ServiceProcess.ServiceAccount.LocalSystem, // this is required for WS-2000
System.ServiceProcess.ServiceStartMode.Automatic);
// Uninstall
IntegratedServiceInstaller Inst = new IntegratedServiceInstaller();
Inst.Uninstall(serviceName);
Działa to jak czar. Bardzo przydatny. Dzięki za publikację! –
- 1. Jak zainstalować plik node.js jako usługę Windows?
- 2. Jak zainstalować usługę Windows .NET bez InstallUtil.exe vb.net
- 3. Zainstalować usługę Shield Limited Edition z usługą WIndows
- 4. Jak zainstalować usługę Windows za pomocą Inno Setup?
- 5. Problemy z pakietem Instalatora Windows
- 6. Jak programowo zatrzymać usługę Windows
- 7. Jak utworzyć usługę Windows w języku C/C++?
- 8. Wdrażanie C#/.NET aplikacji bez instalatora ani ClickOnce
- 9. Przekierowanie stdout + stderr na usługę C# Windows
- 10. Jak stworzyć usługę Windows Seler?
- 11. Dowolne przykłady tworzenia usługi Windows w C/C++? (Brak GUI)
- 12. Jak mogę otworzyć porty przez usługę Windows?
- 13. Nie mogę zainstalować instalatora laravel przez kompozytor
- 14. Jak ręcznie zainstalować moduł Pypi bez pip/easy_install?
- 15. Jak zainstalować usługę Windows z wiersza poleceń, podając nazwę i opis?
- 16. Jak prawidłowo zatrzymać wielowątkową usługę Windows .NET?
- 17. Jak zainstalować aplikację Windows 8 bez przesyłania do sklepu
- 18. Jak zainstalować aplikację My C# bez uprawnień administratora?
- 19. Jak utworzyć usługę Windows z słoika Java?
- 20. Zainstaluj Matlab MCR jako część Kreatora Instalatora C#
- 21. Jak zainstalować Perl na Windows 8?
- 22. Jak zainstalować kompas na Windows
- 23. Jak zainstalować apcu w Windows
- 24. Jak zainstalować Poppler na Windows
- 25. Dlaczego 7zip Ignoruj moją InstallPath podczas tworzenia instalatora SFX?
- 26. Testy integracyjne na górnej półce, aby uruchomić usługę Windows # C#
- 27. Jak utworzyć usługę Windows dla Mac OS X?
- 28. Podsystem Windows 10 Linux. Jak zainstalować MongoDB
- 29. Ramy instalatora aplikacji dla systemu Windows
- 30. Określ systemu Windows Nazwa usługi na zainstalować z instalacyjnego Projektu
wierzę, trzeba jeszcze stworzyć instalator w projekcie dla installutil pracować z konfiguracji A dla usługi właściwości: http://www.developer.com/net/net/article.php/11087_2173801_2 –
Dan jest poprawny, nadal musisz utworzyć instalator. Polecenie sc (zobacz poniżej) pozwoli ci zainstalować/usunąć/uruchomić/zatrzymać, itp. Usługę Windows bez konieczności instalowania (co wydaje mi się, w każdym razie, rdzeniem pytania). Jest to przydatne, ponieważ znaczna część metadanych usługi (typ uruchomienia, nazwa konta, właściwości restartu itd.), Które są wypiekane w instalatorze, może być przechowywana na zewnątrz. Jest to podwójnie przydatne w połączeniu ze skryptami do wdrożenia, np. MSBuild lub Nant, ponieważ nie wymaga rekompilacji. Oznacza to również, że można zainstalować, czy jest napisane w C#, C, C++. –
Potrzebujesz klasy "Instalator", ale nie instalatora w sensie pliku setup.exe. – Nathan