Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Currently I have the below vbscript

 

Dim strPath
WScript.Echo BrowseFolder( "My Computer", False )


Function BrowseFolder( myStartLocation, blnSimpleDialog )
' This function generates a Browse Folder dialog
' and returns the selected folder as a string.
'
' Arguments:
' myStartLocation   [string]  start folder for dialog, or "My Computer", or
'                             empty string to open in "Desktop\My Documents"
' blnSimpleDialog   [boolean] if False, an additional text field will be
'                             displayed where the folder can be selected
'                             by typing the fully qualified path
'
' Returns:          [string]  the fully qualified path to the selected folder
'
' Based on the Hey Scripting Guys article
' "How Can I Show Users a Dialog Box That Only Lets Them Select Folders?"
' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0617.mspx
'
' Function written by Rob van der Woude
' http://www.robvanderwoude.com
   Const MY_COMPUTER   = &H11&
   Const WINDOW_HANDLE = 0 ' Must ALWAYS be 0

   Dim numOptions, objFolder, objFolderItem
   Dim objPath, objShell, strPath, strPrompt

   ' Set the options for the dialog window
   strPrompt = "Select a folder:"
   If blnSimpleDialog = True Then
       numOptions = 0      ' Simple dialog
   Else
       numOptions = &H10&  ' Additional text field to type folder path
   End If
   
   ' Create a Windows Shell object
   Set objShell = CreateObject( "Shell.Application" )

   ' If specified, convert "My Computer" to a valid
   ' path for the Windows Shell's BrowseFolder method
   If UCase( myStartLocation ) = "MY COMPUTER" Then
       Set objFolder = objShell.Namespace( MY_COMPUTER )
       Set objFolderItem = objFolder.Self
       strPath = objFolderItem.Path
   Else
       strPath = myStartLocation
   End If

   Set objFolder = objShell.BrowseForFolder( WINDOW_HANDLE, strPrompt, _
                                             numOptions, strPath )

   ' Quit if no folder was selected
   If objFolder Is Nothing Then
       BrowseFolder = ""
       Exit Function
   End If

   ' Retrieve the path of the selected folder
   Set objFolderItem = objFolder.Self
   objPath = objFolderItem.Path
   ' Return the path of the selected folder
   BrowseFolder = objPath


'Declare Constants
Const FS = 0
Const MC = 25
'Declare Variables
Dim objWMIService
Dim objNewShare
Dim strComputer
Dim errReturn
strComputer = "."
'Main Code
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create(objPath, objFolderItem.Name, FS, true, "VBS Shared Folder")

Select Case errReturn

Case "0"
msgbox "Share was created succesfully"

Case "2"
msgbox "Access is denied - you do not have the relevant access rights to share a folder"

Case "8"
msgbox "An unknown error has occured and this script has failed to share the folder"

Case "10"
msgbox "Invalid Level as per the win32_share class error messages"

Case "21"
msgbox "An invalid parameter was used when trying to create the share in this script"

Case "22"
msgbox "A shared folder already exists with the same share name, create a folder with a new name"

Case "23"
msgbox "You are using a re directed / mapped network path which will not work"

Case "24"
msgbox "An unknown device or directory has been used in the path for the shared folder"

Case "25"
msgbox "Net Name not found"

End Select

End Function


 

Just wondering - would it be possible to convert this into a hta - could obviously add a bit more functionality possibly with ref to permissions etc ?

Posted

Should be able to, HTAs run VBScript in a trusted container so should be able to do this as long as user permissions allow. Just add a couple of textboxes and a button to trigger the actual mapping and it should work fine.

 

You may have to redo the browsing bit though as I am unsure as to whether that would work, it should though.

Posted
Should be able to, HTAs run VBScript in a trusted container so should be able to do this as long as user permissions allow. Just add a couple of textboxes and a button to trigger the actual mapping and it should work fine.

 

You may have to redo the browsing bit though as I am unsure as to whether that would work, it should though.

 

am guessing you could use the FSO to enumerate each text field with relevant files / folders or w/e ?

 

was not sure on that point either lol - am guessing you could have a multi line text field ( not sure if its called the same thing in html )

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...