Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: can anyone improve on this? (VBS)  (Read 7249 times)

0 Members and 1 Guest are viewing this topic.

trekxor

    Topic Starter


    Greenhorn
    • Yes
    • Clouds
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
can anyone improve on this? (VBS)
« on: March 31, 2012, 03:55:26 AM »
I have this little bit of vbs that starts a number of Programs, here email and web. At work it's x 7. I was hoping to find a way to economise on the code.
Code: [Select]
strProgramPath = """C:\Program Files (x86)\Mozilla Firefox\firefox.exe"""
SET objShell = CREATEOBJECT("Wscript.Shell")
objShell.Run strProgramPath

strProgramPath = """C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe"""
SET objShell = CREATEOBJECT("Wscript.Shell")
objShell.Run strProgramPath
SET objShell = Nothing

thanks
||Operating System: MS Windows 7 Ultimate 64-bit SP1. ||CPU: Intel Core 2 Quad Q9650  @ 3.00GHz Yorkfield 45nm Technology. ||RAM:4.00 GB Dual-Channel DDR2 @ 537MHz (5-5-5-18).
||Motherboard:Gigabyte Technology Co., Ltd. EP43-UD3L (Socket 775) ||Graphics: 1280MB GeForce GTX 570 (CardExpert Technology)
||Hard Drives: 977GB SAMSUNG HD103UJ, 488GB Seagate ST3500630NS, 488GB Hitachi Hitachi HDT725050VLA360. 488GB Western Digital WDC WD5000.

oldun

  • Guest
Re: can anyone improve on this? (VBS)
« Reply #1 on: March 31, 2012, 05:03:20 AM »
You only need to call 'CREATEOBJECT' once.
Code: [Select]
strProgramPath = """C:\Program Files (x86)\Mozilla Firefox\firefox.exe"""
SET objShell = CREATEOBJECT("Wscript.Shell")
objShell.Run strProgramPath

strProgramPath = """C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe"""
objShell.Run strProgramPath
SET objShell = Nothing

Or you could place the paths in an array and use a for loop:
Code: [Select]
arrPgm = Array("""C:\Program Files (x86)\Mozilla Firefox\firefox.exe""","""C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe""")
SET objShell = CREATEOBJECT("Wscript.Shell")
For Each pgm in arrPgm
objShell.Run pgm
wscript.sleep 1000
Next
SET objShell = Nothing

Salmon Trout

  • Guest
Re: can anyone improve on this? (VBS)
« Reply #2 on: March 31, 2012, 06:00:39 AM »
SET objShell = Nothing

If pruning lines is your aim, you can omit this line as well. The script engine automatically clears variables when they go out of scope, so clearing them manually just before then (i.e. at the end of script execution) is pointless and unnecessary.



trekxor

    Topic Starter


    Greenhorn
    • Yes
    • Clouds
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: can anyone improve on this? (VBS)
« Reply #3 on: March 31, 2012, 08:12:46 AM »
Thanks...
||Operating System: MS Windows 7 Ultimate 64-bit SP1. ||CPU: Intel Core 2 Quad Q9650  @ 3.00GHz Yorkfield 45nm Technology. ||RAM:4.00 GB Dual-Channel DDR2 @ 537MHz (5-5-5-18).
||Motherboard:Gigabyte Technology Co., Ltd. EP43-UD3L (Socket 775) ||Graphics: 1280MB GeForce GTX 570 (CardExpert Technology)
||Hard Drives: 977GB SAMSUNG HD103UJ, 488GB Seagate ST3500630NS, 488GB Hitachi Hitachi HDT725050VLA360. 488GB Western Digital WDC WD5000.