从 Windows 服务卸载软件 - 为什么我不能从 Windows 服务调用 MSIEXE.EXE

Uninstall Software from Windows Service - Why can I not call MSIEXE.EXE from A Windows Service

我在独立的 Windows 应用程序中有以下代码,用于使用注册表中的密钥卸载程序。我过去在很多地方都用过这个,它一直有效..直到现在。

        using (Process p = new Process())
        {
            p.StartInfo.FileName = "MsiExec.exe";
            p.StartInfo.Arguments = "/x " + s.RegKey; // + " /qb";
            p.StartInfo.WorkingDirectory = @"C:\temp\";
            p.Start();
        }

效果很好。然后我将相同的代码移动到 windows 服务中,如下所示。这是从服务器应用程序(windows 应用程序)传递到 Kafka 服务器并由 windows 服务使用的 KAFKA 消息。

var readMessagesThread = new Thread(() =>
            {
                var consumerConfig = new ConsumerConfig
                {
                    GroupId = "Consumer-Group",
                    BootstrapServers = Global.KafkaServerURI,
                    MessageMaxBytes = Global.MessageMaxBytes,
                    AllowAutoCreateTopics = true,
                    FetchMaxBytes = Global.MessageMaxBytes
                };

                var cons = new ConsumerBuilder<Ignore, string>(consumerConfig).Build();
                cons.Subscribe("chat-topic");

                var cts = new CancellationTokenSource();
                Console.CancelKeyPress += (_, e) =>
                {
                    e.Cancel = true;
                    cts.Cancel();
                };

                try
                {
                    while (true)
                        try
                        {
                            ConsumeResult<Ignore, string> cr = cons.Consume(cts.Token);

                            string decryptedMessage = Encryption.DecryptString(Global.AUTH_KEY, cr.Message.Value);
                            Message deserializedMessage = JsonConvert.DeserializeObject<Message>(decryptedMessage);
                            
                            switch (deserializedMessage.MessageType)
                            {
                                case Global.MessageType.UninstallSoftware:
                                
                               ******  Call function which has the same lines of code as above **
                                Break;
                            }
                        }

                        catch (ConsumeException e)
                        {
                            Console.WriteLine(e);
                        }
                }
                catch (Exception e)
                {
                    cons.Close();
                }

            });

            readMessagesThread.Start();
        }

当我运行代码行调用MSIEXEC时,没有任何反应。 我在三个不同的地方尝试了确切的代码,并一遍又一遍地使用命令参数。

是因为在服务中吗?是因为它在线程中吗? 该服务 运行正在使用 LocalSystem 帐户。

我花了 20 多个小时来完成这项工作。 为什么它在一个应用程序中有效,而在另一个应用程序中无效?

如有任何帮助,我们将不胜感激。

***** 2020 年 11 月 25 日 927 am *** 好的,谢谢你通知我会话 0... 这很有帮助。 现在,由于我已经可以使用 PowerShell 或 DOS 与命令提示符进行交互,我是否能够使用进程

发送该命令

https://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite

这让我得到了我想要的东西。