Batch File Success and Error logging

后端 未结 2 847
伪装坚强ぢ
伪装坚强ぢ 2021-01-16 09:33

Is there a way, within a batch file, to log the error and success of the batch file?

I am trying to copy a file from my computer to 200 machines (works great) but wa

2条回答
  •  执念已碎
    2021-01-16 10:09

    This is simple logging - just checks if the drive was mapped and if the filename appears on the mapped drive, and writes the log to your desktop.

    @echo off
    if [%1]==[] goto usage
    echo mapping l: to %1\c$
    net use * /delete /y
    net use l: \\%1\c$ password /user:%1\administrator
    if not exist L:\ (echo %1 failed mapping drive letter>>"%userprofile%\desktop\net use log.txt"& goto :EOF)
    
    echo copying link file to C: Drive
    copy "c:\_\CopyFileToHost\logoff.cmd" l:\
    if not exist "L:\logoff.cmd" (echo %1 failed copying "c:\_\CopyFileToHost\logoff.cmd">>"%userprofile%\desktop\net use log.txt")
    
    echo deleting l: mapping
    net use l: /delete /y
    
    goto :eof
    
    :usage
    echo Usage: %0 hostname
    exit /B 1
    

提交回复
热议问题