Jump to content

vbscript only works when double clicked


Recommended Posts

Hello everyone I'm pretty new to vbscript but I'm trying to make a script to check usb drives have been changed for backups. This script bellow works fine when I double click it but when I use cscript.exe or wscript.exe and even WHS it runs through the script but does not execute the code except for WScript.Echo "Worked"???

Set obj = CreateObject("Scripting.FileSystemObject")  Set objTextFile = obj.OpenTextFile("C:\purplec\BackupCheck\ListDrives.txt",1)  For i = 1 to 84	objTextFile.ReadLine  Next  strLine = objTextFile.ReadLine  objTextFile.Close  If (obj.FileExists("disk1.txt")) Then  Set objWriteFile = obj.OpenTextFile("disk2.txt",2,true)    objWriteFile.WriteLine strLine    objWriteFile.CloseElseSet objWriteFile = obj.OpenTextFile("disk1.txt",2,true)    objWriteFile.WriteLine strLine    objWriteFile.CloseEnd If  If (obj.FileExists("disk2.txt")) Then  Set objTextFile = obj.OpenTextFile("disk1.txt",1)    strLine1 = objTextFile.ReadLine    objTextFile.CloseSet objTextFile = obj.OpenTextFile("disk2.txt",1)    strLine2 = objTextFile.ReadLine    objTextFile.CloseIf strLine1 = strLine2 Then     Set objWriteFile = obj.OpenTextFile("NotChanged.txt",2,true)   objWriteFile.WriteLine strLine1   objWriteFile.WriteLine strLine2   objWriteFile.CloseElse     Set objWriteFile = obj.OpenTextFile("Changed.txt",2,true)   objWriteFile.WriteLine strLine1   objWriteFile.WriteLine strLine2   objWriteFile.Close   Set objWriteFile = obj.OpenTextFile("disk1.txt",2,true)   objWriteFile.WriteLine strLine2   objWriteFile.CloseEnd IfEnd IfWScript.Echo "Worked"

Thanks in advance :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...