Vbscript VB脚本的等效%username%
我希望从当前用户的计算机上删除OfficeFileCache文件夹。目前我有Vbscript VB脚本的等效%username%,vbscript,Vbscript,我希望从当前用户的计算机上删除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.ex
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脚本中寻找与用户名等效的名称 如有疑问,请阅读:
ExpandEnvironmentStrings方法
返回环境变量的展开值
就你而言:
fso.DeleteFolder obj.ExpandEnvironmentStrings("C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache")
如果您使用的路径类似于
C:\Users\%username%\AppData\Local\...
这样更好:
%LocalAppData%\...
所以
如果用户将其
%UserProfile%
设置到另一个目录,则效果会更好。只需:fso.DeleteFolder obj.expandEnvironmentString(“C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache”)
Fso.DeleteFolder Obj.ExpandEnvironmentStrings("%LocalAppData%\Microsoft\Office\16.0\OfficeFileCache")