Freigeben über


BITS Compact Server & WMI provider

BITS Compact Server is a simple and secure HTTP / HTTPS server. BITS Compact Server exposes COM API for configuration. It can also be configured through a WMI provider.

Features:

1. HTTP / HTTPS file server, for ad-hoc file hosting. It is not intended to be an internet facing server.

2. Independent of IIS.

3. Supports SSL, Authentication (NTLM, Negotiate and client certificates) and Authorization (SDDL strings).

4. COM API for programmatic access.

5. WMI provider for configuring BITS Compact Server and managing BITS jobs remotely.

6. WMI Powershell cmdlets can be used for scripting.

Typically, BITS Compact Server would be used in deployment scenario which involves distribution of files to multiple machines. The lifetime of the hosted files would be short enough, so that setting up an IIS for hosting them is not required. The anticipated usage is the maximum of 25 URLGroups, each URLGroup supporting 3 simultaneous downloads. Hence, it is not intended to act as an internet facing server.

Installing BITS Compact Server

 

BITS Compact Server ships as an Optional Component in Windows Server 2008 R2. It can be installed via Server Manager or ocsetup.

a. Using Server Manager UI:

                                       i. Open server manager.

                                     ii. Add Feature.

                                    iii. Select “Compact Server” under Background Intelligent Transfer Service (BITS)

                                   iv. Follow the on screen installation steps.

b. Using Server Manager Powershell cmdlets

                                 i. Import-Module ServerManager

                               ii. Add-WindowsFeature BITS-Compact-Server

c. Using ocsetup:

                                       i. From an elevated command prompt, ocsetup LightweightServer

NOTE: The package name is case-sensitive.

BITS Compact Server basics

 

BITS Compact server is a simple and secure HTTP / HTTPS server. BITS Compact Server exposes COM API for configuration. It can also be configured through a WMI provider.

MSDN: https://msdn.microsoft.com/en-us/library/dd904465(VS.85).aspx

HTTP or HTTPS URLs are created, which point to specified files on the machine. A URL can be constructed as follows:

For example, consider the following URL:

https://localhost:8080/Sample/File.txt

The URL consists of 5 parts:

a. “http” – the protocol which is used. Can be http or https

b. “localhost” – refer https://msdn.microsoft.com/en-us/library/aa364698(VS.85).aspx.

c. “8080” – port on which the file will be accessible.

d. “Sample” – URL prefix.

e. “File.txt” – URL suffix.

“https://localhost:8080/Sample” – is referred to as the URLGroup.

BITS Compact server does not support multiple levels of URL prefixes; hence https://localhost:8080/Sample/Sample2/File.txt will not be a valid URLGroup or URL.

A single URLGroup can have multiple URLs associated with it.

For example:

The URLs “https://localhost:8080/Sample/File1.txt” and “https://localhost:8080/Sample/File2.txt” belong to the same URLGroup “https://localhost:8080/Sample/”

URLs in the same URLGroup share settings like, SSL certificates, Authentication, Connection and Bandwidth Limits etc.

BITS Compact Server and WMI

 

BITS Compact Server exposes configuration through WMI for remote management. The WMI provider resides in “root\Microsoft\BITS” namespace.

The WMI classes that are exposed are:

a. BITSCompactServerURLGroup – used for creating and managing URLGroups and URLs on BITS Compact Server. https://msdn.microsoft.com/en-us/library/dd904504(VS.85).aspx

b. BITSClientJob – BITS client side provider used for managing BITS jobs. https://msdn.microsoft.com/en-us/library/dd904502(VS.85).aspx

c. BITSClientFile – embedded object for getting information about file that is being transferred using the BITS client provider. https://msdn.microsoft.com/en-us/library/dd904501(VS.85).aspx

 

HelloWorld script

 

Host a file on BITS Compact Server and download it using WMI Powershell cmdlets

## Get BITS Compact Server WMI Class

$bcs = [wmiclass] "root\Microsoft\bits:Bitscompactserverurlgroup"

## Create URLGroup

$null = $bcs.CreateUrlGroup("https://+:80/Demo/")

## Get created URLGroups object

$urlgroup = Get-WmiObject -Namespace "root\Microsoft\bits" -Class "Bitscompactserverurlgroup" -Filter "urlgroup='https://+:80/Demo/'"

## Host a file. The file has to be present and accessible"

$null = $urlgroup.CreateUrl("100mb.zip","C:\100mb.zip","")

## Get BITS client WMI Class

$bits = [wmiclass] "root\microsoft\bits:bitsclientjob"

## Create BITS Job to download hosted file

$jobInfo = $bits.CreateJob("BlogDownload","https://localhost:80/Demo/100mb.zip","c:\100mb_downloaded.zip")

## Get created BITS job's object

$bitsJob = Get-WmiObject -Namespace "root\microsoft\bits" -Class "bitsclientjob" -Filter ("jobId='" + $jobInfo.JobId + "'")

## Poll for status

while ($bitsJob.State -ne 6)

{

                [UInt64] $progress = $bitsJob.BytesTransferred / $bitsJob.BytesTotal * 100

                Write-Progress -Activity "Downloading..." -status "$progress% Complete" -percentComplete $progress

                               

                ## Check for errors in transfer

                if(($bitsJob.State -eq 4) -or ($bitsJob.State -eq 5))

                {

                                Write-Host "Download ERROR: " $bitsJob.GetError(1033).ErrorDescription -ForegroundColor Red -BackgroundColor Black

                                exit

                }

               

                Sleep 3

                ## Refresh state

                $bitsJob.Get()

}

Write-Host "Downloaded Completed" -ForegroundColor Yellow

## Complete the BITS job to commit file to disk

$null = $bitsJob.setJobState(1)

 

NOTE:

§ Firewall ports are not opened when a URL Group is created for a particular port. https://technet.microsoft.com/en-us/library/cc772353(WS.10).aspx

§ Access to WMI provider needs administrative privileges.