Link to home
Start Free TrialLog in
Avatar of NetManaged
NetManagedFlag for United States of America

asked on

Run sub based on InputBox value

Hello, I need help creating a vbscript to run subs or loops or whatever is best to run a robocopy command string based on user input.
Attached is the effort so far (that doesn't work).

This is a modification of another process that does work (no subs, just put in folder names)
Looking forward to your help!
Dim iBernieFolder

	iBernieFolder = InputBox("Enter Letter of Permissions to set for new folder")

	if iBernieFolder = r Then
Do
strProjectName = InputBox("Enter the Employee Resources Folder Name to Create (ie. 09069.0 Richmond, etc. :")
Do While strProjectName = ""
MsgBox "Please enter the Employee Resources Folder Name to proceed!"
strProjectName = InputBox("Employee Resources Folder Name to Create:")
strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\R_NTFS"
strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName

   dim oExec, WshShell
   strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
   
   Set WshShell = wscript.createobject("wscript.shell")
   Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
   set WshShell = nothing
Loop
   


	elseif iBernieFolder = w Then
Do
strProjectName = InputBox("Enter the Employee Resources Folder Name to Create (ie. 09069.0 Richmond, etc. :")
Do While strProjectName = ""
MsgBox "Please enter the Employee Resources Folder Name to proceed!"
strProjectName = InputBox("Employee Resources Folder Name to Create:")
strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\W_NTFS"
strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName

   dim oExec, WshShell
   strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
   
   Set WshShell = wscript.createobject("wscript.shell")
   Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
   set WshShell = nothing
Loop  



		elseif iBernieFolder = x Then
Do
strProjectName = InputBox("Enter the Employee Resources Folder Name to Create (ie. 09069.0 Richmond, etc. :")
Do While strProjectName = ""
MsgBox "Please enter the Employee Resources Folder Name to proceed!"
strProjectName = InputBox("Employee Resources Folder Name to Create:")
strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\X_NTFS"
strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName

   dim oExec, WshShell
   strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
   
   Set WshShell = wscript.createobject("wscript.shell")
   Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
   set WshShell = nothing
Loop
   
MsgBox "ATTENTION:  Do not close console/command prompt window!  The window will close when the copy of " & strPackage & " is complete. On a VPN connection this can take up to 

2:30 minutes or longer (depending on your network/Internet connection and traffic at Redmond) to complete. Please click OK now."

Endif

Open in new window

Avatar of Psy053
Psy053
Flag of Australia image

Is this the complete script?  What are r, w and x?



The snippet below uses Do Until Loops for input verification, then uses a Select Case statement to run the appropriate command.

Please have a look through it, and if you have any questions please let me know.


dim iBernieFolder
dim oExec
dim WshShell

Set WshShell = Wscript.CreateObject("Wscript.Shell")

Do Until iBernieFolder = "R" OR iBernieFolder = "W" OR iBernieFolder = "X"
	iBernieFolder = Ucase(InputBox("Enter Letter of Permissions to set for new folder" & VbCr & "(R, W or X)"))
Loop


Do until Len(strProjectName) > 0
	strProjectName = InputBox("Enter the Employee Resources Folder Name to Create (ie. 09069.0 Richmond, etc):")
Loop


Select Case iBernieFolder
	Case "R"
		strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\R_NTFS"
		strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName
		strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _ 
				chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30" & strDest1
		Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
		Set WshShell = Nothing	


	Case "W"
		strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\W_NTFS"
		strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName
		strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _
				chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
		Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
		Set WshShell = Nothing

	Case "X"
		strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources Folders\X_NTFS"
		strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName
		strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _
				chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
		Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters)
		Set WshShell = nothing
End Select

MsgBox 	"ATTENTION:  Do not close console/command prompt window!  The window will close when the " & _ 
	"copy of " & strPackage & " is complete. On a VPN connection this can take up to 2:30 " & _
	"minutes or longer (depending on your network/Internet connection and traffic at Redmond) to " &_ 
	"complete. Please click OK now."

Open in new window

Avatar of NetManaged

ASKER

Hey Psy053!

   My apologies for the delay in responding to you! I tested your script, after a very slight modification, it worked a treat (see code attached).

For additional points, would you mind modifying to allow the following?
Ability to click Cancel on the Input boxes and the process end gracefully.

Thanks!
Greg
dim iBernieFolder 
dim oExec 
dim WshShell 
 
Set WshShell = Wscript.CreateObject("Wscript.Shell") 
 
Do Until iBernieFolder = "R" OR iBernieFolder = "W" OR iBernieFolder = "X" 
        iBernieFolder = Ucase(InputBox("Enter Letter of Permissions to set for new folder" & VbCr & "(R, W or X)")) 
Loop 
 
 
Do until Len(strProjectName) > 0 
        strProjectName = InputBox("Enter the Employee Resources Folder Name to Create (ie. 09069.0 Richmond, etc):") 
Loop 
 
 
Select Case iBernieFolder 
        Case "R" 
                strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources SHARED Engineering Folder Template\R_NTFS" 
                strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName 
                strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _  
                                chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30"
                Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters) 
                Set WshShell = Nothing   
 
 
        Case "W" 
                strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources SHARED Engineering Folder Template\W_NTFS" 
                strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName 
                strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _ 
                                chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30" 
                Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters) 
                Set WshShell = Nothing 
 
        Case "X" 
                strSource = "\\Mch10\public\Projects\_ProjectFolderTools\Employee Resources SHARED Engineering Folder Template\X_NTFS" 
                strDest1 = "\\Mch10\public\Employee Resources\SHARED\_Engineering" & "\" & strProjectName 
                strParameters = chr(34) & strSource & chr(34) & chr(32) & chr(34) & strDest1 & _ 
                                chr(34) & chr(32) & "/E /COPYALL /V /LOG:copy.log /R:10 /W:30" 
                Set oExec = WshShell.Exec ("\\mch10\public\Projects\_ProjectFolderTools\robocopy.exe" & chr(32) & strParameters) 
                Set WshShell = nothing 
End Select 
 
MsgBox  "ATTENTION:  Do not close console/command prompt window!  The window will close when the " & _  
        "copy of " & strPackage & " is complete. On a VPN connection this can take up to 2:30 " & _ 
        "minutes or longer (depending on your network/Internet connection and traffic at Redmond) to " &_  
        "complete. Please click OK now."

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Psy053
Psy053
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great Job! Thanks! Points upgraded and awarded.