none
Need help on VB script RRS feed

  • General discussion

  • I am calling sub script from main VB script, script is working but I need help on each stage of failure return code event log should be created by command prompt, I mean in case of failure of each script script will run below command to create event then move for calling next script

    error should be written when subscript failed with return code >1 other than 0

    EVENTCREATE /T ERROR /L APPLICATION /ID 900 /D "Unable to find remote directory location on Schneider server"

    here is script

    please help

    option explicit
    DIM STRDEBUG : STRDEBUG = TRUE

    Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
    ' Dim strChemin : strChemin = oFS.GetParentFolderName(WScript.ScriptFullName)
    Dim strChemin : strChemin = oFS.GetParentFolderName(WScript.ScriptFullName)
    dim strLogFile : strLogFile = "Export_all.log"
    Dim objShell : Set objShell = CreateObject("Wscript.shell")
    Dim objLogFile : Set objLogFile = oFS.CreateTextFile(left(strChemin,1) & ":\DATA\ADMINIT\DRP\" & strLogFile, True)
    Dim colDrives : Set colDrives = oFS.Drives
    Dim objPath
    Dim colSubfolders, colDrivefolders
    dim objFolder, DriveFolder
    Dim objSubfolder, objDrivefolder
    Dim objDrive
    Dim command
    Dim objNet
    Set objNet = WScript.CreateObject("WScript.Network")

    objLogFile.writeline "**************************"
    objLogFile.writeline "Export configuration Start"
    objLogFile.writeline "**************************" & VbCrLf
     

    command =  strChemin &"\Export_Quotas.bat " & left(strChemin,1)
    ExecCmd command
    objLogFile.writeline "**************************" & VbCrLf

    objLogFile.writeline "------ Exporting FTP begin" & VbCrLf
    command =  "powershell -file """ & strChemin & "\Export_FTP.ps1"""
    objShell.run(command)
    objLogFile.writeline "------ Exporting FTP End" & VbCrLf
    objLogFile.writeline "**************************" & VbCrLf

    objLogFile.writeline "------ Exporting Printers begin" & VbCrLf
    command =  "powershell -file """ & strChemin & "\Export_Printers.ps1"""
    objShell.run(command)
    objLogFile.writeline "------ Exporting Printers End" & VbCrLf
    objLogFile.writeline "**************************" & VbCrLf

    objLogFile.writeline "------ Exporting Shared Foders begin" & VbCrLf
    command =  "powershell -file """ & strChemin & "\Export_Shares.ps1"""
    objShell.run(command)
    objLogFile.writeline "------ Exporting Shared Foders End" & VbCrLf
    objLogFile.writeline "**************************" & VbCrLf


    For Each objDrive in colDrives
        if ucase(objDrive.DriveLetter)<>"C" and ucase(objDrive.DriveLetter)<>"D" and ucase(objDrive.DriveLetter)<>"A" then
            objPath = objDrive.DriveLetter
            on error resume next
            
            Set DriveFolder = oFS.GetFolder(objPath & ":\")
            if err.number=0 then
                Set colDrivefolders = DriveFolder.Subfolders
                
                For Each objDrivefolder in colDrivefolders
                    If Instr(Ucase(objDrivefolder.Name),"DATA")<>0 Then
                        Set objFolder = oFS.GetFolder(objPath &":\" & objDrivefolder.name & "\")
                        if err.number=0 then
                            on error goto 0
                            Set colSubfolders = objFolder.Subfolders
                            For Each objSubfolder in colSubfolders
                                if ucase(objSubfolder.Name)<>"DFSRPRIVATE" then
                                    command =  strChemin & "\Export_ACL.bat " & left(strChemin,1) & " " & objPath & " " & objDrivefolder.name & " " & objSubfolder.Name
                                    ExecCmd command
                                    command =   "FILEACL " & objPath & ":\" & objDrivefolder.name & "\" & objSubfolder.Name & " /NOINHERITED /SUB /BATCH /FORCE /OUTPUT:" & left(strChemin,1) & ":\DATA\ADMINIT\DRP\" & objNet.ComputerName & "_backup\ACL\" & objDrivefolder.name & "\" & objNet.ComputerName & "_" & objPath & "_" & objDrivefolder.name & "_" & objSubfolder.Name & "_ACL.txt"                            
                                    ExecCmd command    
                                end if
                            Next
                        else
                            on error goto 0
                        End if
                    End If
                Next
                
            else
                on error goto 0
            End If
            
            
        end if
    Next

    command = strChemin &"\Export_DHCP.bat " & left(strChemin,1)
    ExecCmd command
    objLogFile.writeline "**************************" & VbCrLf

    objLogFile.writeline VbCrLf
    objLogFile.writeline "**************************"
    objLogFile.writeline "Export configuration End"
    objLogFile.writeline "**************************"

    Function ExecCmd(strCom)
        if STRDEBUG then
            objLogFile.writeline strCom
        end if
        
        dim objShell : set objShell = CreateObject("Wscript.Shell")
        dim objProc : set objProc  = objShell.Exec(strCom)

        Do
           WScript.Sleep 300
        Loop Until objProc.Status <> 0

        if STRDEBUG then
            if objProc.ExitCode <> 0 then
               objLogFile.writeline "EXIT CODE: " & objProc.ExitCode
               objLogFile.writeline "ERROR: " & objProc.StdErr.ReadAll
            end if
            objLogFile.writeline "OUTPUT: " & objProc.StdOut.ReadAll
    end if
    End Function


    regards DJ

    • Changed type Bill_Stewart Monday, July 30, 2018 1:41 PM
    • Moved by Bill_Stewart Monday, July 30, 2018 1:41 PM This is not "scripts on demand"
    Friday, June 8, 2018 11:23 AM

All replies