Stack Exchange
Using OpenTextFile for all files *.xml
I need to add text to the end of any XML file that detects me in a route, but it does not take the value = *.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Lenovo_BiosPasswordSettings", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

Set FSO   = WScript.CreateObject ("Scripting.FileSystemObject")
Set Linea = CreateObject("Microsoft.XMLDOM")
Set Linea = FSO.OpenTextFile("c:\temp\gpresult\*.xml", ForAppending, False, -1)

For Each objItem In colItems
    If (objItem.PasswordState = 2) Then
        WScript.Echo "Contraseña desactivada"
        Linea.WriteLine ""
        Linea.WriteLine "<EUT>"
        Linea.WriteLine "    </PasswordBios>"
        Linea.WriteLine "        PasswordState="Contraseña activada""
        Linea.WriteLine "    </PasswordBios>"
        Linea.WriteLine "</EUT>"
    Else
        WScript.Echo "Contraseña desactivada"
        Linea.WriteLine ""
        Linea.WriteLine "<EUT>"
        Linea.WriteLine "    </PasswordBios>"
        Linea.WriteLine "        PasswordState="Contraseña desactivada""
        Linea.WriteLine "    </PasswordBios>"
        Linea.WriteLine "</EUT>"
    End If
    Linea.Close
    Err.Clear
    EscribeLog = 0
Next


Do not edit XML files like that. I already told you that XML is a structured, hierarchical data format that you cannot simply append text to. You already have code using a proper XML parser in your previous question. Build on that.

I do not know what is that XML code that you indicate.
With the code I use can write correctly if I indicate the exact name of the xml file, I just need to know what parameters to use to read me any file on that route, you could help me about this, do not want to have to enter another code that I do not know anymore part I am very new with vbscript.

I was talking about the code in your previous question, as already stated. Also, it's clearly not possible that the code in this question would produce valid XML (because XML does not allow multiple root elements), or would even work in the first place (because the quoting in the lines where you write PasswordState= is broken).

The OpenTextFile() method does not allow wildcards. For processing multiple XML files you need to enumerate the files, check for a matching extension, then process them as XML files rather than plain text files.
Set fso = CreateObject("Scripting.FileSystemObject")
Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.Async = False
For Each f In fso.GetFolder("c:\temp\gpresult").Files
    If LCase(fso.GetExtensionName(f)) = "xml" Then
        xml.Load f.Path
        For Each objItem In colItems
            'code for appending nodes goes here
        Next
    End If
Next

Also, DO NOT modify XML by appending text at the end of the file, because XML does not allow multiple root nodes.
Valid XML:
<foo>
    <something>abc</something>
</foo>

Invalid XML:
<foo>
    <something>abc</something>
</foo>
<bar>
    <something>abc</something>
</bar>


Thanks for the information, but in my case I need to modify an xml that in each team is generated with a different name and need to add this text to the end of each:

                 
                                PasswordState = "Active password"
                 

Could you provide me with a complete code that searches for any xml in this path c: \ ProgramData \ gpresult and write at the end of the xml without deleting the previous?

SO is not a free script writing service, so no, I will not provide you with a turnkey solution for your problem. If you want that you'll need to hire someone.
