Discussion:
VB script question
(too old to reply)
s***@gmail.com
2015-10-28 18:21:51 UTC
Permalink
Hello I have 3 different vb Scripts that I like to put it in one.
And the script should be run only if the folder or file not present. Scripts should run so people can not see any error messages. Trying to avoid phone calls to help desk.Is it possible to make a one script out of all three if yes can I get an example of the script. I have Windows 7 machines in my organization.

Script 1 Creates folder (Because root folder exist but not the entire path)
========================================
Option Explicit

Dim shl
Set shl = CreateObject("WScript.Shell")
Call shl.Run("%COMSPEC% /c mkdir ""%APPDATA%\Microsoft\Document Building Blocks\1033\15""",0,true)
=================================================

Script 2
==================================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objWShell = wScript.createObject("WScript.Shell")

usrName = objWShell.expandEnvironmentStrings("%USERNAME%")

objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " , "C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building Blocks\1033\", True
=======================================================

Script 3
===============================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objWShell = wScript.createObject("WScript.Shell")

usrName = objWShell.expandEnvironmentStrings("%USERNAME%")

objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " , "C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building Blocks\1033\15\", True
==============================================================================


All three scripts work from the same User Login script group policy. But like to enhance
JJ
2015-10-29 12:13:41 UTC
Permalink
On Wed, 28 Oct 2015 11:21:51 -0700 (PDT), ***@gmail.com wrote:
And the script should be run only if the folder or file not present.

Use IF statement. See your VBScript guide for details.
Post by s***@gmail.com
Scripts should run so people can not see any error messages.
Use ON ERROR statement. See your VBScript guide for details.
Post by s***@gmail.com
Is it possible to make a one script out of
all three if yes can I get an example of the script.
Yes. Just copy and paste script2 into script1, and then script3 into
script1.
Post by s***@gmail.com
But like to enhance it little but by making it one script.
Sorry, I'm not a mind reader.

PS) Use a proper newsgroup client.
Todd Vargo
2015-10-31 16:52:15 UTC
Permalink
Post by s***@gmail.com
And the script should be run only if the folder or file not present.
Use IF statement. See your VBScript guide for details.
Post by s***@gmail.com
Scripts should run so people can not see any error messages.
Use ON ERROR statement. See your VBScript guide for details.
Post by s***@gmail.com
Is it possible to make a one script out of
all three if yes can I get an example of the script.
Yes. Just copy and paste script2 into script1, and then script3 into
script1.
Not quite that simple. Since script1 uses Option Explicit, the undefined
variable names usrName, objFSO, and objWShell would present errors by
simply copy/pasting into the first script without respective
declarations. Although not problematic, usrName, objFSO, and objWShell
would not need redefined to the same value a second time.
Also, by adding OERN statement, the IF statement would not be needed
in this instance.
Post by s***@gmail.com
Post by s***@gmail.com
But like to enhance it little but by making it one script.
Sorry, I'm not a mind reader.
Having a bad day?

If you are going to take the time to respond, you could at least
copy/past the OPs own code in the correct order and clean it up as
required to make it one *working* script. Don't assume the OP wrote the
original code.

'Watch for word wrap. All lines begin with 2 spaces.
Option Explicit

Dim objFSO, objWShell, usrName
Set objFSO = CreateObject("Scripting.FileSystemObject")

set objWShell = CreateObject("WScript.Shell")


On Error Resume Next 'Skips to next line if folder or file exists.


Call objWShell.Run("%COMSPEC% /c mkdir ""%APPDATA%\Microsoft\Document
Building Blocks\1033\15""",0,true)

usrName = objWShell.expandEnvironmentStrings("%USERNAME%")

objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " ,
"C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building
Blocks\1033\", True

objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " ,
"C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building
Blocks\1033\15\", True
Post by s***@gmail.com
PS) Use a proper newsgroup client.
Consider taking up a new hobby.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
s***@gmail.com
2015-10-29 17:23:34 UTC
Permalink
Post by s***@gmail.com
Hello I have 3 different vb Scripts that I like to put it in one.
And the script should be run only if the folder or file not present. Scripts should run so people can not see any error messages. Trying to avoid phone calls to help desk.Is it possible to make a one script out of all three if yes can I get an example of the script. I have Windows 7 machines in my organization.
Script 1 Creates folder (Because root folder exist but not the entire path)
========================================
Option Explicit
Dim shl
Set shl = CreateObject("WScript.Shell")
Call shl.Run("%COMSPEC% /c mkdir ""%APPDATA%\Microsoft\Document Building Blocks\1033\15""",0,true)
=================================================
Script 2
==================================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objWShell = wScript.createObject("WScript.Shell")
usrName = objWShell.expandEnvironmentStrings("%USERNAME%")
objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " , "C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building Blocks\1033\", True
=======================================================
Script 3
===============================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objWShell = wScript.createObject("WScript.Shell")
usrName = objWShell.expandEnvironmentStrings("%USERNAME%")
objFSO.CopyFile "\\192.168.80.19\public\building blocks.dotx " , "C:\Users\" & usrName & "\appdata\Roaming\Microsoft\Document Building Blocks\1033\15\", True
==============================================================================
All three scripts work from the same User Login script group policy. But like to enhance it little but by making it one script.
Thank you very much for your help. Sorry if I asked a question in a wrong group. I thought this one is proper for vbscripts.
Loading...