+ Post New Thread
Results 1 to 3 of 3
Coding Thread, hta to share folder in Coding and Web Development; Currently I have the below vbscript Code: Dim strPath WScript.Echo BrowseFolder( "My Computer", False ) Function BrowseFolder( myStartLocation, blnSimpleDialog ) ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,044
    Thank Post
    3,579
    Thanked 1,119 Times in 1,024 Posts
    Rep Power
    377

    hta to share folder

    Currently I have the below vbscript

    Code:
    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 ?

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,271
    Thank Post
    884
    Thanked 2,749 Times in 2,322 Posts
    Blog Entries
    11
    Rep Power
    785
    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.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,044
    Thank Post
    3,579
    Thanked 1,119 Times in 1,024 Posts
    Rep Power
    377
    Quote Originally Posted by SYNACK View Post
    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 )



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 21st May 2009, 11:16 PM
  2. share a folder on edubuntu for xp users
    By Uraken in forum *nix
    Replies: 6
    Last Post: 2nd February 2008, 10:03 PM
  3. Redirecting Fonts system folder to a network share.
    By markwilliamson2001 in forum Windows
    Replies: 5
    Last Post: 18th January 2008, 04:02 PM
  4. win2k3 share sub-folder missing security tab
    By torledo in forum Windows
    Replies: 9
    Last Post: 8th January 2008, 09:09 PM
  5. My Documents Folder Redirection to a Share?
    By link470 in forum Windows
    Replies: 7
    Last Post: 5th December 2007, 03:53 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •