【问题标题】:Equivalent %username% for VB scriptVB 脚本的等效 %username%
【发布时间】:2018-04-17 16:49:58
【问题描述】:

我希望从当前用户的计算机中删除 OfficeFileCache 文件夹。目前我有..

Option Explicit
Dim obj : Set obj =CreateObject ("wscript.shell")
Dim fso : Set fso =CreateObject ("scripting.FileSystemObject")

obj.Run "taskkill /f /im msouc.exe.exe",0
obj.Run "taskkill /f /im msosync.exe.exe",0

fso.DeleteFolder "C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache"

最后一部分是我遇到的麻烦。只是在 VB 脚本中寻找与用户名等效的内容。

【问题讨论】:

  • 简单地说:fso.DeleteFolder obj.ExpandEnvironmentStrings("C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache")

标签: vbscript


【解决方案1】:

如有疑问,请阅读documentation

ExpandEnvironmentStrings 方法

返回环境变量的扩展值。

在你的情况下:

fso.DeleteFolder obj.ExpandEnvironmentStrings("C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache")

【讨论】:

    【解决方案2】:

    如果你正在使用类似的路径

    C:\Users\%username%\AppData\Local\...
    

    这样更好:

    %LocalAppData%\...
    

    所以

    Fso.DeleteFolder Obj.ExpandEnvironmentStrings("%LocalAppData%\Microsoft\Office\16.0\OfficeFileCache")
    

    这样做会更好,以防用户将他们的%UserProfile% 设置为另一个目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-26
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2010-09-05
      相关资源
      最近更新 更多