0

i have a code to login to a site every 15 minutes (set to five seconds for testing) in google chrome. It needs to be logged in in order for me to use internet. in its current form, every fifteen minutes it opens another chrome browser and logs in and keeps the browser alive (its needed) after fifteen minutes it creates one more chrome browser and it continues. what i would like to do is, the second time it opens i want the first chrome browser closed. ie any any given time besides the one i am using there should only be one more window.

the current code is

foundProc = true
do  while foundProc = true
wscript.sleep (5000)
foundProc = False
procName = "chrome.exe"
procNameFriend = "Chrome"
for each Process in objWMIService.InstancesOf ("Win32_Process")
If StrComp(Process.Name,procName,vbTextCompare) = 0 then
foundProc = true        
End If
Next
If foundProc = True Then       'if chrome is open logging in to the site
Shell.Run("chrome.exe")
wscript.sleep (500)
shell.SendKeys "<login site>"      
shell.SendKeys "blah blah blah"    'now logged in
wscript.sleep (2500)
'wscript.sleep (1000)
shell.SendKeys "%{TAB}"  ' alt tab to return to current window
End If  
loop

1 Answers1

0

I'm not sure there was a question there but I'm assuming you're having trouble closing the first instance of Chrome after opening the second? If so, you can use your Win32_Process object to terminate it. Try adding this to the end of your shown script, prior to End If:

Process.Terminate

Bond
  • 16,071
  • 6
  • 30
  • 53
  • no i want both chromw windows coz it needs to be opened to access the internet. i just want to close that tab the next time the window opens – user3316111 Feb 16 '14 at 16:01