bitsadmin 示例bitsadmin examples

下面的示例演示如何使用 bitsadmin 工具执行最常见的任务。The following examples show how to use the bitsadmin tool to perform the most common tasks.

传输文件Transfer a file

若要创建作业,请添加文件,激活传输队列中的作业并完成该作业:To create a job, add files, activate the job in the transfer queue, and to complete the job:

bitsadmin /transfer myDownloadJob /download /priority normal https://downloadsrv/10mb.zip c:\\10mb.zip

在传输完成或发生错误之前,BITSAdmin 会继续在 MS-DOS 窗口中显示进度信息。BITSAdmin continues to show progress information in the MS-DOS window until the transfer completes or an error occurs.

创建下载作业Create a download job

若要创建名为 myDownloadJob 的下载作业:To create a download job named myDownloadJob:

bitsadmin /create myDownloadJob

BITSAdmin 返回一个用于唯一标识该作业的 GUID。BITSAdmin returns a GUID that uniquely identifies the job. 在后续调用中使用 GUID 或作业名称。Use the GUID or job name in subsequent calls. 以下文本是示例输出。The following text is sample output.

示例输出Sample output

created job {C775D194-090F-431F-B5FB-8334D00D1CB6}

将文件添加到下载作业Add files to the download job

若要将文件添加到作业:To add a file to the job:

bitsadmin /addfile myDownloadJob https://downloadsrv/10mb.zip c:\\10mb.zip

对要添加的每个文件重复此调用。Repeat this call for each file you want to add. 如果有多个作业使用 myDownloadJob 作为其名称,则必须使用作业的 GUID 来唯一地标识该作业才能完成。If multiple jobs use myDownloadJob as their name, you must use the job's GUID to uniquely identify it for completion.

激活下载作业Activate the download job

创建新作业后,BITS 会自动挂起该作业。After you create a new job, BITS automatically suspends the job. 激活传输队列中的作业:To activate the job in the transfer queue:

bitsadmin /resume myDownloadJob

如果有多个作业使用 myDownloadJob 作为其名称,则必须使用作业的 GUID 来唯一地标识该作业才能完成。If multiple jobs use myDownloadJob as their name, you must use the job's GUID to uniquely identify it for completion.

确定下载作业的进度Determine the progress of the download job

/Info 开关返回作业的状态以及传输的文件和字节数。The /info switch returns the state of the job and the number of files and bytes transferred. 当状态显示为时 TRANSFERRED ,表示 BITS 已成功传输作业中的所有文件。When the state is shown as TRANSFERRED, it means that BITS has successfully transferred all files in the job. 还可以添加 /verbose 参数以获取作业的完整详细信息,并添加 /list/monitor 以获取传输队列中的所有作业。You can also add the /verbose argument to get complete details of the job, and /list or /monitor to get all the jobs in the transfer queue.

返回作业的状态:To return the state of the job:

bitsadmin /info myDownloadJob /verbose

如果有多个作业使用 myDownloadJob 作为其名称,则必须使用作业的 GUID 来唯一地标识该作业才能完成。If multiple jobs use myDownloadJob as their name, you must use the job's GUID to uniquely identify it for completion.

完成下载作业Complete the download job

若要在状态更改为后完成作业 TRANSFERREDTo complete the job after the state changes to TRANSFERRED:

bitsadmin /complete myDownloadJob

必须先运行该 /complete 开关,然后才能使用该作业中的文件。You must run the /complete switch before the files in the job become available. 如果有多个作业使用 myDownloadJob 作为其名称,则必须使用作业的 GUID 来唯一地标识该作业才能完成。If multiple jobs use myDownloadJob as their name, you must use the job's GUID to uniquely identify it for completion.

使用/list 开关监视传输队列中的作业Monitor jobs in the transfer queue using the /list switch

返回作业状态以及传输队列中所有作业传输的文件数和字节数:To return the state of the job and the number of files and bytes transferred for all jobs in the transfer queue:

bitsadmin /list

示例输出Sample output

{6AF46E48-41D3-453F-B7AF-A694BBC823F7} job1 SUSPENDED 0 / 0 0 / 0
{482FCAF0-74BF-469B-8929-5CCD028C9499} job2 TRANSIENT_ERROR 0 / 1 0 / UNKNOWN

Listed 2 job(s).

使用/monitor 开关监视传输队列中的作业Monitor jobs in the transfer queue using the /monitor switch

若要返回作业的状态以及传输队列中所有作业传输的文件数和字节数,请每隔5秒刷新一次数据:To return the state of the job and the number of files and bytes transferred for all jobs in the transfer queue, refreshing the data every 5 seconds:

bitsadmin /monitor

备注

若要停止刷新,请按 CTRL + C。To stop the refresh, press CTRL+C.

示例输出Sample output

MONITORING BACKGROUND COPY MANAGER(5 second refresh)
{6AF46E48-41D3-453F-B7AF-A694BBC823F7} job1 SUSPENDED 0 / 0 0 / 0
{482FCAF0-74BF-469B-8929-5CCD028C9499} job2 TRANSIENT_ERROR 0 / 1 0 / UNKNOWN
{0B138008-304B-4264-B021-FD04455588FF} job3 TRANSFERRED 1 / 1 100379370 / 100379370

使用/info 开关监视传输队列中的作业Monitor jobs in the transfer queue using the /info switch

返回作业状态以及传输的文件数和字节数:To return the state of the job and the number of files and bytes transferred:

bitsadmin /info

示例输出Sample output

GUID: {482FCAF0-74BF-469B-8929-5CCD028C9499} DISPLAY: myDownloadJob
TYPE: DOWNLOAD STATE: TRANSIENT_ERROR OWNER: domain\user
PRIORITY: NORMAL FILES: 0 / 1 BYTES: 0 / UNKNOWN
CREATION TIME: 12/17/2002 1:21:17 PM MODIFICATION TIME: 12/17/2002 1:21:30 PM
COMPLETION TIME: UNKNOWN
NOTIFY INTERFACE: UNREGISTERED NOTIFICATION FLAGS: 3
RETRY DELAY: 600 NO PROGRESS TIMEOUT: 1209600 ERROR COUNT: 0
PROXY USAGE: PRECONFIG PROXY LIST: NULL PROXY BYPASS LIST: NULL
ERROR FILE:    https://downloadsrv/10mb.zip -> c:\10mb.zip
ERROR CODE:    0x80072ee7 - The server name or address could not be resolved
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being
processed.
DESCRIPTION:
JOB FILES:
0 / UNKNOWN WORKING https://downloadsrv/10mb.zip -> c:\10mb.zip
NOTIFICATION COMMAND LINE: none

从传输队列中删除作业Delete jobs from the transfer queue

若要从传输队列中删除所有作业,请使用/reset 开关:To remove all jobs from the transfer queue, use the /reset switch:

bitsadmin /reset

示例输出Sample output

{DC61A20C-44AB-4768-B175-8000D02545B9} canceled.
{BB6E91F3-6EDA-4BB4-9E01-5C5CBB5411F8} canceled.
2 out of 2 jobs canceled.

其他参考Additional References