我必须使用计划任务来完成。
创建一个包含映射文本的标准 bat 文件。
`
net use R: /Delete /y
net use R: "\\SERVERNAME\R" /persistent:yes
net use S: /Delete /y
net use S: "\\SERVERNAME\S" /persistent:yes
`
使用计划任务作业信息创建 XML
`
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2016-03-12T14:19:18.8527017</Date>
<Author>DOMAIN\USER</Author>
</RegistrationInfo>
<Triggers />
<Principals>
<Principal id="Author">
<GroupId>S-1-5-32-544</GroupId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>I:\Scripts\Schedualed Taks XML\Maps.bat</Command>
</Exec>
</Actions>
</Task>
`
使用批处理文件创建任务 (schtasks.exe)
`
@echo off
if exist "exists.txt" del "exists.txt"
for /F %%A in (SNL.txt) do (
Echo %%A
schtasks.exe /create /f /tn "Map Drives" /XML "I:\Scripts\Schedualed Taks XML\DriveMaps.xml" /s %%A
)
pause
`
注意: SNL.txt 是您希望在其上创建任务的计算机列表。
然后使用批处理文件运行任务(如果需要,您可以制作这个批处理文件)
`
@echo off
if exist "exists.txt" del "exists.txt"
for /F %%A in (SNL.txt) do (
Echo %%A
schtasks.exe /run /s %%A /tn "Map Drives"
)
Pause
`