Login | |
|
 |
Remote File Share loop - 3/10/2008 6:45:59 AM
|
|
 |
|
| |
Wyvern
Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
|
got a script together to create file share remotely with user input, however, I have been beating my brains out trying to get a working loop for the whole thing. I want to have them input a yes or a no to create another share, and only have the loop end when they input a no. I can get it to loop, but only the share creation, not the yes/no box. Arrghhh! Here is the script minus my broken attmepts on the loop. Just point me in the right direction and I can probably get it whipped. Maybe I just need sleep. Const FILE_SHARE = 0 Const MAXIMUM_CONNECTIONS = TRUE ''=====System variables for Event Writer===== const HKEY_LOCAL_MACHINE = &H80000002 Const ForWriting = 2 Const ForReading = 1 Const ForAppending = 8 Const EVENT_SUCCESS = 0 ''=====Dim statements - dont change===== Dim ServName, Drive, Path, FolderName, Descript Dim objEShell ''Event writer Set objEShell = WScript.CreateObject("Wscript.Shell") ServName = InputBox("Please enter the server name for the new share, without the \\.", "Server Name for New Share") Drive = InputBox ("Please enter the Drive letter for the new folder. The drive partiton must exist on the server specified.", "Drive letter for New Folder") Path = InputBox("Please enter the full path for the new share folder, ending with \ .") FolderName = InputBox ("Please enter the folder name for the new share.", "Folder Name for New Share") Descript = InputBox ("Please enter a description for the new share.", "Description of New Share") Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) Then Set objFolder = objFSO.GetFolder("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) CreateShare WScript.Echo"Folder already exists, creating share." Else Wscript.Echo "Folder does not exist. Proceeding to create the folder: " & Drive & ":\" & Path & FolderName & " on " & ServName Set objFSOCF = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSOCF.CreateFolder("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & ServName & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") errReturn = objNewShare.Create _ (Drive & ":\" & Path & FolderName, FolderName, FILE_SHARE, _ MAXIMUM_CONNECTIONS, Descript) WScript.Echo "Finished creating the folder: " & Drive & ":\" & Path & FolderName & " on " & Server End If ''===Write info to server event log=== objEShell.LogEvent 2, "Creating new share on: " & ServName & "Shared folder is: " & Drive & "\" & Path & FolderName & " " & Descript, ServName sub CreateShare Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & ServName & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") errReturn = objNewShare.Create _ (Drive & ":\" & Path & FolderName, FolderName, FILE_SHARE, _ MAXIMUM_CONNECTIONS, Descript) End sub
_____________________________
With enough bailing wire and duct tape, almost anything is possible.
|
|
| |
|
|
|
 |
RE: Remote File Share loop - 3/10/2008 8:22:22 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
So something like: Const FILE_SHARE = 0 Const MAXIMUM_CONNECTIONS = TRUE ''=====System variables for Event Writer===== const HKEY_LOCAL_MACHINE = &H80000002 Const ForWriting = 2 Const ForReading = 1 Const ForAppending = 8 Const EVENT_SUCCESS = 0 ''=====Dim statements - dont change===== Dim ServName, Drive, Path, FolderName, Descript Dim objEShell ''Event writer Set objEShell = WScript.CreateObject("Wscript.Shell") bAnotherShare = True While bAnotherShare ServName = InputBox("Please enter the server name for the new share, without the \\.", "Server Name for New Share") Drive = InputBox ("Please enter the Drive letter for the new folder. The drive partiton must exist on the server specified.", "Drive letter for New Folder") Path = InputBox("Please enter the full path for the new share folder, ending with \ .") FolderName = InputBox ("Please enter the folder name for the new share.", "Folder Name for New Share") Descript = InputBox ("Please enter a description for the new share.", "Description of New Share") Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) Then Set objFolder = objFSO.GetFolder("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) CreateShare WScript.Echo"Folder already exists, creating share." Else Wscript.Echo "Folder does not exist. Proceeding to create the folder: " & Drive & ":\" & Path & FolderName & " on " & ServName Set objFSOCF = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSOCF.CreateFolder("\\"& ServName & "\"& Drive & "$\" & Path & FolderName) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & ServName & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") errReturn = objNewShare.Create _ (Drive & ":\" & Path & FolderName, FolderName, FILE_SHARE, _ MAXIMUM_CONNECTIONS, Descript) WScript.Echo "Finished creating the folder: " & Drive & ":\" & Path & FolderName & " on " & Server End If ''===Write info to server event log=== objEShell.LogEvent 2, "Creating new share on: " & ServName & "Shared folder is: " & Drive & "\" & Path & FolderName & " " & Descript, ServName nReturn = MsgBox("Would you like to create another share?", 4) If nReturn = 7 Then bAnotherShare = False End If Wend sub CreateShare Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & ServName & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") errReturn = objNewShare.Create _ (Drive & ":\" & Path & FolderName, FolderName, FILE_SHARE, _ MAXIMUM_CONNECTIONS, Descript) End Sub
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Remote File Share loop - 3/10/2008 8:56:55 AM
|
|
 |
|
| |
Wyvern
Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
|
I will try this out later. If this is it, I was so stinking close. thanks!!
_____________________________
With enough bailing wire and duct tape, almost anything is possible.
|
|
| |
|
|
|
|
|