3

For example I'm in C:\Users\User\Desktop\Tools and I'm trying to stay here as admin.

I tried this way, gluing together different commands:

"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit" & -windowstyle hidden -Command Start-Process powershell  -ArgumentList '-NoExit', '-Command cd %V' -Verb runAs""

The PATH changes to C:\WINDOWS\system32 why? How to elevate rights in current directory via simple command?

1 Answer 1

3

Use $PWD from the calling process to change the location on startup:

Start-Process powershell -ArgumentList '-NoExit', "-Command cd '$pwd'; & .\actual\script\you\want\to\run.ps1" -Verb runAs
Sign up to request clarification or add additional context in comments.

1 Comment

work fine Start-Process powershell -ArgumentList '-NoExit', "-Command cd '$pwd'" -Verb runAs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.