The following .vbs creates the desired task without any issue (please excuse the syntax):
Option Explicit
Dim wshell
Set wshell = CreateObject("WScript.Shell")
wshell.Run "schtasks /create /sc once /tn ""Reminder"" /tr ""C:\Windows\System32\cmd.exe \""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo *** Message goes here *** & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul\"""" /st 18:00 /sd 08/20/2016 /f"
However if I try pass the schtasks command string via a variable as follows:
Option explicit
dim strdate, strtime, strmessage, strtask, wshell
strdate = "08/20/2016"
strtime = "18:30"
strmessage = "Turn off pump"
WScript.Echo strdate
WScript.Echo strtime
WScript.Echo strmessage
strtask = """schtasks /create /sc once /tn """"Reminder"""" /tr """"C:\Windows\System32\cmd.exe \""""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo " & strmessage & " & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul"""""""" /st " & strtime & " /sd " & strdate & " /f""" & " ,0" & " ,true"
WScript.Echo strtask
Set wshell = CreateObject("WScript.Shell")
wshell.Run strtask
I get the following error:
I can't understand why I'm getting this, the variable being parsed is, after all, identical to the previous snippet (including the quotes)... Could someone please explain to me what I'm missing?
EDIT
Thanks to Ansgar Wiechers' guidance. I've managed to get a working, albeit inelegant, script by removing the run command options, and intrinsically checking for an external command error instead. See hereunder:
option explicit
dim strdate, strtime, strmessage, strtask, exitcode, wshell
strdate = "08/21/2016"
strtime = "13:45"
strmessage = "Turn off pump"
WScript.Echo strdate
WScript.Echo strtime
WScript.Echo strmessage
strtask = "schtasks /create /sc once /tn ""Reminder"" /tr ""C:\Windows\System32\cmd.exe \""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo " & strmessage & " & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul\"""" /st " & strtime & " /sd " & strdate & " /f"
set wshell = CreateObject("WScript.Shell")
exitcode = wshell.Run(strtask, 0, True)
if exitcode <> 0
then WScript.Echo "External command failed: " & Hex(exitcode)
End If
I seriously doubt that your original command ever worked. The nested quotes around the argument list to CMD.exe should always have made it raise an error. Remove those nested quotes (leave just the double quotes around the entire CMD statement) and also remove the arguments to the Run method from strTask, and task creation should work as you expect.
strtask = "schtasks /create /sc once /tn ""Reminder""" & _
" /tr ""C:\Windows\System32\cmd.exe /c title Alert" & _
" & mode con: cols=40 lines=10 & color f0 & cls" & _
" & echo " & strmessage & _
" & echo. & echo. & echo. & echo. & echo. & echo. & echo." & _
" & echo Press any key to exit & pause > nul""" & _
" /sd " & strdate & " /st " & strtime & " /f"
exitcode = wshell.Run(strtask, 0, True)
If exitcode <> 0 Then
WScript.Echo "External command failed: " & Hex(exitcode)
End If
It's always a good idea to add some code to check the exit status of external commands, so you can detect if something went wrong.
With that said, you could greatly improve maintainability of this code with some modifications:
Don't create the commandline as one big string. Build it from the inside out.
Use environment variables if possible (e.g. %COMSPEC% instead of the literal path to CMD.exe)
Use quotes only where they're required.
Use a quoting function for adding escaped double quotes.
Function qq(str)
qq = """" & str & """"
End Function
cmdargs = "/c title Alert & mode con: cols=40 lines=10 & color f0 & cls" & _
" & echo " & strmessage & " & echo. & echo. & echo. & echo." & _
" & echo. & echo. & echo. & echo Press any key to exit & pause > nul"
strtask = "schtasks /create /f /sc once /tn Reminder" & _
" /tr " & qq("%COMSPEC% " & cmdargs) & _
" /sd " & strdate & " /st " & strtime
exitcode = wshell.Run(strtask, 0, True)
Better yet, put the batch code into an actual batch file:
#echo off
title Alert
mode con: cols=40 lines=10
color f0
cls
echo %~1
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Press any key to exit
pause > nul
and create the task to run that batch file with your message:
Function qq(str)
qq = """" & Replace(str, """", "\""") & """"
End Function
batchfile = "C:\path\to\your.bat"
strtask = "schtasks /create /f /sc once /tn Reminder" & _
" /tr " & qq(qq(batchfile) & " " & qq(strmessage)) & _
" /sd " & strdate & " /st " & strtime
exitcode = wshell.Run(strtask, 0, True)
Related
I use the following code VBS to read a text file. How can I save the contents of this text file to my computer clipboard to paste elsewhere?
Option Explicit
Dim objFileToRead, strFileText, content
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\1.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
Here is an easy way to do it using clip command line :
Option Explicit
Dim Title : Title = "Copy the contents of a text file to the clipboard"
Dim File2Read : File2Read = "C:\1.txt"
If CreateObject("Scripting.FileSystemObject").FileExists(File2Read) Then
CreateObject("WScript.Shell").Run "cmd.exe /c clip < "& File2Read &"",0,TRUE
MsgBox "The contents of file : " & chr(34) & File2Read & chr(34) & vbCrlf & _
" is copied to the clipboard !",vbInformation,Title
Else
MsgBox "Check if the " & chr(34) & File2Read & chr(34) &" exists !",vbExclamation,Title
End If
EDIT : Save a ping test into file and copy it to clipboard !
Option Explicit
Dim Title : Title = "Copy the contents of a text file to the clipboard"
Dim File2Read : File2Read = "E:\Yahoo_Ping.txt"
CreateObject("WScript.Shell").Run "CMD /C Ping www.yahoo.com > "& File2Read &"",1,True
If CreateObject("Scripting.FileSystemObject").FileExists(File2Read) Then
CreateObject("WScript.Shell").Run "CMD /U /C clip < "& File2Read &"",0,TRUE
MsgBox "The contents of file : " & chr(34) & File2Read & chr(34) & vbCrlf & _
" is copied to the clipboard !",vbInformation,Title
Else
MsgBox "Check if the " & chr(34) & File2Read & chr(34) &" exists !",vbExclamation,Title
End If
With Batch and Powershell :
#echo off
Title Set-Clipboard and Get-ClipBoard with Powershell and Batch
Set "InputFile=%Temp%\%~n0.txt"
echo Please be patient ....
Ping www.stackoverflow.com > "%InputFile%"
Set "OutPutFile=%userprofile%\Desktop\MyClipBoard.txt"
Call :RunPS-Get-ClipBoard "%InputFile%" "%OutPutFile%"
Cls & Type "%OutPutFile%"
Pause & Exit
REM ----------------------------------------------------------------------
:RunPS-Get-ClipBoard <InputFile> <OutPutFile>
Set psCmd="&{Set-Clipboard -Value (GC '"%~1"') | Get-ClipBoard}"
If Exist "%~2" Del "%~2"
#for /F "tokens=*delims=" %%i in ('Powershell %psCmd%') do >> "%~2" echo %%i
Goto:eof
REM ----------------------------------------------------------------------
I wrote a vbscript to determine what are the vbscripts running in background but when I execute my script . it only opens the folder of my script not the other scripts location or folder . What should I do?? Please help
Myscript.vbs
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
strPath = "explorer.exe /e," & strFolder
objShell.Run strPath
Please help guys . I am very new to vbscript .
I have for you an old vbscript since 2015 that can tell you what vbscript is running in the background with its command line of course to get their paths and you have a possiblity to choose what vbscript you want to kill and you get in the end of the script a log file for this.
So you can give a try for this first, and i will edit and update it for any modifications in order to answer your question.
Option Explicit
Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count
If AppPrevInstance() Then
MsgBox "There is an existing proceeding !" & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,_
"There is an existing proceeding !"
WScript.Quit
Else
Copyright = "[Hackoo "& chr(169) & " 2015]"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject( "Wscript.Shell" )
NomFichierLog="Killed_Process.txt"
temp = ws.ExpandEnvironmentStrings("%temp%")
PathNomFichierLog = temp & "\" & NomFichierLog
Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1)
Call Find("wscript.exe")
Call Explorer(PathNomFichierLog)
End If
'***************************************************************************************************
Function Explorer(File)
Dim ws
Set ws = CreateObject("wscript.shell")
ws.run "Explorer "& File & "\",1,True
end Function
'***************************************************************************************************
Sub Find(MyProcess)
Dim colItems,objItem,Processus,Question,Msg
Titre = " Process(es) "& DblQuote(MyProcess) &" running "
Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
& "Where Name like '%"& MyProcess &"%' AND NOT commandline like " & CommandLineLike(WScript.ScriptFullName) & "",,48)
Count = 0
For Each objItem in colItems
Count= Count + 1
Processus = objItem.CommandLine
Question = MsgBox ("Would do you like to kill this script : " & DblQuote(Processus) & " ?" ,VBYesNO+VbQuestion,Titre+Copyright)
If Question = VbYes then
objItem.Terminate(0)'To kill the process
OutPut.WriteLine Processus
else
Count= Count - 1 'decrementing the count of -1
End if
Next
OutPut.WriteLine String(100,"*")
If Count > 1 Then
Msg = " were killed"
Else
Msg = " was killed"
End if
OutPut.WriteLine count & Titre & Msg
OutPut.WriteLine String(100,"*") & VbCrLF
End Sub
'**************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
EDIT : Extract_CommandLine.bat
Copy and paste this code as batch file in order to extract the command line of each process.
Set ProcessNames="cmd.exe" "mshta.exe" "powershell.exe" "cscript.exe" "wscript.exe"
You can add or remove the process name from the variable ProcessNames between the double quotes.
#echo off
Title Extract CommandLine Of Running Processes by Hackoo 2020
Mode 110,10 & color 0A
Set "TmpFile=%~n0_Abs_cmdline.txt"
Set "LogFile=%~n0_cmdline.txt
If Exist "%TmpFile%" Del "%TmpFile%"
If Exist "%LogFile%" Del "%LogFile%"
Set ProcessNames="cmd.exe" "mshta.exe" "powershell.exe" "cscript.exe" "wscript.exe"
SetLocal EnableDelayedExpansion
for %%A in (%ProcessNames%) Do (
Call :GetCommandLine %%A ProcessCmd
If defined ProcessCmd (
echo !ProcessCmd!>con
echo !ProcessCmd!>>"%TmpFile%"
)
)
Timeout /T 3 /NoBreak>nul
If Exist "%TmpFile%" Call :Extract "%TmpFile%" "%LogFile%"
If Exist "%LogFile%" Start "" "%LogFile%"
If Exist "%LogFile%" Call :ExplorerIT "%LogFile%"
Exit
::---------------------------------------------------------------------------------------------------------------
:GetCommandLine <ProcessName> <ProcessCmd>
Set "ProcessCmd="
for /f "tokens=2 delims==" %%P in (
'wmic process where caption^="%~1" get commandline /format:list ^| findstr /I "%~1" ^| find /I /V "%~nx0" 2^>nul'
) do (
if not defined %2 Set "%2=%%P"
)
Exit /b
::---------------------------------------------------------------------------------------------------------------
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"(^?^!.*(\x22\w^)^)\b.*(\w^).*(\.ps1^|\.hta^|\.vbs^|\.vbe^|\.cmd^|\.bat^|\.lnk^)"^)
echo WScript.StdOut.WriteLine Data
echo Function Extract(Data,Pattern^)
echo Dim oRE,oMatches,Match,Line
echo set oRE = New RegExp
echo oRE.IgnoreCase = True
echo oRE.Global = True
echo oRE.Pattern = Pattern
echo set oMatches = oRE.Execute(Data^)
echo If not isEmpty(oMatches^) then
echo For Each Match in oMatches
echo Line = Line ^& chr(34^) ^& Trim(Match.Value^) ^& chr(34^) ^& vbcrlf
echo Next
echo Extract = Line
echo End if
echo End Function
)>"%tmp%\%~n0.vbs"
cscript /nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::-----------------------------------------------------------------------------------------------------------
:ExplorerIT <LogFile>
#For /f "delims=" %%a in ('Type "%~1"') do (
Start "SelectFile" Explorer /select,"%%~a"
)
Exit /B
::-----------------------------------------------------------------------------------------------------------
So I am creating a code in VBS to automate setting up computers. Step 1 of my code works well, Step 2 not implemented in this example but works good, Step 3 throws me a "Expected end of Statement" error at Command_3A.
The string I am trying to set is start "Lightspeed" /wait /i "Programs\Lightspeed\UserAgentx64 V2.1.14.msi"
I have tried these ways but I am missing something.
Command_3A = "start "Lightspeed" /wait /i "Programs\Lightspeed\UserAgentx64 V2.1.14.msi" "`
Command_3A = "start " ""Lightspeed"" " /wait /i " ""Programs\Lightspeed\UserAgentx64 V2.1.14.msi"" "`
Command_3A = (start "Lightspeed" /wait /i "C:\Users\ccollins\Desktop\ThumbDrive\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" )`
Here is my code:
'Dim objShell
Set objShell = WScript.CreateObject ("WScript.Shell")
Drive_Letter = "C:"
File_Path = "C:\Users\ccollins\Desktop\ThumbDrive\"
' Step 1 - Set Power Settings
Command_1A = "powercfg /change standby-timeout-ac 0"
Command_1B = "powercfg /change standby-timeout-dc 15"
Command_1C = "powercfg /change monitor-timeout-ac 0"
Command_1D = "powercfg /change monitor-timeout-dc 15"
Command_1E = "powercfg /change hibernate-timeout-ac 0"
Command_1F = "powercfg /change hibernate-timeout-dc 15"
objShell.Run "cmd /k " & Command_1A & "&" & Command_1B & "&" & Command_1C & "&" & Command_1D & "&" & Command_1E & "&" & Command_1F & "& exit"
' Step 2 - Remove Bloatware (Win10Apps)
' Step 3 - Install wanted programs
Command_3A = (start "Lightspeed" /wait /i "C:\Users\ccollins\Desktop\ThumbDrive\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" )
Command_3B = "start "Acrobat" /wait "Programs\AcroRdrDC1801120058_en_US.exe" /sAll "
Command_3C = "start "AZMerit" /wait /I "Programs\AzMERITSecureBrowser10.4-2018-08-02.msi" /passive "
Command_3D = "start "Java" /wait "Programs\jre-8u201-windows-x64.exe" /s "
Command_3E = "start "Chrome" /wait "Programs\ChromeStandaloneSetup64.exe" /silent /install "
Command_3F = "start "Eset" /wait "Programs\ESet Rip and Replace.exe" "
objShell.Run "cmd /k " & Drive_Letter & "&" & Command_3A & "&" & Command_3B & "&" & Command_3C & "&" & Command_3D & "&" & Command_3E & "&" & Command_3F & "& exit"
Set oShell = Nothing'
I am definitely missing something and just need another set of eyes to look at my code.
So this is what I came up with. I had to use Chr(34) for the " in the code that wanted inserted as part of the command. I also inserted an input box for sPath and UAC control.
Set wshShell = WScript.CreateObject("WScript.Shell")
dim sPath
' ----------------------------------------------------------'
' UAC Control
If WScript.Arguments.Length = 0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe" _
, Chr(34) & WScript.ScriptFullName & Chr(34) & " RunAsAdministrator", , "runas", 1
WScript.Quit
End If
'Step 0 - Set Drive Letter or File Path
sPath = InputBox("Enter the Path to the Drive. If entering just drive letter then add :, if file path remove the end \")
' Step 1 - Set Power Settings
' Step 2 - Remove Bloatware (Win10Apps)
' Step 3 - Install wanted programs
Function GetOsBits()
Set shell = CreateObject("WScript.Shell")
If shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
GetOsBits = 64
Else
GetOsBits = 32
End If
End Function
Command_3A = Chr(34) & sPath & "\Programs\Lightspeed\UserAgentx64 V2.1.14.msi" & Chr(34)
Command_3B = Chr(34) & sPath & "\Programs\Lightspeed\UserAgentx86 V2.1.14.msi" & Chr(34)
Command_3C = Chr(34) & sPath & "\Programs\AcroRdrDC1801120058_en_US.exe" & Chr(34) & "& /sAll "
Command_3D = Chr(34) & sPath & "\Programs\Java\jre-8u201-windows-x64.exe" & Chr(34) & "& /s "
Command_3E = Chr(34) & sPath & "\Programs\Java\jre-8u201-windows-i586.exe" & Chr(34) & "& /s "
Command_3F = Chr(34) & sPath & "\Programs\Chrome\ChromeStandaloneSetup64.exe" & Chr(34) & "& /silent /install "
Command_3G = Chr(34) & sPath & "\Programs\Chrome\ChromeStandaloneSetupi586.exe" & Chr(34) & "& /silent /install "
Command_3H = Chr(34) & sPath & "\Programs\ESet Rip and Replace.exe" & Chr(34)
If GetOsBits = 64 Then
wshShell.Run(Command_3A) 'LightSpeed
wscript.Sleep 4000
wshShell.Run(Command_3C) 'Adobe Reader
wscript.Sleep 30000
wshShell.Run(Command_3D) 'Java
wscript.Sleep 30000
wshShell.Run(Command_3F) 'Chrome
wscript.Sleep 30000
wshShell.Run(Command_3H) 'Eset
wscript.Sleep 30000
Else
wshShell.Run(Command_3B) 'LightSpeed x86
wscript.Sleep 4000
wshShell.Run(Command_3C) 'Adobe Reader
wscript.Sleep 4000
wshShell.Run(Command_3E) 'Java x86
wscript.Sleep 30000
wshShell.Run(Command_3G) 'Chrome x86
wscript.Sleep 30000
wshShell.Run(Command_3H) 'Eset
wscript.Sleep 30000
End If
Set oShell = Nothing
Is it possible to run any type of file (like,. mp3, doc, exe..) with a Vbscript file at a specific time?
I looked in many places but there were no success..
Give a try for this example that can schedule Notepad to be executed everyday at 10:00 AM
So, you need just to modify those 3 arguments in this script to yours :
TaskName
App_FullPath
strTime
Option Explicit
Dim TaskName,App_FullPath,strTime
TaskName = "Execute_Notepad"
App_FullPath = "C:\windows\notepad.exe"
strTime = "10:00"
Call CreateTask(TaskName,App_FullPath,strTime)
'*****************************************************************
Sub CreateTask(TaskName,App_FullPath,strTime)
Dim ws,strtask,exitcode
Set ws = CreateObject("Wscript.Shell")
strtask = "schtasks /create /sc Daily /tn "& qq(TaskName) & _
" /tr "& qq(App_FullPath) & _
" /st " & strTime & " /f"
exitcode = ws.Run(strtask, 0, True)
If exitcode <> 0 Then
WScript.Echo "External command failed: " & Hex(exitcode)
Else
wscript.echo "Success !"
End If
End Sub
'*****************************************************************
Function qq(str)
qq = chr(34) & str & chr(34)
End Function
'*****************************************************************
Edit : Batch file to show or delete a numbered task names
#echo off
Mode 100,3 & color 0A
Title Delete Tasks with their time tasks execution by Hackoo 2017
:Menu
Mode 100,3 & color 0A
cls & echo(
echo Type the time with this format "hh:mm" or a task name to show or delete for scheduled Tasks
set /a "count=0"
set /p "strTime="
cls & echo(
echo Please wait a while ... looking for a scheduled Tasks for "%strTime%"
Setlocal EnableDelayedExpansion
#for /f "tokens=1 delims=," %%a in ('schtasks /query /fo csv ^| find /I "%strTime%"') do (
set /a "Count+=1"
set "TaskName[!Count!]=%%~a"
)
Rem Display numbered Task Names
Mode 90,30 & cls & echo(
#for /L %%i in (1,1,%Count%) do (
set "Task=[%%i] - !TaskName[%%i]:~1!"
echo !Task!
)
If not defined Task (
Mode 90,3 & Color 0C
echo(
echo No Scheduled Tasks found with this criteria
Timeout /T 3 /nobreak >nul & goto Menu
)
echo(
Rem Asking user if he wants to delete or not the numbered task names
echo Type the number of the task to delete !
set /p "Input="
#for /L %%i in (1,1,%Count%) Do (
If "%INPUT%" EQU "%%i" (
schtasks /delete /tn "!TaskName[%%i]:~1!"
)
)
echo(
echo Type any key to show and delete another task !
Pause>nul
Goto Menu
In this vbscript you can change 4 arguments :
TaskName
AppFullPath
StartTime
Frequency
Option Explicit
Dim TaskName,AppFullPath,StartTime,Frequency
'************* Four params can be changed here********************
TaskName = "Execute Notepad by Hackoo"
AppFullPath = "C:\windows\notepad.exe"
StartTime = "10:00"
Frequency = "Minute"
REM The value of frequency can be taken
Rem as "MINUTE", "HOURLY", "DAILY", "WEEKLY" or "MONTHLY"
REM https://technet.microsoft.com/en-us/library/bb490996.aspx
REM Don't change anything under this line
'************************** Main *********************************
Call CreateTask(TaskName,AppFullPath,StartTime,Frequency)
'*****************************************************************
Sub CreateTask(TaskName,AppFullPath,StartTime,Frequency)
Dim ws,strtask,exitcode
Set ws = CreateObject("Wscript.Shell")
strtask = "schtasks /create /sc "& Frequency &" /tn "& qq(TaskName) & _
" /tr "& qq(AppFullPath) & _
" /st " & StartTime & " /f"
exitcode = ws.Run(strtask, 0, True)
If exitcode <> 0 Then
WScript.Echo "External command failed: " & Hex(exitcode)
Else
wscript.echo "The Task "& qq(TaskName) & " is created successfully !"& vbcrlf &_
"to be run "& qq(Frequency) &" with a StartTime at " & qq(StartTime) & ""
End If
End Sub
'*****************************************************************
Function qq(str)
qq = chr(34) & str & chr(34)
End Function
'*****************************************************************
I am trying to use the code located here, and with some tweaking for HTA. It works to a point:
Set wshShell = WScript.CreateObject( "WScript.Shell" )
changes into:
Set wshShell = CreateObject( "WScript.Shell" )
The popup comes up, but it won't go away until I click it. I need it appear when a process is running, then disappear when it ends. Why is my execution failing to do this?
ProgressMsg "Copying, Please wait.", "File Being Copied"
strCMD = "cmd.exe /c robocopy " & strLocalSemesterCourse & " " & strServerSemesterCourse &" " & strFileName & " /LOG+:" & strLogName & " /V /FP /TEE"
nReturn = objShell.Run(strCMD, 1, true)
ProgressMsg "", "Finished"
You need to define objProgressMsg as a global variable for this to work:
Dim objProgressMsg
...
ProgressMsg "Copying, Please wait.", "File Being Copied"
strCMD = "cmd.exe /c robocopy " & strLocalSemesterCourse & " " _
& strServerSemesterCourse &" " & strFileName & " /LOG+:" & strLogName _
& " /V /FP /TEE"
nReturn = objShell.Run(strCMD, 1, true)
ProgressMsg "", "Finished"
Without the global variable, ProgressMsg() will use a local variable objProgressMsg. Local variables don't retain their value after the function exits, so the variable will be empty every time you call the function.