'Constants used for event logging
Option explicit
SetLocale("en-us")
Const CommonAppData = &H23&
Const QUOTE = """"
' Declare Global Variables
Dim oAPI, oBag, bPropertyBagCreated
Dim g_szNiCEBaseDir
Dim g_objFSO, g_WshShell, g_objShell
'Start by setting up API object and creating a discovery data object.
Set oAPI = CreateObject("MOM.ScriptAPI")
Set g_objFSO = CreateObject("Scripting.FileSystemObject")
Set g_WshShell = WScript.CreateObject("WScript.Shell")
Set g_objShell = CreateObject("Shell.Application")
'******************************************************************
' MAIN
'******************************************************************
'First check ProgramData
g_szNiCEBaseDir = RemoveSlash(g_WshShell.ExpandEnvironmentStrings("%ProgramData%")) & "\NiCE\conf\nice_base.env"
If g_objFSO.FileExists(g_szNiCEBaseDir) Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Path", RemoveSlash(g_WshShell.ExpandEnvironmentStrings("%ProgramData%")) & "\NiCE")
oAPI.AddItem(oBag)
bPropertyBagCreated = true
Else
'Next Check ALLUSERSPROFILE + \Application Data
g_szNiCEBaseDir = RemoveSlash(g_WshShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")) & "\Application Data\NiCE\conf\nice_base.env"
If g_objFSO.FileExists(g_szNiCEBaseDir) Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Path", RemoveSlash(g_WshShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")) & "\Application Data\NiCE")
oAPI.AddItem(oBag)
bPropertyBagCreated = true
Else
'Last try. Check CommonAppData'
Dim objFolder, objFolderItem
Set objFolder = g_objShell.Namespace(CommonAppData)
Set objFolderItem = objFolder.Self
g_szNiCEBaseDir = RemoveSlash(objFolderItem.Path) & "\NiCE\conf\nice_base.env"
If g_objFSO.FileExists(g_szNiCEBaseDir) Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Path", RemoveSlash(objFolderItem.Path) & "\NiCE")
oAPI.AddItem(oBag)
bPropertyBagCreated = true
End If
End If
End If
If bPropertyBagCreated = False Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Path", "")
oAPI.AddItem(oBag)
End If
oAPI.ReturnItems()
'******************************************************************
' Subs and Functions
'******************************************************************
'==================================================================================
' Function: RemoveSlash
' Purpose: removes the last char of a string if it a forward or backward slash
'==================================================================================
Function RemoveSlash(Path)
Dim szLastChar
szLastChar = Right(Path,1)
If szLastChar = "\" OR szLastChar = "/" Then
removeSlash = Left(Path,Len(Path)-1)
Else
removeSlash = Path
End If
End Function</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
<WriteAction ID="RemoveFolder" TypeID="System!System.CommandExecuter">
<ApplicationName/>
<WorkingDirectory/>
<CommandLine>RD /S /Q "$Data[Default='']/Property[@Name='Path']$"</CommandLine>
<TimeoutSeconds>300</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
</WriteAction>
<WriteAction ID="WriteCompleted" TypeID="NiCE.Library.W.Write.Event2.WA">
<EventInformations>13312;Information;The removal of the data folder for Computer '$Config/TargetSystem$' was completed. The Output is $Data[Default='']///*[local-name()="StdOut"]$$Data[Default='']///*[local-name()="StdErr"]$</EventInformations>
<EventError>$Data[Default='']///*[local-name()="StdErr"]$</EventError>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WriteCompleted">
<Node ID="RemoveFolder">
<Node ID="GetFolder"/>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>