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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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
Answered 08/20/2009 by: Pudsey
Senior Yellow Belt

Please log in to comment
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.
Answered 08/21/2009 by: VBScab
Red Belt

Please log in to comment
0
Set objShell = WScript.CreateObject("WScript.Shell")

how many times have we seen this happen
Answered 08/21/2009 by: cygan
Fifth Degree Brown Belt

Please log in to comment
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
Answered 08/21/2009 by: McRip
Orange Senior Belt

Please log in to comment
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.
Answered 08/21/2009 by: VBScab
Red Belt

Please log in to comment
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,
Answered 08/21/2009 by: Nitro40
Yellow Belt

Please log in to comment
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.
Answered 08/21/2009 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity