0

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\Office16円.0\OfficeFileCache"

The last part is what I am having trouble with. Just looking for an equivalent to usernames within a VB script.

Visual Vincent
18.4k5 gold badges33 silver badges83 bronze badges
asked Apr 17, 2018 at 16:49
1
  • 1
    simply: fso.DeleteFolder obj.ExpandEnvironmentStrings("C:\Users\%username%\AppData\Local\Microsoft\Office16円.0\OfficeFileCache") Commented Apr 17, 2018 at 16:53

2 Answers 2

1

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\Office16円.0\OfficeFileCache")
Sign up to request clarification or add additional context in comments.

Comments

0

If you're using some path like

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

This is better:

%LocalAppData%\...

So

Fso.DeleteFolder Obj.ExpandEnvironmentStrings("%LocalAppData%\Microsoft\Office16円.0\OfficeFileCache")

does it better, in case the user set their %UserProfile% to another directory.

answered Apr 18, 2018 at 4:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.