VBS-Datei wird blitzschnell geschlossen

dinoldo

Cadet 4th Year
Registriert
Juni 2017
Beiträge
104
Hallo Leute,

ich habe eine VBS-Datei, die beim Start direkt blitzschnell geschlossen wird. Habt ihr eine Idee, woran es bitte liegen könnte?

Code:
Option Explicit

Dim currentLine
Dim fso, txtFile, newFileContent
Dim shell
Dim element, Msg
Dim location(5)

const file = "\Standards\data\"
const vbsInterpreter = "cscript.exe"
const CheckFile = "\Standards\config\system\config.cfg"

Set shell = CreateObject("WScript.Shell")

Call ForceConsole

Set fso = CreateObject("Scripting.FileSystemObject")
Set txtFile = fso.OpenTextFile("P:\Standort\Hamburg" & file & "nova.cfg", 1)

currentLine = txtFile.ReadLine()
newFileContent = CStr(Val(currentLine) + 1)

txtFile.Close()

Set txtFile = fso.OpenTextFile("P:\Standort\Hamburg" & file & "nova.cfg", 2)
txtFile.Write newFileContent
txtFile.Close()

location(0) = "P:\Standort\Hamburg"
location(1) = "P:\Standort\Berlin"
location(2) = "P:\Standort\Köln"
location(3) = "P:\Standort\Düsseldorf"
location(4) = "P:\Standort\Kiel"
location(5) = "P:\Standort\Mänchen"

WScript.StdOut.WriteLine "Erreichbarkeit vom Server wird geprüft! Bitte warten..."
WScript.Sleep 50000
For Each element In location
    If Len(element) > 0 Then
        If Not fso.FileExists(element & CheckFile) Then Msg = Msg & vbLf & element
    End If
Next

WScript.StdOut.WriteLine ""

If Msg <> vbNullString Then
    If MsgBox("Folgende Standorte sind nicht ereichbar:" & vbLf & Msg & vbLf & vbLf & "Weitermachen?", vbQuestion Or vbYesNo, "Fehler") = vbNo Then WScript.Quit
End If

For Each element In location
    If Len(element) > 0 Then
    If fso.FileExists(element & CheckFile) Then   
        WScript.StdOut.WriteLine "Bearbeitet wird: " & element & file
        fso.CopyFile "P:\Standort\Hamburg" & file & "nova.cfg", element & file, True
    End If
    End If
Next

Sub ForceConsole()
    If InStr(LCase(WScript.FullName), vbsInterpreter) = 0 Then
        shell.Run vbsInterpreter & " //NoLogo " & Chr(34) & WScript.ScriptFullName & Chr(34)
        WScript.Quit
    End If
End Sub

Besten Dank im Voraus!

Gruß Dino
 
Besten Dank!

Es lag an newFileContent = CStr(Val(currentLine) + 1)
So funktioniert es: newFileContent = CStr(CLng(currentLine) + 1)
 
Wie kann man bitte oben im Code die Hintergrundfarbe vom Fenster ändern?

1684568117739.png
 
Na, immer noch auf der Suche nach Idioten, die deinen bezahlten Job machen sollen?

Ich würde es mit einer Mischung von Batch und VBS umsetzen. CSCRIPT übernimmt die Farben von der aktuellen Batch/CMD. Anscheinend (auf die Schnelle gegoogelt) gibt es wohl keinen VBS-Befehl zum Ändern der Hintergrundfarbe.
 
Code:
dim txt
txt = chr(27) & "[91mRed" & chr(27) & "[0m normal"
wscript.echo txt

Code:
wscript.echo      "[92mGreen[0m  "
 
Zurück
Oben