Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

powershell - This command cannot be run due to the error: Access is denied

I Have an application running on windows server 2019 and Zabbix to monitor that process. I have a powershell script that Zabbix run if the app crash but is not working I get the error "This command cannot be run due to the error: Access is denied."

My script neeeds to send a number and press ENTER to run the app.

Start-Process "c:my_app.exe"
Start-Sleep -s 1
$obj = new-object -ComObject WScript.Shell
$obj.SendKeys("3")
Start-Sleep -s 1
$obj.SendKeys("{ENTER}")

Anyone have a similar situation that works?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

More information would help tbh. Is that script triggered by a scheduled task? I'd go about trying to debug this as follows:

Devise your script into 2 parts.

  1. Part 1 : Start the process
  2. Part 2 : Test if the SendKeys() work

Test each part individually.

My guess is that the user-context you are running your script in, does not have sufficient permissions to start that process. Maybe it has no access to the path? Chances of you not having permission to send a key, are low i'd say.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...