【问题标题】:VBScript add network placeVBScript 添加网络地址
【发布时间】:2019-12-16 22:48:34
【问题描述】:

我想使用 VBScript 创建一个网络位置。这些存储在:C:\Users\Danespe\AppData\Roaming\Microsoft\Windows\Network Shortcuts

当我使用以下代码时,我在该文件夹中获得了一个带有箭头图标的快捷方式,并且该快捷方式出现在该文件夹中。

    Set sys_sh = CreateObject("WScript.Shell")
    Set sys_ap = CreateObject("Shell.Application")
    strNetHood = sys_ap.Namespace(&H13&).Self.Path
    strShortcutName = "PaleoNAS"
    strShortcutPath = "\\Paleo-NAS\PM2"
    Set objShortcut = sys_sh.CreateShortcut(strNetHood & "\" & strShortcutName & ".lnk")
    objShortcut.TargetPath = strShortcutPath
    objShortcut.Save

当我手动添加网络位置时,我在同一个文件夹中获得了一个文件(不是快捷方式),而且还带有一个箭头图标,并且该文件出现在 Windows 资源管理器的左侧窗格中,位于我的电脑块。

我想实现第二个结果,文件也出现在资源管理器窗格中,但通过 VBScript,而不是手动。

【问题讨论】:

  • 将共享网络驱动器添加到您的计算机系统。 wsh.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword])?
  • 抱歉,没有得到任何结果。尝试了各种变体,我得到的只是各种错误消息。你能扩展一下这个答案吗?顺便说一句,我不想​​创建一个映射网络驱动器,用一个字母和冒号来访问它。我查看了命令,在我看来这就是它的目标。如果这是应该做的,那么谢谢你,但这不是我想要的。
  • 好吧,如果你映射一个驱动器,它会神奇地出现在你想要的地方。以下文件夹中的链接C:\Users\<User>\AppData\Roaming\Microsoft\Windows\Network Shortcuts\c$ (127.0.0.1)
  • 是的,我知道,但我想使用网络 PLACE,而不是网络驱动器。
  • 与您的回答类似,可能是this 可以帮助

标签: networking vbscript shortcut


【解决方案1】:

我在另一个论坛上发现了一些有用的东西。这就是诀窍。我不了解 target.lnk 文件的内部结构,但这可以满足我的需要。

Dim fs,Shell,DomainADSPath
Set Shell = WScript.CreateObject("WScript.Shell")
Set fs = Createobject("Scripting.FilesystemObject")

CreateNetworkLink "NewNetLink","\\Paleo-NAS\PM2","My Home directory"

Sub CreateNetworkLink(LinkName,LinkTargetPath,LinkDescription)
'> Get the path to the Network Neighborhood special folder.
Set NetHoodfolder = fs.getfolder(Shell.SpecialFolders("NetHood"))
Folder=NetHoodFolder &"\" &LinkName
If Fs.FolderExists(Folder)=False Then 
   Fs.CreateFolder(Folder)
   set LinkFolder=fs.getfolder(Folder)
   Linkfolder.attributes=1
End If
   CreateLink Folder,"target.lnk",LinkTargetPath,LinkDescription,"",""
   WriteFile Folder &"\Desktop.ini","[.ShellClassInfo]",2
   WriteFile Folder &"\Desktop.ini","CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}",8
   WriteFile Folder &"\Desktop.ini","Flags=2",8
   WriteFile Folder &"\Desktop.ini","ConfirmFileOp=0",8
End Sub

'>This Subroutine Creates the Shortcut Based on the parameters sent to it.
Sub CreateLink(LinkLocation,LinkName,LinkTargetPath,LinkDescription,LinkWorkingDirectory,LinkIconLocation)
    Set ShellLink = Shell.CreateShortcut(LinkLocation &"\" & LinkName)
    ShellLink.TargetPath = LinkTargetPath
    ShellLink.WindowStyle = 1
    ShellLink.Description = LinkDescription
    ShellLink.WorkingDirectory = LinkWorkingDirectory
    'shelllink.IconLocation = LinkIconLocation
    ShellLink.Save
End Sub

'> This function writes to a file
Function WriteFile(Filename,Text,AccessType)
   'Const ForWriting = 2, ForAppending=8 
   Dim fs, f
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set f = fs.OpenTextFile(FileName, AccessType, true)
   f.WriteLine Text
   f.Close
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2015-04-23
    • 2019-02-03
    • 2019-06-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多