/build/static/layout/Breadcrumb_cap_w.png

Finding Common Files Folder

I am a true noob to VBScript, but need to use some in an installation package. I have a VBScript that will remove the folder C:\Program Files\Common Files\CompanyName\XYZ and its contents. However, right now I have it hard coded to that path. I would like a way to use a system variable to give me the path to the Common Files folder. That would prevent me from running into trouble if they have Windows installed on something other than a C: drive. I have searched the web and cannot find what I am looking for, but it seems like it should be simple enough.

My current script is...
Dim FSO, Folder
set FSO=CreateObject("Scripting.FileSystemObject")
Folder="C:\Program Files\Common Files\CompanyName\XYZ"
IF FSO.FolderExists(Folder) Then
FSO.DeleteFolder(Folder)
End If

Any help would be greatly appreciated.

Thanks,
Nitro.

0 Comments   [ + ] Show comments

Answers (7)

Posted by: Pudsey 14 years ago
Senior Yellow Belt
0
You could try something like this


Dim FSO, Folder, ComFiles

Set FSO=CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
Set objEnvVar = objShell.Environment("PROCESS")

ComFiles = objEnvVar("CommonProgramFiles")
Folder= ComFiles & "\CompanyName\XYZ"

IF FSO.FolderExists(Folder) Then
FSO.DeleteFolder(Folder)
End If


I hope this helps.

Puds
Posted by: anonymous_9363 14 years ago
Red Belt
0
Forget script.Do it properly and use the RemoveFile table.

Set the target to [%CommonProgramFiles]CompanyName\XYZ. The brackets indicate to the engine that you want to resolve the folder using a proeprty and the leading percentage sign indicates that that property is itself resolved from an environment variable.
Posted by: cygan 14 years ago
Fifth Degree Brown Belt
0
Set objShell = WScript.CreateObject("WScript.Shell")

how many times have we seen this happen
Posted by: McRip 14 years ago
Orange Senior Belt
0
Or you may doi it with this script. VBScab doesn't like but I do and it works...


Option Explicit
On Error Resume Next
Const COMMON_FILES = &H2b&
Dim Objshell
Dim oFSO
Dim FoldertoKill
Dim objFolder
Dim objFolderItem

Set oFSO = Createobject("scripting.filesystemobject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(COMMON_FILES)
Set objFolderItem = objFolder.Self

FoldertoKill = objFolderItem.Path & "\Your Folder here"
ofso.DeleteFolder FoldertoKill, True
on error goto 0


Cheers
Posted by: anonymous_9363 14 years ago
Red Belt
0
It's not that I don't like script (although the absence of ANY error-trapping makes me shudder, as usual). Indeed, I have reams and reams of script which I use on a regular basis. However, I take the "why complicate things?" view. One row in the RemoveFile table takes care it.
Posted by: Nitro40 14 years ago
Yellow Belt
0
Great, this is what I was looking for. I think I have to use a script as I need to add the folder back in with a different set of files (naming and versions).

Thanks,
Posted by: anonymous_9363 14 years ago
Red Belt
0
...so use the 'Directory' table in a similar way.You then use the directory name from that table for the component containing your new files.

What authoring tool are you using? Wise? InstallShield? Both make this pretty easy in their respective GUIs.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
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