Ben,
Thank you for the refresher and the reminder to document the work.
Here's what I came up with your help:
' newproj.vbs
' Written by Jim Majorowicz, MCP
' Whitsell Computer Services
' Version 1.0
' Date: 1/23/2009
' Written for Alliant Systems
' All Rights Reserved.
' This script uses a default folder structure template to create
' a folder structure for each new project.
' Revision History:
' 0.1 - 01/22/09 - Initial attempt and testing
' 0.2 - 01/23/09 - fixed tempname/template folder constant
' confusion. First working script.
' 1.0 - 01/23/09 - Incorporated advice from Ben Scott to assist in
troubleshooting
' and clean up user experience. Thanks Ben.
' funny characters
Const sp = " " ' space
Const bs = "\" ' backslash
Const dq ="""" ' double-quote
cr = chr(13) ' carriage return
lf = chr(10) ' line feed
' other variables
Const title = "New Project Folder"
Const instructions = "Enter the project number and name of the folder set
you wish to create."
Const tempname = "00000 - Sample Project"
templatefolder = "99999 - Project Template"
XCopyCMD = "XCOPY"
XCopySWCH = "/E /H /I /K /O"
' folder containing everything
Const basepath = "P:\Projects"
'Set the program shell
Set WshShell = WScript.CreateObject("WScript.Shell")
' runs a command, waits for exit
Sub RunWait (cmd)
Const WshShellRunHidden = 0
Const WshShellRunWait = True
WshShell.Run cmd, WshShellRunHidden, WshShellRunWait End Sub
' ask user to input the name of the new folder
foldername = InputBox(instructions, title, tempname)
' prefix full paths
templatefolder = basepath & bs & templatefolder
foldername = basepath & bs & foldername
' build command
executeCMD = _
XCopyCMD & sp & _
dq & templatefolder & dq & sp & _
dq & foldername & dq & sp & _
XCopySWCH
' display, then execute
WScript.Echo "This will create a project folder called: " & foldername & cr
& lf & "Click Okay to create."
RunWait executeCMD
-----Original Message-----
From: Ben Scott [mailto:[email protected]]
Sent: Thursday, January 22, 2009 4:43 PM
To: NT System Admin Issues
Subject: Re: Retaining permissions when copying folders
On Thu, Jan 22, 2009 at 7:19 PM, Jim Majorowicz <[email protected]>
wrote:
> When I run it, I get the Input box okay, but as soon as I click okay after
> typing in some text, I get a quick dos pop up but nothing appears.
As a first guess, I'd say maybe the current working directory isn't
what you think it is when WshShell.Run is called, so the folders
aren't where XCOPY looks for them. Try prefixing the full path to the
folder names.
Some additional tips:
1. Tell WshShell.Run to wait for the command to complete, rather than
continuing immediately.
2. Have the script display what the command is before it executes
3. Use symbolic constants instead of CHR()
4. Use line continuation to make long lines easier to understand
The following is partial code:
' funny characters
Const sp = " " ' space
Const bs = "\" ' backslash
Const dq ="""" ' double-quote
' folder containing everything
Const basepath = "N:\foo\bar"
' runs a command, waits for exit
Sub RunWait (cmd)
Const WshShellRunHidden = 0
Const WshShellRunWait = True
WshShell.Run cmd, WshShellRunHidden, WshShellRunWait
End Sub
' put your user dialog stuff here
' prefix full paths
templatefolder = basepath & bs & templatefolder
foldername = basepath & bs & foldername
' build command
executeCMD = _
XCopyCMD & sp & _
dq & templatefolder & dq & sp & _
dq & foldername & dq & sp & _
XCopySWCH
' display, then execute
WScript.Echo "executeCMD = <" & executeCMD & ">"
RunWait executeCMD
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~