添加新的网络位置,而不是映射网络驱动器 [英] Add new network location, not map network drive

查看:1037
本文介绍了添加新的网络位置,而不是映射网络驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有100个用户,我需要为每个用户添加多个网络位置.它们不能是网络驱动器(例如Q :),因为某些用户已经映射了超过26个驱动器.

Let's say I have 100 users and I need to add several network locations for each user. They cannot be network drives (e.g. Q:) as some users already have more than 26 drives mapped.

我希望使用批处理文件或VB脚本来执行此操作.通过添加网络快捷方式,我设法使用VB脚本使其工作,但这不是用户所需的解决方案.

I was hoping to do this using either a batch file or a VB script. I've managed to get it working using a VB script by adding network shortcuts but this isn't the solution the users need.

我一直在搜索,找不到与网络位置有关的任何东西.

I've been searching and can't find anything related specifically to Network Locations.

我愿意尝试其他方法.

推荐答案

编辑以正确回答问题;在网络位置中创建快捷方式的原始答案保留在最后.

EDITED to properly answer the question; the original answer, that creates a shortcut in Network Locations, is kept at the end.

经过一些测试,网络位置是位于%AppData%\Microsoft\Windows\Network Shortcuts文件夹中的只读文件夹,其中包含两个文件:desktop.ini具有精确的内容(请参见代码)和target.lnk指向目标的快捷方式.

After some testing, a network location is a read-only folder located in the %AppData%\Microsoft\Windows\Network Shortcuts folder, with two files inside: desktop.ini with a precise content (see in code) and a target.lnk shortcut to the target.

Option Explicit

Function CreateNetworkLocation( networkLocationName, networkLocationTarget )
    Const ssfNETHOOD  = &H13&
    Const fsATTRIBUTES_READONLY = 1
    Const fsATTRIBUTES_HIDDEN = 2
    Const fsATTRIBUTES_SYSTEM = 4

    CreateNetworkLocation = False 

    ' Instantiate needed components
    Dim fso, shell, shellApplication
        Set fso =               WScript.CreateObject("Scripting.FileSystemObject")
        Set shell =             WScript.CreateObject("WScript.Shell")
        Set shellApplication =  WScript.CreateObject("Shell.Application")

    ' Locate where NetworkLocations are stored
    Dim nethoodFolderPath, networkLocationFolder, networkLocationFolderPath
        nethoodFolderPath = shellApplication.Namespace( ssfNETHOOD ).Self.Path

    ' Create the folder for our NetworkLocation and set its attributes
        networkLocationFolderPath = fso.BuildPath( nethoodFolderPath, networkLocationName )
        If fso.FolderExists( networkLocationFolderPath ) Then 
            Exit Function 
        End If 
        Set networkLocationFolder = fso.CreateFolder( networkLocationFolderPath )
        networkLocationFolder.Attributes = fsATTRIBUTES_READONLY

    ' Write the desktop.ini inside our NetworkLocation folder and change its attributes    
    Dim desktopINIFilePath
        desktopINIFilePath = fso.BuildPath( networkLocationFolderPath, "desktop.ini" )
        With fso.CreateTextFile(desktopINIFilePath)
            .Write  "[.ShellClassInfo]" & vbCrlf & _ 
                    "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" & vbCrlf & _ 
                    "Flags=2" & vbCrlf
            .Close
        End With 
        With fso.GetFile( desktopINIFilePath )
            .Attributes = fsATTRIBUTES_HIDDEN + fsATTRIBUTES_SYSTEM
        End With 

    ' Create the shortcut to the target of our NetworkLocation
    Dim targetLink
        targetLink = fso.BuildPath( networkLocationFolderPath, "target.lnk" )
        With shell.CreateShortcut( targetLink )
            .TargetPath = networkLocationTarget
            .Save
        End With        

    ' Done
        CreateNetworkLocation = True 

End Function

CreateNetworkLocation "Tests", "\\192.168.1.2\c$"

在Windows 7中测试.

Tested in Windows 7.

原始答案-以防万一有人觉得有用.

Original answer - Just in case someone finds it useful.

您需要做的就是在文件夹中创建一个快捷方式:

All you need to do is to create a shortcut in the folder:

%AppData%\Microsoft\Windows\Network Shortcuts

只是一个VBScript示例(如问题所示,不确定标记是否指向其他需求):

Just a VBScript sample (as indicated in the question, not sure if the tags points to another needs):

Option Explicit

Const ssfNETHOOD  = &H13&

Dim fso, shell, shellApplication

    Set fso =               WScript.CreateObject("Scripting.FileSystemObject")
    Set shell =             WScript.CreateObject("WSCript.Shell")
    Set shellApplication =  WScript.CreateObject("Shell.Application")

Dim networkLocationsFolder
    networkLocationsFolder = shellApplication.Namespace( ssfNETHOOD ).Self.Path

    With shell.CreateShortcut(fso.BuildPath( networkLocationsFolder, "Test PC.lnk" ))
        .TargetPath = "\\192.168.1.10\c$"
        .WindowStyle = 1
        .IconLocation = "shell32.dll, 9"
        .Description = "Access to Test computer drive"
        .WorkingDirectory = "\\192.168.1.10\c$"
        .Save
    End With

这篇关于添加新的网络位置,而不是映射网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆