Windows: start a file using a (non-default) shell verb like “edit” from .bat or command-line

前端 未结 4 798
醉话见心
醉话见心 2021-02-15 16:20

How can I start a file with an associated non-default command (shell verb) like \"edit\", \"print\", ... from command-line or from a .bat script by usi

4条回答
  •  攒了一身酷
    2021-02-15 16:51

    As learned from the comments and after further searching: there seems to be no direct command for that task in standard Windows indeed.
    However using a VBScript snippet should be highly compatible and have lowest system requirements. (Works on all machines here directly - from XP - unlike JScript)

    VBScript has been installed by default in every desktop release of Microsoft Windows since Windows 98;1 in Windows Server since Windows NT 4.0 Option Pack;[2] and optionally with Windows CE (depending on the device it is installed on).

    Example script shellexec.vbs :

    ' shellexec.vbs : starts a file using a (non-default) shell verb like "EDIT"
    ' Usage: shellexec.vbs FILE VERB
    ' Example: shellexec.vbs demo.png EDIT
    fn = WScript.Arguments(0)
    cmd = WScript.Arguments(1)
    Wscript.Echo "ShellExecute """ + cmd + """ on " + fn
    CreateObject("shell.application").ShellExecute fn, "", "", cmd, 1
    

    Use from command-line or batch-file:

    shellexec.vbs demo.png EDIT
    

    or:

    cscript.exe //Nologo shellexec.vbs demo.png EDIT
    

提交回复
热议问题