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
1.3k views
in Technique[技术] by (71.8m points)

powershell - Start-Process -WorkingDirectory as administrator does not set location

When I enter the command

Start-Process powershell -WorkingDirectory "D:folder"

it opens new PowerShell window with D:folder location set.

But when I enter the command

Start-Process powershell -WorkingDirectory "D:folder" -Verb RunAs

it opens new PowerShell window with admin rights but with C:Windowssystem32 location set.

How can I open new PowerShell window with admin rights and my own location determined?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

I also had the same problem and solved it with this command:

Start-Process powershell.exe -verb runAs -ArgumentList '-NoExit', '-Command', 'cd D:folder'

Once you run the above command, Windows will launch with admin authority and the specified directory.


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

...