0

I've got the following problem:

I want to uninstall and reinstall some software (Symantec EPP), because the automatic update does not work.

In our company we have about 500 clients, so I'd thought that it would be easier to write an automation script.

Unfortunately the silent uninstall is not working, so I have to use the SendKeys-method.

I wrote that Script and it's actually working, but just on some clients. For example, if I run the script on my machine, it sends the virtual keystrokes to the program, if I try to run it on another client, it is actually sending the keys (tested with notepad), but not to the program...

And yes, the window is in the foreground.

My guess is that there might be a problem in the registry - probably it is not "allowed" to send keystrokes to a specific window, but then it should not work in notepad either, right?

Does anybody have an idea, why it is sometimes working and sometimes not?

Burgi
  • 6,768
Vinc12
  • 1

2 Answers2

0

With UAC, installers often run elevated, which doesn't only mean higher privileges but also a higher "integrity level" so that a less-privileged process could not tamper with them. (For example, an unprivileged process cannot inject commands into an elevated PowerShell window. In other words, "no write up".)

So in order to control an installer, the PowerShell script itself has to be running elevated.

grawity
  • 501,077
0

Just run as admin (as suggested by user1686).

I found the following lines of code right here: how to run a powershell script as administrator

I copied that code into my script and immediately it was working fine!

param([switch]$Elevated)

function Test-Admin { $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) }

if ((Test-Admin) -eq $false) { if ($elevated) { # tried to elevate, did not work, aborting } else { Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) } exit }

random
  • 15,201
Vinc12
  • 1