2013-01-09 41 views
47

這聽起來像它應該是如此簡單......我一定是愚蠢的。從快捷方式打開特定目錄中的Powershell

所有我想要的是使Windows快捷方式打開PowerShell的到特定目錄:

我使用的目標:

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

把它剛剛吐出來的是命令文本。

任何幫助,將不勝感激。

回答

80

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

+15

如果路徑中有空格,你需要加入''''powershell.exe -noexit -command「cd'c:\ space \ readme.txt'」' – blachniet

+0

正是我在找的東西對於。額外的引號是必要的,包括使用插值路徑時。 –

+3

如果我們討論的是某種快捷方式(如在提示和技巧中),那就是:如果您在Windows資源管理器中的所需文件夾中,可以在地址欄中鍵入'powershell',它將打開PowerShell at那個位置。這也適用於Windows可以通過PATH環境變量找到的'cmd'和任何其他應用程序。 –

3

好 - 你需要使用&參數指定這是一個PowerShell的COMAND &語法稍有不同:

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

這與[Kayasak解決方案](http:///stackoverflow.com/a/14233773/2707864)? –

+0

我在[Hyper](https://hyper.is)中使用了PowerShell,在'.hyper.js'中,我使用瞭如下的解決方案:'shellArgs:['-noexit','&{cd「$ HOME \ \我的舊文件「}']'。我無法制作'['-noexit','-command','「cd」$ HOME \\我的舊文檔「']'或'['-noexit','-command」cd「$ HOME \\我的舊文件「']'工作。 –

+0

舊帖子,但只是幫助我:)我厭倦了作爲管理員卡在system32目錄。謝謝 –

4

嘗試:

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

您還可以將「開始」(Start in)快捷方式字段設置爲您想要的位置。

+1

迄今爲止最簡單的解決方案,特別是如果您嘗試使用帶空格的路徑或奇怪的字符(例如程序文件(x86)下的任何東西) –

+14

「開始」並不適用於我,仍然在c:\ windows \ system32中啓動。 –

+9

是的,如果快捷方式具有「以管理員身份運行「檢查。 – Mica

2

將此密碼複製到記事本中,並以reg擴展名的形式保存。 雙擊生成的文件。如果您收到有關導入註冊表的消息,請單擊是,然後確定。 導航到資源管理器中的任何文件夾並調出上下文菜單。這通常通過單擊鼠標右鍵完成。


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'" 
0
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT 
if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName")) 
{ 
    Try 
    { 
     New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop 
     New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop 
     Write-Host "Successfully!" 
    } 
    Catch 
    { 
     Write-Error $_.Exception.Message 
    } 
} 
else 
{ 
    Write-Warning "The specified key name already exists. Type another name and try again." 
} 

您可以從how to start PowerShell from Windows Explorer

enter image description here

0

如果你想PowerShell來開始作爲管理員,並在特定的目錄中運行下載詳細的腳本,甚至是不同的驅動器上,最好使用Set-Location命令。請按照下列步驟操作

  1. 創建一個ShortCutLink,目標是powershellcommand exe。
  2. 請假Start in:空白。 (通常這開始於當前的工作目錄爲空當,但我們不在乎
  3. 變化Target這與你的目標PowerShell和地點:

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

  4. 點擊Advanced...並選擇Run as administrator
  5. 點擊OK s出來。

不要忘了方便的技巧,從Colors標籤更改快捷方式的顏色。這樣,如果你有兩個或兩個以上的鏈接打開PowerShell的窗口,看到不同的顏色可以通過視覺讓你知道哪個外殼正在工作英寸

相關問題