olalaland
Goto Top

Meine Frage ich brauche ein Batch der an einer Bestimmten stelle (Kann variieren) in verschiedenen .ini dateien einen Wert ändert

Hallo zusammen ich Zermater mir nun schon seid Stunden den Kopf.....
Ich bin mir nicht mal recht sicher ob das was ich vorhabe mit einer Batch funktioniert es geht dabei darum das ich auf einem Server Liegenden .ini dateien die z.B. so aussehen xxxxx-1-on.ini (die 1 wäre eine fortlaufende nummer je nachdem wieviele Benutzer sich bei dem Kunden befinden) eine bestimmte änderung an Werten bzw. an einem Wert vornehmen möchte.
Mal ein kurzer ausschnitt aus eben dieser .ini

[View]
Gamma=100
Contrast=0
Brightness=0
ViewerLocalCacheEnabled=TRUE
[Extern]
[Chat]
AutoPopup=FALSE
[ArcCache]
ArcCacheAuto=TRUE
[MDEntries]
MdEntriesAuto=TRUE
[Worklist]
Enable=TRUE
OrderToScheduledProcedureStep=FALSE
Device=0
ReferringPhysician=
RequestingPhysician=
ShowDetails=FALSE
DaysToShow=14
ShowOrderStatus=FALSE
[Scanner]
Enable=FALSE
[Hardware]
FootswitchPort=0
CardComPort=0
CardDataFormat=0

So nun geht es mir darum den Wert Enable=TRUE unter [Worklist] in Enable=FALSE zu ändern aber nur diesen und nicht jeden Enable wert.
und nein es ist nicht immer der 1. Wert unter [Worklist].

Vielleicht habt ihr dazu ja eine Idee

Content-Key: 500131

Url: https://administrator.de/contentid/500131

Printed on: April 26, 2024 at 20:04 o'clock

Mitglied: 141320
141320 Oct 01, 2019 updated at 11:21:48 (UTC)
Goto Top
Member: Olalaland
Olalaland Oct 01, 2019 at 11:26:55 (UTC)
Goto Top
Oh ja auch ne Idee allerdings müsste ich dazu erstmal in vbscript reinkommen bzw mich einlesen.
Es geht eigentlich um eine "kleine einfache batch datei" die man ggf. auch mal per Fernwartung übertragen kann auch wenn nur wenig Bandbreite verfügbar ist.
Mitglied: 141320
141320 Oct 01, 2019 updated at 11:36:18 (UTC)
Goto Top
die man ggf. auch mal per Fernwartung übertragen kann auch wenn nur wenig Bandbreite verfügbar ist.
Ist bei VBS und Powershell nicht anders.
Member: SeaStorm
SeaStorm Oct 01, 2019 at 11:47:50 (UTC)
Goto Top
hi wenn du ein zusätzliches Tool verwenden darfst, dann nimm
https://www.horstmuc.de/wbat32.htm#inifile

damit geht das ganz simpel
Member: Olalaland
Olalaland Oct 01, 2019 at 13:25:28 (UTC)
Goto Top
Ja das wäre nett ist aber leider nicht möglich
Mitglied: 141320
141320 Oct 01, 2019 updated at 14:01:03 (UTC)
Goto Top
*.VBS File anlegen, Pfad zu den Files in der ersten Zeile anpassen, doppelklick, fertig. Verarbeitet alle *on.ini des Ordners.

Btw. Die Suchfunktion liefert dir hier übrigens hunderte Treffer

PATH = "D:\daten"  
Set fso = CreateObject("Scripting.FileSystemObject")  
For Each ini In fso.GetFolder(PATH).Files
	If LCase(Right(ini.Name,6)) = "on.ini" Then   
		Set objINI = New clsIniFile
		objINI.LoadFile ini.Path,0
		objINI.Value("Worklist","Enable") = "FALSE"  
		objINI.SaveFile ini.Path,0,True	
	End If
Next
msgbox "Habe fertig! :-P", vbInformation  

Class clsIniFile
  Private objFSO
  Private dicIniFile


  Private Sub Class_Initialize()
    Set objFSO = CreateObject("Scripting.FileSystemObject")  

    Set dicIniFile         = CreateObject("Scripting.Dictionary")  
    dicIniFile.CompareMode = vbTextCompare 
  End Sub


  Private Sub Class_Terminate()
    Clear
    Set objFSO     = Nothing
    Set dicIniFile = Nothing
  End Sub
  
  
  Private Sub Clear
    dicIniFile.RemoveAll
  End Sub
  
  
  Private Function IsArrayDimed(ByRef arrArray, intDimension)
    Dim intUBound
    
    If Not IsArray(arrArray) Or intDimension < 1 Then
      IsArrayDimed = False
      Exit Function
    End If
    
    On Error Resume Next

    intUBound = UBound(arrArray, intDimension)
    IsArrayDimed = (Err.Number = 0)

    On Error Goto 0
  End Function
  
  
  Public Function LoadFile(strFilePath, intEncoding)
    Dim objInStream
    Dim objRegEx, colMatches
    Dim strLine, strSection, strKey, strValue
    Dim dicSection

    Clear
    
    strFilePath = objFSO.GetAbsolutePathName(strFilePath)

    If Not objFSO.FileExists(strFilePath) Then
      LoadFile = False
      Exit Function
    End If
    
    Set objRegEx        = New RegExp
    objRegEx.Global     = False
    objRegEx.IgnoreCase = True

    Set objInStream = objFSO.OpenTextFile(strFilePath, 1, False, intEncoding)

    Do While Not objInStream.AtEndOfStream
      strLine = objInStream.ReadLine
      
      objRegEx.Pattern = "^\[(.+)\]$"  
      Set colMatches   = objRegEx.Execute(strLine)

      If colMatches.Count > 0 Then
        strSection = colMatches(0).SubMatches(0)
        Call AddSection(strSection)
      ElseIf strSection <> "" Then  
        objRegEx.Pattern = "^([^;]+)=(.*)$"  
        Set colMatches   = objRegEx.Execute(strLine)
          
        If colMatches.Count > 0 Then
          strKey   = colMatches(0).SubMatches(0)
          strValue = colMatches(0).SubMatches(1)
          Call AddKeyValue(strSection, strKey, strValue)
        End If
      End If
    Loop

    objInStream.Close
    
    LoadFile = True
  End Function
  
  
  Public Function SaveFile(strFilePath, intEncoding, bolOverwrite)
    Dim objOutStream
    Dim strSection, strKey
    
    strFilePath = objFSO.GetAbsolutePathName(strFilePath)

    If objFSO.FileExists(strFilePath) And Not bolOverwrite Then
      SaveFile = False
      Exit Function
    End If
    
    Set objOutStream = objFSO.OpenTextFile(strFilePath, 2, True, intEncoding)
    
    For Each strSection In Sections
      Call objOutStream.WriteLine("[" & strSection & "]")  

      For Each strKey In Keys(strSection)
        Call objOutStream.WriteLine(strKey & "=" & Value(strSection, strKey))  
      Next
    Next
    
    objOutStream.Close

    SaveFile = True
  End Function

  
  Public Function SectionExists(strSection)
    SectionExists = dicIniFile.Exists(strSection)
  End Function


  Public Function AddSection(strSection)
    Dim dicSection
    
    If Not dicIniFile.Exists(strSection) Then
      Set dicSection         = CreateObject("Scripting.Dictionary")  
      dicSection.CompareMode = vbTextCompare 
      
      Call dicIniFile.Add(strSection, dicSection)
      AddSection = True
    Else
      AddSection = False
    End If
  End Function


  Public Function DeleteSection(strSection)
    If dicIniFile.Exists(strSection) Then
      Call dicIniFile.Remove(strSection)
      DeleteSection = True
    Else
      DeleteSection = False
    End If
  End Function


  Public Function ClearSection(strSection)
    Dim dicSection

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)
      dicSection.RemoveAll
      ClearSection = True
    Else
      ClearSection = False
    End If
  End Function


  Public Function KeyExists(strSection, strKey)
    Dim dicSection

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)
      KeyExists = dicSection.Exists(strKey)
    Else
      KeyExists = False
    End If
  End Function


  Public Function AddKeyValue(strSection, strKey, strValue)
    Value(strSection, strKey) = strValue
    AddKeyValue = (Value(strSection, strKey) = strValue)
  End Function


  Public Function DeleteKey(strSection, strKey)
    Dim dicSection

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)

      If dicSection.Exists(strKey) Then
        Call dicSection.Remove(strKey)
        DeleteKey = True
      Else
        DeleteKey = False
      End If
    Else
      DeleteKey = False
    End If
  End Function


  Public Function ClearKey(strSection, strKey)
    Dim dicSection

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)

      If dicSection.Exists(strKey) Then
        dicSection.Item(strKey) = ""  
        ClearKey = True
      Else
        ClearKey = False
      End If
    Else
      ClearKey = False
    End If
  End Function


  Public Property Get Sections
    Sections = dicIniFile.Keys
  End Property
  
  
  Public Property Get Keys(ByRef strSection)
    Dim dicSection
    
    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)
      Keys = dicSection.Keys
    Else
      Keys = Array()
    End If
  End Property
  
  
  Public Property Get Value(ByRef strSection, ByRef strKey)
    Dim dicSection

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)

      If dicSection.Exists(strKey) Then
        Value = dicSection.Item(strKey)
      Else
        Value = ""  
      End If
    Else
      Value = ""  
    End If
  End Property


  Public Property Let Value(ByRef strSection, ByRef strKey, ByRef strValue)
    Dim dicSection

    Call AddSection(strSection)

    Set dicSection = dicIniFile.Item(strSection)

    If Not dicSection.Exists(strKey) Then
      Call dicSection.Add(strKey, strValue)
    Else
      dicSection.Item(strKey) = strValue
    End If
  End Property


  Public Property Get KeyValues(ByRef strSection)
    Dim dicSection, strKey, intIdx, arrResult

    If dicIniFile.Exists(strSection) Then
      Set dicSection = dicIniFile.Item(strSection)

      If dicSection.Count > 0 Then
        ReDim arrResult(dicSection.Count - 1, 1)
        intIdx = 0

        For Each strKey In dicSection.Keys
          arrResult(intIdx, 0) = strKey
          arrResult(intIdx, 1) = dicSection.Item(strKey)
          intIdx = intIdx + 1
        Next
      Else
        arrResult = Array()
      End If
    Else
      arrResult = Array()
    End If
    
    KeyValues = arrResult
  End Property
  
  
  Public Property Let KeyValues(ByRef strSection, ByRef arrKeyValues)
    Dim dicSection
    Dim intArrLength, intCnt

    If Not IsArrayDimed(arrKeyValues, 1) Then Exit Property
    If UBound(arrKeyValues, 1) < 0 Then Exit Property
    
    If Not IsArrayDimed(arrKeyValues, 2) Then
      If Not IsArrayDimed(arrKeyValues(0), 1) Then Exit Property
      If UBound(arrKeyValues(0), 1) < 1 Then Exit Property
    Else
      If UBound(arrKeyValues, 2) < 1 Then Exit Property
    End If

    Call AddSection(strSection)

    Set dicSection = dicIniFile.Item(strSection)

    If Not IsArrayDimed(arrKeyValues, 2) Then
      'Manuell erzeugtes 2-dimensionales Array  
      For intCnt = 0 To UBound(arrKeyValues)
        Value(strSection, arrKeyValues(intCnt)(0)) = arrKeyValues(intCnt)(1)
      Next
    Else
      'Natives 2-dimensionales VBScript Array  
      For intCnt = 0 To UBound(arrKeyValues)
        Value(strSection, arrKeyValues(intCnt, 0)) = arrKeyValues(intCnt, 1)
      Next
    End If
  End Property
End Class
Member: SeaStorm
Solution SeaStorm Oct 01, 2019 at 13:59:21 (UTC)
Goto Top
Dann halt in kompliziert ;)

@ECHO OFF
SETLOCAL
SET "Worklistsection="  
(
 FOR /f "tokens=1*delims=" %%a IN (in.ini) DO (  
  FOR /f "tokens=1*delims== " %%b IN ("%%a") DO (  
   SET repro=Y
   IF "%%c"=="" (  
    SET "Worklistsection="  
    IF /i "%%b"=="[Worklist]" SET Worklistsection=y  

   ) ELSE (
    IF DEFINED Worklistsection IF "%%b"=="Enable" (SET "repro="&ECHO(Enable=TRUE)  

   )
   IF DEFINED repro ECHO(%%a
  )
 )
)>out.ini



GOTO :EOF

Nimmt die IN.ini und erstellt daraus die OUT.ini

Das Handling der Dateien bekommst du sicher alleine hin face-smile
Member: Olalaland
Olalaland Oct 01, 2019 at 14:05:42 (UTC)
Goto Top
Wow Das sieht ja echt nett ausface-smile
Ich bin mir ja grade am durchlesen wie genau vbs von der syntax her aufgebaut ist.
Wäre es viel aufwand das ganze abzuändern das er FALSE zu TRUE ändert?
Mitglied: 141320
Solution 141320 Oct 01, 2019 updated at 14:08:32 (UTC)
Goto Top
Zitat von @Olalaland:

Wow Das sieht ja echt nett ausface-smile
Ich bin mir ja grade am durchlesen wie genau vbs von der syntax her aufgebaut ist.
Wäre es viel aufwand das ganze abzuändern das er FALSE zu TRUE ändert?
Öhm, lesen wäre vorteilhaft die Zeile ist ja selbsterklärend ...
objINI.Value("Worklist","Enable") = "FALSE"  
DAS FALSE auf TRUE ändern.
Member: Olalaland
Olalaland Oct 01, 2019 at 14:35:50 (UTC)
Goto Top
Danke mir hämmert im moment ein wenig der Kopf
Member: Olalaland
Olalaland Oct 01, 2019 at 14:37:53 (UTC)
Goto Top
Und @ SeaStorm
gefällt mir fast noch besser da es batch ist leider immer nur für 1 feste .ini, aber vielleicht kann ich da noch ein wenig mit rumprobieren das er wirklich alle xxxxx-1-on.ini in dem Ordner ändert
Member: SeaStorm
SeaStorm Oct 01, 2019 at 14:50:04 (UTC)
Goto Top
da musst du nur eine schleife drum rum basteln und mit Variablen arbeiten. Aber das solltest du schon selbst hin bekommen. ist ja immerhin ne Dienstleistung die ihr euren Kunden anbietet. Da sollten solche Basics dann doch drin sein...
Member: Olalaland
Olalaland Oct 02, 2019 at 06:21:25 (UTC)
Goto Top
Das mag sein ich befinde mich momentan allerdings in einem Praktikum. Zwecks einer Umschulung. Daher bin ich persöhnlich leider noch nicht so weit. Ich versuche dennoch mich in die Thematik einzulesen. face-big-smile ist ja schließlich noch kein Meister vom Himmel gefallen.