防止普通用户卸载我的Windows服务

时间:2018-09-04 10:41:26

标签: c# windows-services

我已经创建了一个Windows服务,并且现在我想阻止普通用户卸载我的服务,所以我已经成功在我的计算机上成功安装了它,这意味着有人需要从那里的计算机上卸载我的Windows服务,然后需要特殊的凭据才能卸载该服务/ p>

任何人都可以建议我该怎么做

我的服务启动方法的结构是这样

static void Main(string[] args)
        {

            if (Environment.UserInteractive)
            {
                Console.WriteLine("TimeClockGetDataService");
                Console.WriteLine();
                switch (args.FirstOrDefault())
                {
                    case "/install":
                        ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
                        break;
                    case "/uninstall":
                        ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
                        break;
                    case "/interactive":
                        using (TimeClockPuchDataGetService service = new TimeClockPuchDataGetService())
                        {
                            service.OnStart(args);
                            Console.WriteLine("Press any key to stop the program");
                            Console.Read();
                            service.Stop();
                            //service.GetDataFromPunchingMachin();
                        }
                        break;
                    default:
                        Console.WriteLine("Supported arguments:");
                        Console.WriteLine(" /install      Install the service");
                        Console.WriteLine(" /uninstall    Uninstall the service");
                        Console.WriteLine(" /interactive  Run the service interactively (on the console)");
                        break;
                }
            }
            else
            {
                Run(new TimeClockPuchDataGetService());
            }
        }

0 个答案:

没有答案