/build/static/layout/Breadcrumb_cap_w.png

How to add (funtionality of) Environmental Variable %AppData% into VB Script for UNinstalling

SCCM deployment
Installshield MSI/MST
VB Script

Hello All,

Using SCCM for per-machine install. I am using an MSI with transform as my install files that SCCM points to.

I have a package that installs folder structure and files to the User's Roaming folder (AppDataFolder). This is being done by an Active Setup that creates folders/files in the user's Roaming profile upon logging into Windows (post install & reboot).

The install works fine, it is the Uninstall that raises the issue. I have a standard folder/file removal script that works fine with hard coded paths. But hard coded paths are not an option for removing anything from a Roaming profile. How can I add "Appdatafolder" or "%appdata%" equivalent to a VB script so that it applies to anyone performing the uninstall from SCCM?

Here is the standard folder/file script I am using. It is good for deleting hard coded paths as shown:

'--------Delete files-------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
strComputer = "."
If objFSO.FolderExists("C:\ProgramData\VendorFolderName\SoftwareFolderName") Then
                objFSO.DeleteFile("C:\ProgramData\VendorFolderName\SoftwareFolderName\*.*"), True
                objFSO.DeleteFolder("C:\ProgramData\VendorFolderName\SoftwareFolderName"), True
End If
Set objFSO = Nothing


Can I use an Environmental Variable such as %appdata% or equivalent to use in a VB script for Roaming folder?


0 Comments   [ + ] Show comments

Answers (2)

Posted by: olditguy 6 years ago
Second Degree Blue Belt
0

Hi rcooder

try this

' Code to get value of env var

Dim myVar

Dim WshShell

Set WshShell = Wscript.CreateObject("WScript.Shell")

myVar = WshShell.ExpandEnvironmentStrings("%APPDATA%")

' Value of env var in myVar  N.B. No trailing slash so you need to prepend it if required

' Now do something like this depending on the folder structure

 objFSO.DeleteFile(myVar & "\VendorFolderName\SoftwareFolderName\*.*"), True


Comments:
  • Thank you for responding. I found what fixed my issue. I used the following:
    '--------Delete folders-------------
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objWShell
    Set objWShell = WScript.CreateObject("WScript.Shell")
    Dim appData
    appData = objWShell.expandEnvironmentStrings("%APPDATA%")
    On Error Resume Next
    strComputer = "."
    If objFSO.FIleExists(appData + "\Microsoft\Word\STARTUP\WordAddIn.dotm") Then
    objFSO.DeleteFile(appData + "\Microsoft\Word\STARTUP\WordAddIn.dotm")
    End If
    Set objFSO = Nothing - rcooder 6 years ago
Posted by: rcooder 6 years ago
Senior Yellow Belt
0

Thanks again olditguy! I didn't get around to trying it but here is the fix that worked for me:


'--------Delete folders-------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objWShell
Set objWShell = WScript.CreateObject("WScript.Shell")
Dim appData
appData = objWShell.expandEnvironmentStrings("%APPDATA%")
On Error Resume Next
strComputer = "."
If objFSO.FIleExists(appData + "\Microsoft\Word\STARTUP\WordAddIn.dotm") Then
 objFSO.DeleteFile(appData + "\Microsoft\Word\STARTUP\WordAddIn.dotm")
End If
Set objFSO = Nothing

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ