我在一个独立的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日上午9:27*好的,感谢您通知我会话0...这很有帮助。现在,既然我已经可以使用PowerShell或DOS与命令提示符进行交互,那么我是否能够使用进程发送该命令
转载请注明出处:http://www.lsql.net/article/20230510/2135950.html