Open Powershell in a specific directory from short

2020-05-13 06:07发布

This sounds like it should be so simple... I must be dumb.

All I want is to make a windows short-cut that opens Powershell into a specific directory:

I'm using the target:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
    -noexit -command {cd c:/path/to/open}

Put it just spits out the command as text.

8条回答
forever°为你锁心
2楼-- · 2020-05-13 06:36

Copy this code into notepad and save with a reg extension. Double click the resulting file.If you get a message about importing to the registry click on yes and then ok. Navigate to any folder in explorer and bring up the context menu. This is typically done by clicking the right mouse button.


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell]
"MUIVerb"="Open in Powershell Window"

[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell\command]
@="c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
查看更多
狗以群分
3楼-- · 2020-05-13 06:39

Ok - you need to use the & parameter to specify it's a powershell comand & the syntax is slightly different:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
-noexit -command "& {cd c:\path\to\open}"
查看更多
你好瞎i
4楼-- · 2020-05-13 06:43

You can also set the "Start in" shortcut field to your desired location.

查看更多
劫难
5楼-- · 2020-05-13 06:45

If you want powershell to start as admin and run in a specific directory, even on a different drive, it is better to use the Set-Location command. Follow these steps

  1. Create a ShortCutLink with the target being the powershellcommand exe.
  2. Leave Start in: blank. (Normally this starts in current working directory when blank; but we do not care.)
  3. Change Target to this with your targets for powershell and locations:

    C:\Windows\...\v1.0\powershell.exe -noexit -command "Set-Location D:\_DCode\Main"

  4. Click Advanced... and select Run as administrator.
  5. Click OKs out.

Don't forget the handy trick to change the colors of the shortcut from the Colors tab. That way if you have two or more links which open powershell windows, seeing a different color can visually let you know which shell one is working in.

查看更多
▲ chillily
6楼-- · 2020-05-13 06:46

try:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
-noexit -command "cd c:/path/to/open"
查看更多
戒情不戒烟
7楼-- · 2020-05-13 06:52

Use this command.

powershell.exe -noexit -command "cd c:\temp"

-NoExit: Do not exit after running startup commands.

查看更多
登录 后发表回答