[英]Uninstall Software from Windows Service - Why can I not call MSIEXE.EXE from A Windows Service
I have the following code in a standalone Windows Application to uninstall a program using the key from the registry.我在独立的 Windows 应用程序中有以下代码,用于使用注册表中的密钥卸载程序。 I have used this in many places in the past and it has always worked.. until now that is.过去我在很多地方使用过它,它一直有效......直到现在。
using (Process p = new Process())
{
p.StartInfo.FileName = "MsiExec.exe";
p.StartInfo.Arguments = "/x " + s.RegKey; // + " /qb";
p.StartInfo.WorkingDirectory = @"C:\temp\";
p.Start();
}
It works perfectly.它完美地工作。 I then moved the same code inside a windows service as seen below.然后我在 Windows 服务中移动了相同的代码,如下所示。 This is a KAFKA message being passed from a server app (windows app) to Kafka server and consumed by the windows service.这是从服务器应用程序(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();
}
When I run the lines of code to call MSIEXEC, nothing happens.当我运行代码行来调用 MSIEXEC 时,没有任何反应。 I have tried the exact code in three different places and have played with the commands arguments over and over again.我已经在三个不同的地方尝试了确切的代码,并一遍又一遍地使用命令参数。
Is it because it is in a service?是因为它在服务中吗? Is it because it is in a thread?是因为它在一个线程中吗? The service is running as LocalSystem account.该服务作为 LocalSystem 帐户运行。
I have spend 20+ hours trying to make this work.我已经花了 20 多个小时试图完成这项工作。 Why does it work in one app and not another?为什么它适用于一个应用程序而不是另一个应用程序?
Any help would be greatly appreciated.任何帮助将不胜感激。
***** Nov 25 2020 927 am *** Ok, thank you for informing me of session 0... that helps. ***** 2020 年 11 月 25 日上午 927 点 *** 好的,感谢您通知我第 0 次会议......这有帮助。 Now, since I can already interact with command prompt using PowerShell or DOS, would I be able to send that command using a process现在,由于我已经可以使用 PowerShell 或 DOS 与命令提示符交互,我是否能够使用进程发送该命令
https://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite https://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite
This allowed me to to what I wanted.这让我可以做我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.