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
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
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
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 500131
Url: https://administrator.de/forum/meine-frage-ich-brauche-ein-batch-der-an-einer-bestimmten-stelle-kann-variieren-in-verschiedenen-ini-dateien-500131.html
Ausgedruckt am: 17.05.2025 um 14:05 Uhr
13 Kommentare
Neuester Kommentar

die man ggf. auch mal per Fernwartung übertragen kann auch wenn nur wenig Bandbreite verfügbar ist.
Ist bei VBS und Powershell nicht anders.
hi wenn du ein zusätzliches Tool verwenden darfst, dann nimm
https://www.horstmuc.de/wbat32.htm#inifile
damit geht das ganz simpel
https://www.horstmuc.de/wbat32.htm#inifile
damit geht das ganz simpel

*.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
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
Dann halt in kompliziert ;)
Nimmt die IN.ini und erstellt daraus die OUT.ini
Das Handling der Dateien bekommst du sicher alleine hin
@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

Zitat von @Olalaland:
Wow Das sieht ja echt nett aus
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 ...Wow Das sieht ja echt nett aus
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?
objINI.Value("Worklist","Enable") = "FALSE"