那么,如何使用或多或少的本机Windows工具和脚本来解决此问题?
我找到了一个解决方法,可以将SMB分享在Windows上,而不是默认端口1045。 首先,我在Windows上设置了WSL Ubuntu,并安装了CIFS-UTIL:
sudo apt install cifs-utils
然后我编写了以下脚本,该脚本在安装网络通过WSL上共享之后创建了一个快捷方式:
# PowerShell script to mount SMB share to WSL, then mount local SMB share to WSL using net use
# Variables
$wslDistro = "Ubuntu" # Change this to your WSL distro (e.g., Ubuntu, Debian)
$wslMountPoint = "/mnt/smb_share" # WSL mount point
$smbServerIP = "somedynamic.dns.army" # SMB server IP address (can be local or remote)
$smbShare = "NAS" # SMB share name
$wslUsername = "NAS" # WSL SMB username
$wslPassword = "strongpassword" # WSL SMB password
# Mount the SMB share inside WSL with the specified file and directory modes
Write-Host "Starting WSL session and mounting SMB share..."
Start-Job -ScriptBlock {
param(
$wslDistro,
$wslMountPoint,
$smbServerIP,
$smbShare,
$wslUsername,
$wslPassword
)
wsl.exe --user root -d $wslDistro -e bash -c "sudo mkdir -p $wslMountPoint; sudo ls -al $wslMountPoint; sudo umount $wslMountPoint; sudo mount -t cifs //$smbServerIP/$smbShare $wslMountPoint -o username='$wslUsername',password='$wslPassword',port=1045,file_mode=0777,dir_mode=0777; chmod 777 $wslMountPoint; while true; do sleep 3600; done"
} -ArgumentList $wslDistro, $wslMountPoint, $smbServerIP, $smbShare, $wslUsername, $wslPassword
sleep 4
# Mount the local SMB share in Windows using net use
Write-Host "Mapping local SMB share to Windows Shortcut..."
$shortcutPath = "$env:USERPROFILE\Desktop\NAS-Drive"
if (!(Test-Path $shortcutPath)) {
New-Item -ItemType SymbolicLink -Path "$shortcutPath" -Target "\\wsl$\Ubuntu$wslMountPoint"
}
Write-Host "SMB share mounted in WSL, and local SMB share linked to Windows at $shortcutPath"
我发现我的解决方案具有非常不稳定的连接,我写了一个小应用程序,可以解决这个问题:
Smbrowser1.0.zip