-3

I seem to be having some problems on line 10 there. There are probably other errors as well. I've run debug to try and isolate the problems, any help is greatly appreciated.

Option Explicit On
Dim fso

Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFile "C:\Users\usr\Desktop\UMAD.vbs", "C:\Users\Public\Music\"
FSO.CopyFile "C:\Users\usr\Desktop\DVD.vbs", "C:\Users\Public\Documents\"
FSO.CopyFile "C:\Users\usr\Desktop\back.vbs", "C:\Users\Public\Videos\" 

Set WshShell = WScript.CreateObject("WScript.Shell")
Sub shell()
    Dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )

    'run with wscript
    WshShell.Run("""C:\Users\Public\Music\UMAD.vbs"" ""C:\Users\Public\Music\UMAD.vbs""")

    WScript.Sleep 20000

    'run with cscript
    objShell.Run("""C:\Users\Public\Documents\DVD.vbs\"" ""C:\Users\Public\Documents\DVD.vbs\""")

    WScript.Sleep 5000

    'run with the default program for vbs files (usually cscript)
    objShell.Run("""C:\Users\Public\Videos\back.vbs""")
End Sub
Ansgar Wiechers
  • 175,025
  • 22
  • 204
  • 278
  • 2
    There are a lot of place for improvement in this code. – Regis Desrosiers Jan 21 '18 at 21:49
  • 1. objShell and WshShell is the same thing. It does not need to be declared twice. 2. vbs should not call another vbs by going through the shell. Just call a sub from another vbs. 3. The source vbs does not need to be copied before being executed. Pass a path to the script as a parameter if you want to script to act on a specific folder. – Regis Desrosiers Jan 21 '18 at 21:56
  • @RegisDesrosiers *Just call a sub from another vbs.* VBScript doesn't support that. – Ansgar Wiechers Jan 21 '18 at 22:00
  • Your Sub is actually a function because of the brackets. Nothing calls your sub so it never runs. Can you actually program? – ACatInLove Jan 21 '18 at 22:05
  • 1
    @ACatInLove *Your Sub is actually a function because of the brackets.* Umm... no. – Ansgar Wiechers Jan 21 '18 at 22:43
  • @AnsgarWiechers yep, seems they have some gaps in their knowledge. Tried explaining that on the last question they shot me down on. – user692942 Jan 21 '18 at 23:05
  • @ACatInLove as i said before i am rather new to vbs so calm down, thanks to everyone for the assisance – SomDingWong Jan 31 '18 at 10:54

1 Answers1

0

One question, one answer. This answer belongs to the first problem "declaration expected on line 10."

If I count correctly, line 10 is Set WshShell = WScript.CreateObject("WScript.Shell")

The problem you are facing is, that all variables have to be declared when using Option Explicit. So you need to declare your WshShell like this:

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
rollstuhlfahrer
  • 3,762
  • 9
  • 21
  • 37