Answer» 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 thanksYou 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
Quote from: oldun on March 31, 2012, 05:03:20 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.
Thanks...
|