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.
My current script is...
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)
Please log in to answer
Posted by:
Pudsey
15 years ago
You could try something like this
I hope this helps.
Puds
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
15 years ago
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.
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
15 years ago
Posted by:
McRip
15 years ago
Or you may doi it with this script. VBScab doesn't like but I do and it works...
Cheers
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
15 years ago
Posted by:
Nitro40
15 years ago
Posted by:
anonymous_9363
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.