1

Good Morning,
I have the following piece of code below that I've tweaked to map a few network drives. I'd like it to be tweaked (but I'm not sure how) so that it maps the network drives, creates a shortcut for each of them on the desktop, renames the shortcut appropriately, and then I guess at the first time they go to open them it'll ask for a password. If possible, if you could make it obvious where some of the changeable stuff is, like "desktop" name or something. I will learn from your input! thanks!

@net use M: \\10.0.0.120\Media Folder\Movies /persistent: yes

@echo Create new P: drive mapping 
@net use P: \\10.0.0.120\Media Folder\Pictures /persistent: yes

@echo Create new S: drive mapping 
@net use S: \\10.0.0.120\Criticals /persistent: yes

@echo Create new L: drive mapping 
@net use F: \\10.0.0.120\Finances & Banking /persistent: yes

@echo Create new N: drive mapping 
@net use N: \\10.0.0.120\Documents /persistent: yes

:Exit
@Pause

2 Answers2

1

If third-party-tools are ok, then I would suggest looking on NirCmd. It has a subcommand "shortcut" with several parameters like name, target directory, iconfile, etc. to setup a link file. Try this page https://www.nirsoft.net/utils/nircmd2.html and search for shortcut [ to jump to the right section(s). Download is here at the bottom of the page https://www.nirsoft.net/utils/nircmd.html

I am not sure if NirCmd can handle UNC Paths though (\\IP\Folder). In this case the mapped drive letters should be used as target for the shortcut file.

Antares
  • 111
0

this is a script / subroutine for creating shortcuts. simply change the paramters passed to the subroutine to change the shortcut properties. I believe I've made it sufficiently clear as to what does what within the below script.

@Echo off
::: [ The full path to the program your creating a shortcut for
    Set "ProgramPath=%~F0"
::: ]
::: [ The Name you want for your shortcut
    Set "ProgramName=%~n0"
::: ]
::: [ The full path to your Icon
    Set "IconLocation=%~dp0IconName.ico"
::: ]
::: [ The directory to create and run the powershell script from.
    Set "RunFrom=%TEMP%"
::: ]

::: [ Pass the properties to the subroutine to create the shortcut via powershell
    Call :CreateShortcut "%ProgramPath%" "%ProgramName%" "%IconLocation%" "%RunFrom%"
::: ]
    Exit /B

::: [ Use batch to create and run a powershell script that makes a .Ink file with the desired properties.
:CreateShortcut <Target Program Path> <Shortcut Name> <Icon Path> <Directory to create powershell file in>
    (
    ECHO # Create a Shortcut with Windows PowerShell
    ECHO $SourceFileLocation = "%~1"
    ECHO $ShortcutLocation = "$env:userprofile\Desktop\%~2.lnk"
    ECHO #New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
    ECHO #-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
    ECHO $WScriptShell = New-Object -ComObject WScript.Shell
    ECHO $Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation^)
    ECHO $Shortcut.TargetPath = $SourceFileLocation
    ECHO $Shortcut.IconLocation = "%~3"
    ECHO #Save the Shortcut to the TargetPath
    ECHO $Shortcut.Save(^)
    ) >"%~4\CreateShortcut.ps1"
::: - Execute powershell script to create Shortcut on User Desktop
    Powershell.exe -NoProfile -ExecutionPolicy Bypass -File %~4\CreateShortcut.ps1
Exit /B
::: ]
T3RR0R
  • 621