Caporegime
Hi guys,
I've never been a VBScript guru but a couple of years back I got to a point where I could butcher a script to make it do what I wanted - I've since had a long break from any form of scripting.
Anyway, I am making a script for work and I've got it doing 95% of what we need, but just stuck on one bit.
The scripts function is to copy files from multiple directories to others. Variables are set in an external VBS file in case the directories change in the future.
Initially the script prompts to user to confirm they want to run the file copy, then it gets the machine name for the output logfile at the end.
After that it loads an external VBS file which has the variables it needs for source and destination directories.
After that it uses Robocopy to make the file copies.
Finishing with a simple message box confirming everything is finished.
Here is the script.
So this script works. It's been tested. The log file is great, tells you what was skipped/copied/failed etc.
However my boss wants to go one step further and this is where I get stuck. As it will be idio...sorry I mean users running this script. He wants an overall result displayed in the end message box. I've tried googling and cannot find a way to do this.
For example he wants it to show
"Actions finished
- 4 files copied
- 2 skipped
- 0 Failed
*OK*"
The idea being is that if the user gets a message that any of the copy actions have failed it shows them, so they can then proceed to contact us lot to check out the log file.
Is this possible?
Also quick note. I'm a script noob. So go easy on me!
I've never been a VBScript guru but a couple of years back I got to a point where I could butcher a script to make it do what I wanted - I've since had a long break from any form of scripting.
Anyway, I am making a script for work and I've got it doing 95% of what we need, but just stuck on one bit.
The scripts function is to copy files from multiple directories to others. Variables are set in an external VBS file in case the directories change in the future.
Initially the script prompts to user to confirm they want to run the file copy, then it gets the machine name for the output logfile at the end.
After that it loads an external VBS file which has the variables it needs for source and destination directories.
After that it uses Robocopy to make the file copies.
Finishing with a simple message box confirming everything is finished.
Here is the script.
Code:
'Message Box Prompt
a=MsgBox("This will copy the files",1, "Message Copy")
'Get Computer Name
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
'Enter path & VBSript name of external file
Dim gsLibDir : gsLibDir = "C:\Users\jacobe\Documents\Scripts\"
Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )
ExecuteGlobal goFS.OpenTextFile( gsLibDir & "EFBRS.vbs" ).ReadAll()
'Robocopy Begin process
Set objshell = CreateObject("WScript.Shell")
'FOR MANUALS
'Run Robocopy with logging
objcommand = "Robocopy.exe " & sLocalDestinationPath & " " & sFinalDestinationPath & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
objshell.run(objcommand)
'FOR OPT Files
'Run Robocopy with logging
objcommand = "Robocopy.exe " & sLocalDestinationPath2 & " " & sFinalDestinationPath2 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
objshell.run(objcommand)
'File copy from multiple sources into one destination
objcommand = "Robocopy.exe " & sLocalDestinationPath & " " & sFinalDestinationPath3 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
objshell.run(objcommand)
objcommand = "Robocopy.exe " & sLocalDestinationPath2 & " " & sFinalDestinationPath3 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
objshell.run(objcommand)
'Copy Complete Message Box
result=MsgBox("Copy Complete",0, "Copy Status")
So this script works. It's been tested. The log file is great, tells you what was skipped/copied/failed etc.
However my boss wants to go one step further and this is where I get stuck. As it will be idio...sorry I mean users running this script. He wants an overall result displayed in the end message box. I've tried googling and cannot find a way to do this.
For example he wants it to show
"Actions finished
- 4 files copied
- 2 skipped
- 0 Failed
*OK*"
The idea being is that if the user gets a message that any of the copy actions have failed it shows them, so they can then proceed to contact us lot to check out the log file.
Is this possible?
Also quick note. I'm a script noob. So go easy on me!