MapDrives.ps1的代码如下:
$i=3
while($True){
$error.clear()
$MappedDrives = Get-SmbMapping |where -property Status -Value Unavailable -EQ | select LocalPath,RemotePath
foreach( $MappedDrive in $MappedDrives)
{
try {
New-SmbMapping -LocalPath $MappedDrive.LocalPath -RemotePath $MappedDrive.RemotePath -Persistent $True
} catch {
Write-Host "Shared folder connection error: $MappedDrive.RemotePath to drive $MappedDrive.LocalPath"
}
}
$i = $i - 1
if($error.Count -eq 0 -Or $i -eq 0) {break}
Start-Sleep -Seconds 30
}
MapDrives.ps1的代码如下:
PowerShell -Command "Set-ExecutionPolicy -Scope CurrentUser Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
PowerShell -File "%SystemDrive%\Scripts\MapDrives.ps1" >> "%TEMP%\StartupLog.txt" 2>&1
4.2、单击选项卡“操作” - 单击“新建” - 选择“启动程序” - 单击“浏览” - 找到刚刚保存的文件 "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\MapDrives.cmd"
特别注意:开机后有可能会弹出黑框执行命令,一定不要手动关闭!!!