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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...