2016-05-27 8 views
1

PowerShellの新機能です。今すぐ仕事はいくつかのプログラムをタスクバーにピンすることです。このTutorialは素晴らしく、私のWin7 32bitのVmwareでうまく動作します。しかし、同じスクリプトはVMWareのWin10 32bitでは動作しません。だから私はコードを修正し、最終的にいくつか動詞が見つかりませんでした。私のテストコードは、次のとおりです。PowerShellで実行可能ファイルの動詞が見つかりません

CLS 
$cmd = 'C:\Windows\System32\cmd.exe' 
Test-Path $cmd 
$Shell = New-Object -ComObject Shell.Application 
$Desktop = $Shell.NameSpace(0X0) 
$itemLnk = $Desktop.ParseName($cmd) 
$itemVerbs = $itemLnk.Verbs() 
Foreach($v in $itemVerbs) 
{ 
    write-host $v.Name 
} 

ISEが管理し、その結果として実行されるだけでなく、mannually右のcmd.exeをクリックすると表示さ「動詞」は、下記のように示されている: enter image description here enter image description here

なぜ、どのようにこれを修正するか教えてください、ありがとうございます! C:\Windows\に位置一切cmd.exeがないため

+0

コード全体を共有してください。例えば。 '$ item'とは何ですか? –

+0

@jisaakこれはタイプミスで、更新しました。確認してください。 –

答えて

1

ITSはおそらく、代わりにこれを使用する:

$cmd = Join-Path $env:SystemRoot 'System32\cmd.exe' 

注:Imは、システムのルートを取得するために$env:SystemRootをパスを結合するJoin-Pathコマンドレットを使用して(例えばC:\Windows

+0

私はそれほど愚かではありません。スクリプトでSystemRootを使用していましたが、私はC:を使用しています。 –

+0

私の答えを読む。間違ったsystemRootに起因するものではなく、system32サブフォルダがないため... –

+0

あなたは正しいですが、私は再び更新しましたが、同じ問題です。 –

1

最初のセパレータとプロパティの上にある動詞のみを使用できます。プロパティを表示するには、プログラムを実行し続けなければなりません。

動詞をリストして実行するVBScriptがあります。 ShVerb.vbs /?上記を読む。

HelpMsg = vbcrlf & " ShVerb" & vbcrlf & vbcrlf & " 2014" & vbcrlf & vbcrlf & " Lists or runs an explorer verb (right click menu) on a file or folder" & vbcrlf & vbcrlf & " ShVerb <filename> [verb]" & vbcrlf & vbcrlf & " Used without a verb it lists the verbs available for the file or folder" & vbcrlf & vbcrlf 
HelpMsg = HelpMsg & " The program lists most verbs but only ones above the first separator" & vbcrlf & " of the menu work when used this way" & vbcrlf & vbcrlf 
HelpMsg = HelpMsg & " The Properties verb can be used. However the program has to keep running" & vbcrlf & " to hold the properties dialog open. It keeps running by displaying" & vbcrlf & " a message box." 
Set objShell = CreateObject("Shell.Application") 
Set Ag = WScript.Arguments 
set WshShell = WScript.CreateObject("WScript.Shell") 
Set fso = CreateObject("Scripting.FileSystemObject") 

    If Ag.count = 0 then 
     wscript.echo " ShVerb - No file specified" 
     wscript.echo HelpMsg 
     wscript.quit 
    Else If Ag.count = 1 then 
     If LCase(Replace(Ag(0),"-", "/")) = "/h" or Replace(Ag(0),"-", "/") = "/?" then 
      wscript.echo HelpMsg 
      wscript.quit 
     End If 
    ElseIf Ag.count > 2 then 
     wscript.echo vbcrlf & " ShVerb - To many parameters" & vbcrlf & " Use quotes around filenames and verbs containing spaces" & vbcrlf 
     wscript.echo HelpMsg 
     wscript.quit 
    End If 

    If fso.DriveExists(Ag(0)) = True then 
     Set objFolder = objShell.Namespace(fso.GetFileName(Ag(0))) 
'  Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0))) 
     Set objFolderItem = objFolder.self 
     msgbox ag(0) 
    ElseIf fso.FolderExists(Ag(0)) = True then 
     Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0))) 
     Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0))) 
    ElseIf fso.fileExists(Ag(0)) = True then 
     Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0))) 
     Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0))) 
    Else 
     wscript.echo " ShVerb - " & Ag(0) & " not found" 
     wscript.echo HelpMsg 
     wscript.quit 
    End If 

    Set objVerbs = objFolderItem.Verbs 

    'If only one argument list verbs for that item 

    If Ag.count = 1 then 
     For Each cmd in objFolderItem.Verbs 
      If len(cmd) <> 0 then CmdList = CmdList & vbcrlf & replace(cmd.name, "&", "") 
     Next 
     wscript.echo mid(CmdList, 2) 

    'If two arguments do verbs for that item 

    ElseIf Ag.count = 2 then 
     For Each cmd in objFolderItem.Verbs 
      If lcase(replace(cmd, "&", "")) = LCase(Ag(1)) then 
       wscript.echo(Cmd.doit) 
       Exit For 
      End If 
     Next 
    'Properties is special cased. Script has to stay running for Properties dialog to show. 
     If Lcase(Ag(1)) = "properties" then 
      WSHShell.AppActivate(ObjFolderItem.Name & " Properties") 
      msgbox "This message box has to stay open to keep the " & ObjFolderItem.Name & " Properties dialog open." 
     End If 
    End If 
End If 
+0

申し訳ありませんが、質問はpowershellについてです。 –

+0

WindowsシェルのCOMインターフェイスに関する質問はありません。上のコードで説明しているように、PowerShellコードと同じですが、使用できる動詞と使用できない動詞は何ですか?基本的には、コンテキストメニュー拡張やCutなどの内部コマンドは使用できません。プログラムを実行すると、使用できる動詞がわかります。 –

+0

あなたは**理由**を説明しましたが、**どのように**ですか? –

関連する問題