Jump to content

UDF: _FileCreateNetworkPlace


CyberSlug
 Share

Recommended Posts

Wow, I haven't posted in a LONG time. The info at http://community.bartdesmet.net/blogs/bart...09/23/3554.aspx was helpful in creating the following function (which I've only tested under XP Pro, by the way):

;The following function adds a network place to "My Network Places" 
; $networkResource is of the form \\server\share OR http://webserver/share OR ftp://ftp.example.com/
; $name can be any valid file name, i.e., it Cannot contain the characters \ / : * ? " < > |
;
Func _FileCreateNetworkPlace($networkResource, $name)
    Local $NHItem = @UserProfileDir & "\NetHood\" & $name
    DirCreate($NHItem)
    FileSetAttrib($NHItem, "+S")
    FileCreateShortcut($networkResource, $NHItem&'\target.lnk', "", "", $networkResource)
    IniWriteSection($NHItem&'\desktop.ini', ".ShellClassInfo", "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" & @LF & "Flags=2")
    Local $success = FileSetAttrib($NHItem&'\desktop.ini', "+SH")
    ;;ShellExecute(@UserProfileDir & "\NetHood\" & $name)  ;Open Network Place when Finished...
    Return $success
EndFunc

;Example usage

_FileCreateNetworkPlace("\\Laptop\Share", "Stuff")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

  • 3 years later...
  • 2 months later...
  • 2 weeks later...

works a treat in Windows 7 did this if its of any help, its only a snippet but should give you the idea..

Func Network_Shortcuts()
    #cs
        Description
        Does a basic todyup of the array $griups and maps the 'My Network Places' shares this works for both
        user and groups.
        
        Dependencies
        _FileCreateNetworkPlace($networkResource, $name
        vars.ini with a section named [Network Shortcuts], format for this section is: user or group, network share to be mapped and description. 
        
        [Network Shortcuts]
        peter = \\dc-pri-cfu\netlogon,Network Logon
        Domain Users = \\dc-pri-cfu\Remote Installs,Remote Install
        
        Global Veriables
        $network_shortcuts, $groups, $pbar
    $var_groups, $var_$network_shortcuts
        $var_network_shortcuts = generic_read_array($vars_file, "Network Shortcuts", $network_shortcuts)
    #ce

    ProgressSet($pbar, "Adding Network Shortcuts...")
    Local $avar, $avar_description, $avar_share, $l, $ll, $lll
    ConsoleWrite(@CRLF & @CRLF & ">>>> Network Shortcuts <<<< [" & $var_network_shortcuts & "]" & @CRLF)
    ; Read Users
    For $l = 1 To $var_network_shortcuts
        $avar_description = _StringBetween($network_shortcuts[$l][1], ",", "", +1)
        $var = StringLen($avar_description[0])
        $avar_share = StringLeft($network_shortcuts[$l][1], StringLen($network_shortcuts[$l][1]) - $var - 1)
        ;Rewrite sections of the array
        $network_shortcuts[0][2] = "Link Description"
        $network_shortcuts[$l][2] = $avar_description[0]
        $network_shortcuts[0][1] = "Share Location"
        $network_shortcuts[$l][1] = $avar_share
        ConsoleWrite($avar_share & " = " & $avar_description[0] & " remove " & $var & " char from the right" & @CRLF)
    Next
    For $ll = 1 To $var_network_shortcuts
        If $network_shortcuts[$ll][0] = @UserName Then
            ProgressSet($pbar + 1, "Network Shortcut " & $network_shortcuts[$ll][1])
            _FileCreateNetworkPlace($network_shortcuts[$ll][1], $network_shortcuts[$ll][2])
            ConsoleWrite("added User [" & @UserName & "] using Share [" & $network_shortcuts[$ll][1] & "] with Description [" & $network_shortcuts[$ll][2] & "]" & @CRLF)
        EndIf
        For $lll = 1 To $var_groups
            If $network_shortcuts[$ll][0] = $groups[$lll][1] Then
                ProgressSet($pbar + 1, "Network Shortcut " & $network_shortcuts[$ll][1])
                _FileCreateNetworkPlace($network_shortcuts[$ll][1], $network_shortcuts[$ll][2])
                ConsoleWrite("added Group [" & $groups[$lll][1] & "] using Share [" & $network_shortcuts[$ll][1] & "] with Description [" & $network_shortcuts[$ll][2] & "]" & @CRLF)
            EndIf
        Next
    Next
    If $diags = 1 Then _ArrayDisplay($network_shortcuts, "Network Shortcuts" & " " & $l, $var_network_shortcuts, 0, "<")
EndFunc ;==>Network_Shortcuts

Func _FileCreateNetworkPlace($networkResource, $name)
    #cs
        The following function adds a network place to "My Network Places"
        $networkResource is of the form \\server\share OR http://webserver/share OR ftp://ftp.example.com/
        $name can be any valid file name, i.e., it Cannot contain the characters \ / : * ? " < > |
    #ce

    Local $NHItem = @UserProfileDir & "\NetHood\" & $name
    DirCreate($NHItem)
    FileSetAttrib($NHItem, "+S")
    FileCreateShortcut($networkResource, $NHItem & '\target.lnk', "", "", $networkResource)
    IniWriteSection($NHItem & '\desktop.ini', ".ShellClassInfo", "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" & @LF & "Flags=2")
    Local $success = FileSetAttrib($NHItem & '\desktop.ini', "+SH")
    ;ShellExecute(@UserProfileDir & "\NetHood\" & $name) ;Open Network Place when Finished...
    Return $success
EndFunc ;==>_FileCreateNetworkPlace
Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...