我是PowerShell的新手。 现在的任务是将一些程序固定到任务栏 。 本教程非常棒,在我的Win7 32位版本的Vmware中运行良好。 但是同样的脚本不能在Vmware的Win10 32bit中运行。 所以我修改了代码,最后发现是因为找不到一些动词 。 我的testing代码如下:
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以pipe理员身份运行,结果以及通过右键单击cmd.exefind的“动词”如下所示:
所以请告诉我为什么以及如何解决这个问题,谢谢!
它可能是因为没有位于C:\Windows\
cmd.exe
,请改用它:
$cmd = Join-Path $env:SystemRoot 'System32\cmd.exe'
注意:我使用Join-Path cmdlet来组合路径和$env:SystemRoot
来检索系统根目录(例如C:\Windows
)
你只能使用第一个分隔符和属性上方的动词。 您的程序必须保持运行才能显示属性。
这是一个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