分享

工具——Windows下使用vbs脚本打开文件夹或软件

 昵称68737584 2020-10-12

Windows下使用vbs脚本打开文件夹或软件

打开文件夹:

1、在“C:\my_script”目录下创建open_dir.vbs脚本文件:

Set objShell = CreateObject('Wscript.Shell')
strPath = Wscript.Arguments(0)
strPath = 'explorer.exe /e,' & strPath
objShell.Run strPath

其中,“Set objShell = CreateObject('Wscript.Shell')”行表示打开一个窗口; “strPath = 'explorer.exe /e,' & strPath”行表示:以资源浏览器的方式打开文件夹;

2、在在该目录下创建open_dir.bat批处理文件:

cd C:\my_script
open_dir.vbs 'D:\Shared_Dir\ShareDir'
open_dir.vbs 'E:\Proj_Code\SVN\C15'

其中,open_dir.vbs 'D:\Shared_Dir\ShareDir'行中后面的参数路径'D:\Shared_Dir\ShareDir'会传递给上面的“strPath”,并且应该是绝对路径;

打开软件:

创建open_software.vbs文件:

'open working software

Program1 = 'D:\Soft_Pro\fm70chb1_92_chs\Foxmail.exe'  
Program2 = 'D:\Soft_Pro\imo\i'm office\IMOClient.exe'

Set WshShell=createobject('wscript.shell')
Set oExec=WshShell.Exec(Program1)
Set WshShell=createobject('wscript.shell')
Set oExec=WshShell.Exec(Program2)

其中,Program1是所要打开的软件的 绝对路径;Set WshShell=createobject('wscript.shell')和Set oExec=WshShell.Exec(Program1)行表示在新建的窗口中执行打开一个路径为(Program1)的软件的命令;

附:vbs脚本中的注释符号 (’),如上例中的  'open working software;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多