With the GUI it isn't possible to add a local directory like C:\tmp.
Some time ago I wrote a powershell cmdlet to add a network location.
First of all I will tell you how the network location works. A network location is a directory in "C:\Users\user\AppData\Roaming\Microsoft\Windows\Network Shortcuts". The directory name is the same name as the network location.
In this directory is an ini-File stored with the following text
[.ShellClassInfo]
CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
Flags=2
ConfirmFileOp=1
CLSID
The CLSID is a globally unique identifier that identifies a COM class object.
Flags
I have no idea what it does. There are no differences when you set it to 0,1,2,3
ConfirmFIileOp
Is a boolean to avoid a “You Are Deleting a System Folder” warning when deleting or moving the folder.
In this directory is also a shortcut to the directory destination.
Lust but not least the directory attributes must be modified. The attributes must be set to hidden and readonly.
Thats the powershell cmdlet. You can save the text and dot source the ps1 file.
function Add-NetworkLocation
{
<#
.SYNOPSIS
Adds a networklocation
.DESCRIPTION
Adds a networklocation to the computer
.PARAMETER Name
Name for the networklocation, will be shown in the computer
.PARAMETER TargetPath
Targetpath to add the networklocation
.EXAMPLE
PS C:\> Add-NetworkLocation -Name test -TargetPath "C:\Tmp"
#>
[CmdletBinding()]
param(
[Parameter( Position=0, Mandatory=$true, ValueFromPipeline=$false, HelpMessage="Name to create the networklocation, for example: Test")]
[string]$Name,
[Parameter( Position=1, Mandatory=$true, ValueFromPipeline=$false, HelpMessage="TargetPath to create the networklocation, for example: \\myServer.example.com\example")]
[string]$TargetPath
)
# Get the basepath for network locations
$shellApplication = New-Object -ComObject Shell.Application
$nethoodPath = $shellApplication.Namespace(0x13).Self.Path
# Only create if the local path doesn't already exist & remote path exists
if ((Test-Path $nethoodPath) -and !(Test-Path "$nethoodPath\$name") -and (Test-Path $targetPath))
{
# Create the folder
$newLinkFolder = New-Item -Name $name -Path $nethoodPath -type directory
# Create the ini file
$desktopIniContent = @"
[.ShellClassInfo]
CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
Flags=2
ConfirmFileOp=1
"@
$desktopIniContent | Out-File -FilePath "$nethoodPath\$name\Desktop.ini"
# Create the shortcut file
$shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$nethoodPath\$name\target.lnk")
$shortcut.TargetPath = $targetPath
$shortcut.Description = $targetPath
$shortcut.WorkingDirectory = $targetPath
$shortcut.Save()
# Set attributes on the files & folders
Set-ItemProperty "$nethoodPath\$name\Desktop.ini" -Name Attributes -Value ([IO.FileAttributes]::System -bxor [IO.FileAttributes]::Hidden)
Set-ItemProperty "$nethoodPath\$name" -Name Attributes -Value ([IO.FileAttributes]::ReadOnly)
}
}
Then you can add your network location with this command
Add-NetworkLocation -Name Test -TartgetPath "C:\tmp"
Keine Kommentare:
Kommentar veröffentlichen