I have the following code in a standalone Windows Application to uninstall a program using the key from the registry. 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. This is a KAFKA message being passed from a server app (windows app) to Kafka server and consumed by the windows service.
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. 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.
I have spend 20+ hours trying to make this work. 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. Now, since I can already interact with command prompt using PowerShell or DOS, would I be able to send that command using a process
https://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite
This allowed me to to what I wanted.