0

So it's been a hot minute since I've worked with VBS, but I've never run into this problem with simple things like this. Below is the current state of my script to navigate through File Explorer to a specific file, open it, and replace one value in it(the last bit is still in the works.) My issue is that the script does not execute consistently. Sometimes it only opens the file explorer window and then seems to do nothing, but sometimes it works perfectly. When it doesn't, I check task manager to see if the script is still executing, which it should be, but it doesn't show up in processes. Any ideas?

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "explorer"
WScript.Sleep 700
WshShell.AppActivate "File Explorer"
WScript.Sleep 500
WshShell.SendKeys("{TAB}")
WScript.Sleep 100
WshShell.SendKeys("{TAB}")
WScript.Sleep 100
WshShell.SendKeys("{TAB}")
WScript.Sleep 100
WshShell.SendKeys("{TAB}")
WScript.Sleep 100
WshShell.SendKeys("{TAB}")
WScript.Sleep 100

WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{RIGHT}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("{DOWN}")
WScript.Sleep 100
WshShell.SendKeys("~")
WScript.Sleep 100
WshShell.SendKeys("{TAB}")
WScript.Sleep 100
WshShell.SendKeys("T")
WScript.Sleep 100
WshShell.SendKeys("E")
WScript.Sleep 100
WshShell.SendKeys("S")
WScript.Sleep 100
WshShell.SendKeys("S")
WScript.Sleep 100
WshShell.SendKeys("~")
WScript.Sleep 100
WshShell.SendKeys("T")
WScript.Sleep 100
WshShell.SendKeys("~")
WScript.Sleep 100
WshShell.SendKeys("^{H}")
  • 2
    Are you aware that VBScript provides methods to _directly_ open a file and modify it? What you're currently doing doesn't seem "simple" to me in any way! – 41686d6564 stands w. Palestine Jun 29 '18 at 15:41
  • @AhmedAbdelhameed Its the simplest for me in this moment with the computers that I'm working with. The question was about the inconsistent functionality. – Chris Carbone Jun 29 '18 at 15:45
  • It will always be inconsistent. This is what I meant by saying that this isn't simple at all. Unless you have a very good reason for doing it this way, you really shouldn't be opening and modifying text files by sending keyboard commands like this. Here's a question on SO that might help you: [Read and write into a file using VBScript](https://stackoverflow.com/q/1142678/4934172). If you try that and you have a _specific problem_ about it, you're welcome to come back and ask another question. – 41686d6564 stands w. Palestine Jun 29 '18 at 15:50
  • I've noticed lots of inconsistencies with SendKeys, especially on Windows 10. I have had to completely remove it from my scripts because of this. – langstrom Jun 29 '18 at 16:06
  • 1
    Issue was with the sleep timers in the beginning. thanks for the help – Chris Carbone Jun 29 '18 at 16:50

0 Answers0