VBS script

Dell / Precision 530
July 28, 2009 at 23:54:34
Specs: Windows, Dell percision 530
I am running a series of these
oShell.Run """C:\Program Files\Internet Explorer\IExplore.exe"

Is there a way I can make the IE window close after its finished?

I tried oshell.quit

My variables are as listed

Dim wShell, oExec
Set wShell = CreateObject("WScript.Shell")
Set WshShl = Wscript.CreateObject("WScript.Shell")

I tried WshShl. quit also but no luck

Learning in progress..........


See More: VBS script

Report •


#1
July 31, 2009 at 12:55:45
Can you simply use Alt-F4 to close the window, In the following script all I have it doing is opening explorer, waiting 5 seconds and then send an alt-f4 to close the window, the whole Appactivate thing is optional, if you know exactly what will be in the title bar, you can set it to activate that specific window and then send the Alt-F4 so that you know which window will close.


'Run Internet explorer
wshshell.run "iexplore"

Wscript.sleep 5000

'If you have a specific instance you want to close
'type the name of the title bar here.
WshShell.AppActivate "Title bar info - Windows Internet Explorer"

'send Alt-F4 to close window
WshShell.SendKeys "%{F4}"


Report •

#2
August 11, 2009 at 00:06:06
Worked great thank you

I have a script that I run to test our proxy servers. To change my proxy settings I have my VBS script call upon .reg files and then proceed by opening an IE window to see if the changes were successful. The code is long and it requires 6 or 7 .reg files be somewhere (I have them in the same folder) anyway I'm trying to eliminate the need for the extra .reg files, would it makes sense to put the registry modifications within the script? Or is calling an outside file good?

Also I have the same code reused for each setting I would like to setup an array (I believe this would be good?) and just call one function + array name which would point to the new .reg file. This would compact my code by a lot. Is this possible with VBS? I tried to make an array with names associated with each .reg filename (They are not all the same) It works, osrt of, It at least opens an IE window but does not apply the .reg file that is associated with the array name. Is there a way I can call (arrayname) And have that passed into E.G. wShell.Exec("regedit /s proxy.reg")
Like the string name of the .reg I wish to run? I know thats the whole point of an array well one of its capabilities. But cannot get the code to to see within the array it seems
An example of my code

Dim wShell, oExec
Set wShell = CreateObject("WScript.Shell")
Set WshShl = Wscript.CreateObject("WScript.Shell")
Set ProxySet1 = ("proxy1.reg")


Set oExec = wShell.Exec("ProxySet1")

But it wont run the associated .reg file for ProxySet1

Any help would be great

Learning in progress..........


Report •

#3
August 17, 2009 at 06:04:27
I guess I'm a little confused at what you would like to accomplish. Is there a reason that you require 6-7 .Reg files? If I were to write a script I would actually just write the registry changes into the script instead of calling .REG files. If you simply want run all of your REG files from an Array this is how I would put them into an array and then run them.

Option Explicit

Dim WshShell, arrRegFiles, Regfile

Set WshShell = CreateObject("WScript.Shell")

'Array of your .REG files, assuming that they are located in
'the same folder as you VB Script.
arrRegFiles = array("%%0\..\Proxy1.reg","%%0\..\Proxy2.reg",_
"%%0\..\Proxy3.reg","%%0\..\Proxy4.reg",_
"%%0\..\Proxy5.reg","%%0\..\Proxy6.reg")


'For_Each_Next loop, runs through each .REG file that you put
'in the array.
For each RegFile in arrRegFiles
WshShell.run "RegEdit /s " & RegFile
next


Report •

Related Solutions

#4
August 17, 2009 at 13:25:57
I just re-read your post. And I think I'm understanding this now, you have 6 or seven proxy servers that you want to see if they are working properly so what you do is have a script set the server using one of 6 .reg files, open IE to see if the server is running, then close IE call the next .reg file to change the server and so on. Let me ask you this, do you need to change anymore settings then simply the ProxyServer name? If that is the only setting that you need changed the following should do exactly what you are asking for, as I noted. I would probably use F5 To simply refresh the page instead of closing it out.

Option Explicit

Dim WshShell, objRegistry
Dim strComputer, strProxyPath, arrProxyServers, Server

Set WshShell = CreateObject("WScript.Shell")
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strProxyPath = "Software\Microsoft\Windows\CurrentVersion\"&_
"Internet Settings"

'Array of your Proxy servers
arrProxyServers = array("http://ProxyServerName1:80","http://ProxyServerName2:80",_
"http://ProxyServerName3:80","http://ProxyServerName4:80",_
"http://ProxyServerName5:80","http://ProxyServerName6:80")


'For_Each_Next loop, runs through each Proxy server,
'Opening IE, waiting for a bit, then closing IE
For each Server in arrProxyServers
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strProxyPath, "ProxyEnable", 1
objRegistry.SetStringValue HKEY_CURRENT_USER, strProxyPath, "ProxyServer", server
WshShell.run "iexplore"
Wscript.sleep 5000
WshShell.SendKeys "%{F4}" 'or you could simply use {F5} to refresh.
next


Report •


Ask Question