I want to run the schtasks.exe as administrator using PowerShell -Command
with Start-Process
to create a task.
This is the code of my .bat
file I've got so far.
set mydir=%~dp0
set mydir2=%mydir%prim.exe
set mys='`"C:\workspace\prim.exe`"'
Powershell -Command "&{Start-Process -FilePath schtasks -ArgumentList '/Create', '/SC ONLOGON', '/TN CoUpdater', '/IT', '/RL HIGHEST', '/TR', '\"%mydir2%\"' -verb RunAs}"
At first I set up my path to the program I want to run. The problem is that my path name contains some white spaces. After some research I was able to determine that the path is in the task scheduler but without quotes (argument after /TR ):
The next thing I did was adding of quotes to a string and put it as the argument after /TR
set mys='`"C:\workspace\prim.exe`"'
But now I don't know how I should add the quotes to my pathname. I hope anybody can help me with this problem. Thank you!