I am looking to delete OfficeFileCache folder from the current user's computer. Currently I have..
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"
The last part is what I am having trouble with. Just looking for an equivalent to usernames within a VB script.
When in doubt, read the documentation:
ExpandEnvironmentStrings Method
Returns an environment variable's expanded value.
In your case:
fso.DeleteFolder obj.ExpandEnvironmentStrings("C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\OfficeFileCache")
If you're using some path like
C:\Users\%username%\AppData\Local\...
This is better:
%LocalAppData%\...
So
Fso.DeleteFolder Obj.ExpandEnvironmentStrings("%LocalAppData%\Microsoft\Office\16.0\OfficeFileCache")
does it better, in case the user set their %UserProfile%
to another directory.
来源:https://stackoverflow.com/questions/49883514/equivalent-username-for-vb-script