When you start powerhell from the batch, it opens for a moment and closes immediately.

Asked 1 years ago, Updated 1 years ago, 484 views

1.Periodic execution of bat file

@powershell-NoProfile-ExecutionPolicy unlimited-Command "Start-Process PowerShell.exe-Verb runas C:\********\****.ps1"

2.ps1 starts and performs actions with administrator privileges

 if(!([Security.Principal.WindowsPrincipal.Security.Principal.WindowsIdentity]::GetCurrent().IsInRole("Administrators")){Start-Process powerhell.exe"-File`"$PSCommandPath`"-VerbRunAs;exit}
Set-ExecutionPolicy RemoteSigned
-- The following is the execution script:

In step 2, you can see where ps opens with administrator privileges, but the screen closes in an instant and subsequent actions are not performed.
You have permission.
Enter a description of the image here

It is difficult to determine the cause because it closes in an instant.
I can't find a solution to the problem.
If anyone knows anything, could you give me a hint?

windows powershell batch-file

2022-12-12 10:08

1 Answers

Thank you for your comment.
The reason was that the path of calling ps1 from bat was garbled.
Changing the user helped solve this problem.


2022-12-12 13:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.