[英]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 点 *** 好的,感谢您通知我第 0 次会议......这有帮助。 现在,由于我已经可以使用 PowerShell 或 DOS 与命令提示符交互,我是否能够使用进程发送该命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.