[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] [已解决]PowerShell如何根据是否存在指定文件并调用相应程序?

本帖最后由 awk 于 2013-7-7 19:16 编辑

判断当前用户的%userprofile%目录(比如C:\Documents and Settings\用户名\)下面有没有.log日志文件。
如果有,执行C:\Program Files (x86)\下面的QQ.exe
如果没有,执行C:\Program Files (x86)\下面的CS.exe
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

回复 2# PowerShell


    log文件名是不确定的,可能是a.log、b.log、c.log等

TOP

回复 4# PowerShell


我把这个代码保存为test.ps1
  1. $TEST_PATH = $env:USERPROFILE + '\*.log'
  2. if (test-path $TEST_PATH)
  3. {
  4.     start-process  "C:\Program Files (x86)\a.txt"
  5. }
  6. else
  7. {
  8.     start-process  "C:\Program Files (x86)\b.txt"
  9. }
复制代码
在cmd窗口里面执行test.ps1
发现记事本打开了test.ps1,而不是a.txt或者b.txt,如何解决?

TOP

回复 7# lxzzr


我安装这个方式执行的时候报错信息如下:
  1. File E:\Test\test.ps1 cannot be loaded because the execution of scripts is
  2. disabled on this system. Please see "get-help about_signing" for more details.
  3.     + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordE
  4.    xception
  5.     + FullyQualifiedErrorId : RuntimeException
复制代码
请问如何解决?

TOP

回复 9# lxzzr


    可以了。多谢!

TOP

返回列表