Windows 驱动程序入门

驱动程序入门

从这里开始学习有关驱动程序的基本概念。

你应熟悉 C 编程语言,并且应了解函数指针、回调函数以及事件处理程序的理念。若要基于用户模式驱动程序框架 1.x 编写驱动程序,则应熟悉 C++ 和 COM。

什么是驱动程序?

 

为术语“驱动程序”给出单一的准确定义比较困难。就最基本的意义而言,驱动程序是一个软件组件,可让操作系统和设备彼此通信。例如,假设应用程序需要从设备中读取某些数据。应用程序会调用由操作系统实现的函数,操作系统会调用由驱动程序实现的函数。驱动程序(由设计和制造该设备的同一公司编写)了解如何与设备硬件通信以获取数据。当驱动程序从设备获取数据后,它会将数据返回到操作系统,操作系统将数据返回至应用程序。

图:显示应用程序、操作系统以及驱动程序

 

扩大定义

到目前为止,我们的说明采用以下几种方式进行简单化:

  • 并非所有驱动程序都必须由设计该设备的公司编写。在多种情形下,设备根据已发布的硬件标准来设计。这表示驱动程序可以由 Microsoft 编写,设备设计者无须提供驱动程序。
  • 并非所有驱动程序都直接与设备通信。对于给定的 I/O 请求(如从设备读取数据),通常有一些驱动程序(在堆栈中进行分层)参与该请求。可视化堆栈的传统方式是将第一个参与对象放在顶部,将最后一个参与对象放在底部,如此图所示。堆栈中的某些驱动程序可能通过将请求从一种格式转换至另一种格式来参与。这些驱动程序不会与设备直接通信;它们只操纵请求并将请求传递至堆栈下方的驱动程序。图:显示应用程序、操作系统、3 个驱动程序以及设备
  • 堆栈中直接与设备通信的一个驱动程序称为“函数驱动程序”;执行辅助处理的驱动程序称为“筛选器驱动程序”
  • 某些筛选器驱动程序遵守并记录有关 I/O 请求的信息,但不会主动参与这些请求。例如,某些筛选器驱动程序充当验证程序以确保堆栈中的其他驱动程序正确处理 I/O 请求。

我们可以扩大“驱动程序”的定义,方法是表示驱动程序为遵守或参与操作系统与设备之间通信的任一软件组件。

软件驱动程序

我们的扩大定义相当准确,但仍不完整,原因是某些驱动程序与任何硬件设备根本不关联。 例如,假设你需要编写可以访问核心操作系统数据结构的工具,这些结构仅可以由内核模式下运行的代码进行访问。可以通过将工具拆分成两个组件来执行该操作。第一个组件在用户模式下运行且提供用户界面。第二个组件在内核模式下运行且可以访问核心操作系统数据。在用户模式下运行的组件称为应用程序,在内核模式下运行的组件称为“软件驱动程序”。软件驱动程序与硬件设备不关联。有关处理器模式的详细信息,请参阅用户模式和内核模式

此图说明了与内核模式软件驱动程序通信的用户模式应用程序。

图:显示应用程序和软件驱动程序

其他说明

软件驱动程序始终在内核模式下运行。编写软件驱动程序的主要原因是获取对仅在内核模式下可用的受保护数据的访问权限。但是设备驱动程序不会始终需要访问内核模式数据和资源。因此某些设备驱动程序在用户模式下运行。

有一系列的驱动程序我们尚未提及,“总线驱动程序”。若要了解总线驱动程序,你需要了解设备节点和设备树。有关设备树、设备节点以及总线驱动程序的信息,请参阅设备节点和设备堆栈

到目前为止,我们的说明过度简化了“函数驱动程序”的定义。我们表示设备的函数驱动程序为堆栈中直接与设备通信的一个驱动程序。对于直接连接到外围组件互连 (PCI) 总线的设备而言,以上为真。PCI 设备的函数驱动程序获取映射到设备上端口和内存资源的地址。函数驱动程序通过写入这些地址直接与设备通信。但是在多种情形下,设备未直接连接到 PCI 总线。相反设备连接到的主机总线适配器连接到 PCI 总线。例如,USB toaster 连接到主机总线适配器(称为 USB 主控制器),该适配器连接到 PCI 总线。USB toaster 具有函数驱动程序,USB 主控制器也具有函数驱动程序。toaster 的函数驱动程序与 toaster 间接通信,方法是将请求发送至 USB 主控制器的函数驱动程序。然后,USB 主控制器的函数驱动程序与 USB 主控制器硬件直接通信,该硬件与 toaster 通信。

图:显示 USB toaster 驱动程序和 USB 主控制器驱动程序

 

选择驱动程序模型

Microsoft Windows 提供了多种驱动程序模型,你可以使用这些模型编写驱动程序。最佳驱动程序模型的选择策略取决于你计划编写的驱动程序类型。下文介绍了这些选项:

  • 设备函数驱动程序
  • 设备筛选器驱动程序
  • 软件驱动程序
  • 文件系统筛选器驱动程序
  • 文件系统驱动程序

有关各种类型驱动程序之间差异的介绍,请参阅什么是驱动程序?设备节点和设备堆栈。以下部分说明了如何为每种类型的驱动程序选择模型。

为设备函数驱动程序选择驱动程序模型

当你设计一个硬件设备时,首先要考虑的事项之一就是你是否需要编写函数驱动程序。提出下列问题:

是否可以完全避免编写驱动程序?
如果必须编写函数驱动程序,则最好使用哪个驱动程序模型?

若要回答这些问题,请确定设备的何处可以容纳设备和驱动程序技术中介绍的技术列表。参阅该特定技术的文档,以确定是否需要编写函数驱动程序以及了解哪些驱动程序模型可供设备使用。

某些个别技术具有微型驱动程序模型。在微型驱动程序模型中,设备驱动程序由两个部分组成:一个部分处理常规任务,另一部分处理设备特定的任务。通常,Microsoft 编写通用部分,设备制造商编写设备特定的部分。设备特定的部分具有多种名称,其中大部分名称都共享前缀“微型”。以下是微型驱动程序模型中使用的一些名称:

  • 显示器微型端口驱动程序
  • 音频微型端口驱动程序
  • 电池微型类驱动程序
  • 蓝牙协议驱动程序
  • HID 微型驱动程序
  • WIA 微型驱动程序
  • NDIS 微型端口驱动程序
  • 存储器微型端口驱动程序
  • 流微型驱动程序

有关微型驱动程序模型的概述,请参阅微型驱动程序和驱动程序对

并非设备和驱动程序技术中列出的每项技术都有专用的微型驱动程序模型。特定技术的文档可能会建议你使用内核模式驱动程序框架 (KMDF);其他技术的文档可能会建议你使用用户模式驱动程序框架 (UMDF)。关键点是你应从研究特定设备技术的文档开始。如果你的设备技术具有微型驱动程序模型,则必须使用微型驱动程序模型。否则就遵循技术特定的文档中有关是使用 UMDF、KMDF 还是 Windows 驱动程序模型 (WDM) 的建议。

为设备筛选器驱动程序选择驱动程序模型

一些驱动程序频繁参与单个 I/O 请求(如从设备读取数据)。驱动程序在堆栈中进行分层,并且可视化堆栈的常规方法是将第一个驱动程序放在顶部,将最后一个驱动程序放在底部。堆栈具有一个函数驱动程序并且还可以具有筛选器驱动程序。有关函数驱动程序和筛选器驱动程序的介绍,请参阅什么是驱动程序?设备节点和设备堆栈

如果你准备为设备编写筛选器驱动程序,则确定设备的何处可以容纳设备和驱动程序技术中介绍的技术列表。查看特定设备技术的文档是否有关于选择筛选器驱动程序模型的任何指南。如果设备技术的文档未提供此指南,则首先考虑使用 UMDF 作为驱动程序模型。如果筛选器驱动程序需要访问的数据结构无法通过 UMDF 获取,则考虑使用 KMDF 作为驱动程序模型。在极端少见的情形中,驱动程序需要访问的数据结构无法通过 KMDF 获取,则使用 WDM 作为驱动程序模型。

为软件驱动程序选择驱动程序模型

未与设备关联的驱动程序称为“软件驱动程序”。有关软件驱动程序的介绍,请参阅什么是驱动程序?主题。软件驱动程序很有用,原因是这些驱动程序可以在内核模式下运行,这样为其提供了受保护操作系统数据的访问权限。有关处理器模式的信息,请参阅用户模式和内核模式

有关软件驱动程序,你的两个选项为 KMDF 和旧的 Windows NT 驱动程序模型。使用 KMDF 和旧的 Windows NT 模型,你可以在编写驱动程序时无须考虑即插即用 (PnP) 和电源管理。你可以改为专心于驱动程序的首要任务上。使用 KMDF,你不必考虑 PnP 和电源,因为框架会为你处理 PnP 和电源。使用旧的 Windows NT 模型,你不必考虑 PnP 和电源,原因是旧的驱动程序在与 PnP 和电源管理完全无关的环境中运行。

我们的建议是使用 KMDF,尤其是当你已熟悉 KMDF 时。如果你希望驱动程序与 PnP 和电源管理完全无关,则使用旧的 Windows NT 模型。如果你需要编写注意到电源转换或 PnP 事件的软件,则不能使用旧的 Windows NT 模型;必须使用 KMDF。

Note  在极少情形中,你需要编写注意到 PnP 或电源事件的软件驱动程序,并且驱动程序需要访问无法通过 KMDF 获取的数据,则必须使用 WDM。

为文件系统筛选器驱动程序选择驱动程序模型

有关为文件系统筛选器驱动程序选择模型的帮助,请参阅“文件系统微过滤驱动程序”和文件系统筛选器驱动程序

为文件系统驱动程序选择驱动程序模型

有关为文件系统驱动程序选择模型的帮助,请参阅文件系统微过滤驱动程序。+

 

编写第一个驱动程序

提供了三个练习,指导你完成编写和构建小型驱动程序的整个过程。第一个练习基于用户模式驱动程序框架 (UMDF),其他两个练习基于内核模式驱动程序框架 (KMDF)。

尽管因为稳定性和可靠性的缘故 UMDF 为首选模型,但 KMDF 提供了一个有吸引力的机会,可以编写非常小的 Hello World 驱动程序。使用 KMDF,你可以编写非常简短的驱动程序,仅实现两个函数。

这些练习之间彼此独立,因此你可以采用任何顺序选择仅做其中一个练习或所有练习。 要点是获取一些有关驱动程序代码编写和构建的早期实例体验。

 

域名注册信息查询工具 Net Info Tools

发布我自用的一个域名注册信息查询工具。 功能主要集中在域名WHOIS方面。

A Tools for Domain/IP Whois, HTTP Scan, Route trace, root servers Monitoring, QQWry IPLocate. :)p
一个多功能的域名工具. 可以whois域名/IP, 扫描http头信息, 路由追踪, 服务器状态, 调用QQWry查询ip归属. (最新版本 几乎支持所有域名后缀的可注册状态查询, 需要服务端接口支持, 暂不公开发布

下载:(可下载使用的版本

域名 和 IP地址的 WHOIS信息查询

1

WHOIS域名,查询域名相关注册信息,还可转至映射(Referral)的域名管理商WHOIS服务器查询更详细的注册信息。

IP WHOIS 查询IP地址所在的NIC归属,以及AS地址编码等相关分配所有信息。

2

HTTP Scan

扫描获取相关IP地址的WEB服务器HTTP 头信息, 可查询一个C类地址段。

22

IP Info

目前有3个功能, 简单路由追踪,Root跟服务器状态监视,ipv4地址分配表。

33

QQWty

如同其名,调用 纯真网络?的QQWty.dat 查询IP归属地。QQWty可以从 “纯真网络?->?金狐软件 获取。

44

Tools

域名注册及查询相关工具。 包括WHOIS服务器验证,以及域名列表生产器,可以根据各种域名后缀TDL, 进行组合成。

55

.CN Delete

到期删除的.CN域名和中文域名列表,可以查询最近3天的域名删除列表。 支持按后缀类型,长度进行筛选过滤。

66

Bulk

域名注册可用状态的批量查询。 支持从文件选择打开。

可配合上面Tools中的域名组合生成器,方便进行批量可用域名的检测,也可对所需域名进行全后缀的检测,适合玩米的人士。目前几乎支持世界上全部域名后缀的查询。 (P.S. 此功能需要服务器接口支持。由于目前性能及缺少可用服务器,暂不对外开放使用。)

77

TLDs Server

根据 IANA?所使用的 ISO 3166-1 自动检测查询各个 通用顶级域名(gTLD)和 国家顶级域名(ccTLD)? 的WHOIS服务器和注册地址,方便玩米的朋友注册,了解各域名的注册机开放信息。

88

关于

下图显示的是目前开发的最新版本,非可下载使用版本。 (?下载:可下载使用的版本

0

个人使用工具,难免问题众多。有建议和问题欢迎回复及谈论。

在考虑后续增加的一些功能:域名价格列表,在线注册,抢注和会员账号等。。。

文件大小换算

1 Mio file = 1 mebioctet* = 220 octets = 1,024 Kio = 1,048,576 octets
10 Mio file = 10 mebioctet = 10 x 220 octets = 10,240 Kio = 10,485,760 octets
100 Mio file = 100 mebioctet = 100 x 220 octets = 102,400 Kio = 104,857,600 octets
1 Gio file = 1 gibioctet = 230 octets = 1,024 Mio = 1,073,741,824 octets
10 Gio file = 10 gibioctet = 10 x 230 octets = 10,240 Mio = 10,737,418,240 octets

1 Mbit file = 1 megabit = 106 bits = 1,000 kbit = 1,000,000 bits
10 Mbit file = 10 megabit = 107 bits = 10,000 kbit = 10,000,000 bits
100 Mbit file = 100 megabit = 108 bits = 100,000 kbit = 100,000,000 bits
1 Gbit file = 1 gigabit = 109 bits = 1,000 Mbit = 1,000,000,000 bits
10 Gbit file = 10 gigabit = 1010 bits = 10,000 Mbit = 10,000,000,000 bits

 

国际化域名IDN (Internationalized Domain Names) 转换

将域名国际化 IDN (internationalized domain name) 标准编码的域名标签的子字符串解码为一个 Unicode 字符串(Punycode). 或者将一个国际化域名字符串(Punycode )转换为符合 IDN 标准的域名
例:
Bücher.ch --> xn--bcher-kva.ch |
новини.com --> xn--b1amarcd.com |
统计局.中国 --> xn--dgtp91f7xi.xn--fiqs8s |
xn--j6w193g.xn--fiqs8s --> 香港.中国

代码段:

IDNA  >> Punycode

IdnMapping idn = new IdnMapping();
string international = idn.GetAscii(yourDomain, 0, yourDomain.Length);

Punycode  >> IDNA

>IdnMapping idn = new IdnMapping();
string nonInternational = idn.GetUnicode(yourDomain, 0, yourDomain.Length);

 

下载文件 : IDN Converter

 

DistroWatch上的中国Linux发行版

DistroWatch.com – Search Distributions – Country of origin  : CHINA

[ 受欢迎程度排名 截止至 2013-04-18 ]

The following distributions match your criteria (sorted by popularity):

1. Linux Deepin (受欢迎程度排名: 76)

deepin

Linux Deepin


Linux Deepin(最初叫做Hiweed GNU/Linux)是一份易于使用的基于Ubuntu的中文发行。其特性包括预配置好的中文应用软件及工具,例如中文输入法、LibreOffice办公套件、汉英和英汉字典、以及中文TrueType字体。它还供应一份高度定制的GNOME 3桌面和大量可用性方面的增强。

Linux Deepin (formerly Hiweed GNU/Linux) is an easy-to-use Chinese distribution based on Ubuntu. Its features include pre-configured Chinese applications and tools, such as Chinese input method, the LibreOffice office suite, Chinese-English and English-Chinese dictionaries, and Chinese TrueType fonts. It also delivers a highly customised GNOME 3 desktop and a large number of usability enhancements.

2. UbuntuKylin (受欢迎程度排名: 159)

ubuntukylin

UbuntuKylin


UbuntuKylin是Ubuntu正式的子项目,其宗旨是创建一份Ubuntu的变体,以更适合使用简体中文写作系统的华人用户。该项目提供精巧的、考虑周到的、完全定制的、开箱即用的中文用户体验,而这靠一份进行了简体中文本地化的桌面用户环境及广大中文用户喜爱的软件来提供。 UbuntuKylin is an official Ubuntu subproject whose goal is to create a variant of Ubuntu that is more suitable for Chinese users using the Simplified Chinese writing system. The project provides a delicate, thoughtful and fully customised Chinese user experience out-of-the-box by providing a desktop user interface localised into Simplified Chinese and with software generally preferred by many Chinese users.

3. StartOS (受欢迎程度排名: 182)

startos

StartOS


起点操作系统是一份独立的中文Linux发行,它采用了改造的GNOME桌面从而看起来很像Microsoft Windows XP。起先它基于Ubuntu,但从4.0版本开始它采用了自己的包管理工具(称为YPK)和安装程序,尽管其低层的自启动运行媒质依然是使用Ubuntu的Casper工具创建。

StartOS is an independent Chinese Linux distribution with the GNOME desktop tweaked to resemble Microsoft Windows XP. In the beginning it was based on Ubuntu, but starting from version 4.0 it adopted custom package management (called YPK) and system installer, though the underlying live medium is still built using Ubuntu’s Casper tool.

4. CDlinux (受欢迎程度排名: 215)

cdlinux

CDlinux


CDlinux是一份紧凑的Linux迷你发行。它包含了最新的Linux内核、X.Org、Xfce窗口管理器,以及很多流行应用程序。它的国际化/本地化程度很好,并且用户可配置性很高。     CDlinux is a compact Linux mini-distribution. It ships with an up-to-date version of the Linux kernel, X.Org, Xfce window manager, and many popular applications. It has good internationalisation and locale support, and is highly user-configurable.

5. Red Flag Linux (受欢迎程度排名: 247)

redflag

Red Flag Linux


红旗软件有限公司(简称红旗软件)由中国科学院软件研究所和上海联创投资管理有限公司共同组建。我们专注于基于Linux的操作系统的开发和市场,以及面向不断增长的中文技术用户的多平台应用软件。我们的目标是“为网络生活注入活力”。公司将持续发展我们称之为“红旗方式”的一套现代管理模式。这是客户驱动的用户化,它以我们进行自由软件开发的企业模式为基础。

Red Flag Software Co., Ltd. (Red Flag Software) was founded by Software Research Institute of the Chinese Academy of Sciences and NewMargin Venture Capital. We are focused on the development and marketing of Linux-based operating systems and application software on multiple platforms for the constantly growing base of Chinese technology users. Our goal is “Creating Incentives for Networking Life.” The company will continue to develop a modern management pattern we call the “Red Flag Way.” This is client driven customization based on our business model involving free software.

6. Qomo Linux (受欢迎程度排名: 292)

qomo

Qomo Linux


Qomo Linux是一份由Red Flag Linux开发的中文发行,它按社区项目来进行管理(其模式类似于Red Hat的Fedora, 或Novell的openSUSE)。其主要特色在于用户友好的桌面,极好的硬件检测,对简体中文的完整支持,以及为期六个月的发布周期。

Qomo Linux (formerly Everest Linux) is a Chinese distribution developed by Red Flag Linux and managed as a community project (in a fashion similar to Red Hat’s Fedora or Novell’s openSUSE). Its main features are user-friendly desktop, excellent hardware detection, full support for simplified Chinese, and a 6-month release cycle.

7. Asianux (受欢迎程度排名: 317)

asianux

Asianux


Asianux是一份由中国Linux供应商领头羊红旗软件公司和日本Linux供应商Miracle Linux公司联合开发的Linux服务器操作系统,其应用目标则是面向亚洲企业系统的通用性Linux平台。它为企业级客户提供了高可靠性、扩展性、易管理性及更好的软硬件兼容性。Asianux认证伙伴活动则邀请更多的软硬件产品加入到Asianux的认证中来,这无疑将有助于节省开发和认证所需的资源,并为Linux带来高质量和低成本。红旗软件和miracle将发布Asianux,Asianux在中国和日本市场上销售时,每一个Linux发行软件包都不作任何修改。新产品将基于Asianux,每一个都将与各国的本地化特性结合。

Asianux is a Linux server operating system which is co-developed by Chinese Leading Linux vendor Red Flag Software Co., Ltd. and Japanese Linux vendor Miracle Linux Cooperation, aiming at the common-standard enterprise Linux platform for Enterprise systems in Asia. It provides enterprise customers with high reliability, scalability, manageability and better hardware and software compatibility. Asianux certification partner program will invite more hardware and software products to be certified on Asianux, and it will definitely help to reduce developing and certificating resources and provide Linux with high quality and low cost. Red Flag Software and Miracle will distribute and market Asianux without any modifications in each Linux distribution package in China and Japan. New products will be based on Asianux and each will be bundled with localised features in each country.

在C#中调用 VB.Net 中的 IsSingleInstance 实现只运行单个实例的应用程序

<<Windows Forms 2.0 Programming, 2nd Edition>>   –  Single-Instance Applications 这一章中, 学到了调用 VB.Net 中的 IsSingleInstance, 为 C# WinForm 添加只运行应用程序的单个实例 ( Single Instance Application). 是个好方法!

该方法显然从易用性上便捷与 Mutex 和 Process 这两种只运行单个应用程序实例的方法.

 

Single Instance 概念:

从.NET 2.0起,提供了WindowsFormsApplicationBase类来简化Windows应用程序编程,如果您是开发人员会感到感到奇怪,WindowsFormsApplicationBase类不在System.Windows.Forms 命名空间中而是属于Microsoft.VisualBasic.ApplicationServices 命名空间,也许这是作为VB.NET开发人员的优先好处吧。该类对应的程序集为Microsoft.VisualBasic.dll,不过该程序集包含在.NET框架中一起发布,如果要引用该程序集,在部署上不存在额外操作。

WindowsFormsApplicationBase类实现了类似于Application类的一些功能,不过该类还包含一些简化Windows Forms应用程序开发的接口,下面来简单了解一下。WindowsFormsApplicationBase类实现了对单实例应用程序的支持,通过设置IsSingleInstance 属性为True以及重写OnStartupNextInstance方法可以简洁的实现。

 

实现

在 Program.cs – Main 方法

1. 项目中引用VB.Net 的DLL – Microsoft.VisualBasic.DLL,

Program.cs

using Microsoft.VisualBasic.ApplicationServices;

2. 在Program.cs中增加一个类

Program.cs

public sealed class SingleInstanceApplication : WindowsFormsApplicationBase
{
    public SingleInstanceApplication()
    {
        base.IsSingleInstance = true;
        base.ShutdownStyle = ShutdownMode.AfterMainFormCloses;
    }

    protected override void OnCreateMainForm()
    {
        base.MainForm = new MainForm();
    }

    protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)
    {
        base.OnStartupNextInstance(e);
        base.MainForm.Activate();
    }
}

 

3. 修改原 Application.Run(new MainForm()); 方法为:

//添加运行单进程程序
SingleInstanceApplication application = new SingleInstanceApplication();
application.Run(args);

 

SingleInstanceApplication类继承自WindowsFormsApplicationBase,在构造函数中设置为单实例模式,同时设置在主窗体关闭后退出应用程序。在继承类中,OnCreateMainForm方法被重写用来创建主窗体,如果要保证应用程序单一实例运行,还需要重写OnStartupNextInstance方法,在该应用程序的下一个应用程序实例启动时,OnStartupNextInstance方法会得到执行,在上面的实现代码中,调用基类方法同时激活主窗口。

 

IANA IPv4 地址空间注册表

IANA IPv4 Address Space Registry

Last Updated
2013-03-22
Description
The allocation of Internet Protocol version 4 (IPv4) address space to various registries is listed
here. Originally, all the IPv4 address spaces was managed directly by the IANA. Later parts of the
address space were allocated to various other registries to manage for particular purposes or
regional areas of the world. RFC 1466 [RFC1466] documents most of these allocations.

This registry is also available in plain text.

Prefix Designation Date Whois Status [1] Note
000/8 IANA – Local Identification 1981-09 RESERVED [2]
001/8 APNIC 2010-01 whois.apnic.net ALLOCATED
002/8 RIPE NCC 2009-09 whois.ripe.net ALLOCATED
003/8 General Electric Company 1994-05 LEGACY
004/8 Level 3 Communications, Inc. 1992-12 LEGACY
005/8 RIPE NCC 2010-11 whois.ripe.net ALLOCATED
006/8 Army Information Systems Center 1994-02 LEGACY
007/8 Administered by ARIN 1995-04 whois.arin.net LEGACY
008/8 Level 3 Communications, Inc. 1992-12 LEGACY
009/8 IBM 1992-08 LEGACY
010/8 IANA – Private Use 1995-06 RESERVED [3]
011/8 DoD Intel Information Systems 1993-05 LEGACY
012/8 AT&T Bell Laboratories 1995-06 LEGACY
013/8 Xerox Corporation 1991-09 LEGACY
014/8 APNIC 2010-04 whois.apnic.net ALLOCATED [4]
015/8 Hewlett-Packard Company 1994-07 LEGACY
016/8 Digital Equipment Corporation 1994-11 LEGACY
017/8 Apple Computer Inc. 1992-07 LEGACY
018/8 MIT 1994-01 LEGACY
019/8 Ford Motor Company 1995-05 LEGACY
020/8 Computer Sciences Corporation 1994-10 LEGACY
021/8 DDN-RVN 1991-07 LEGACY
022/8 Defense Information Systems Agency 1993-05 LEGACY
023/8 ARIN 2010-11 whois.arin.net ALLOCATED
024/8 ARIN 2001-05 whois.arin.net ALLOCATED
025/8 UK Ministry of Defence 1995-01 whois.ripe.net LEGACY
026/8 Defense Information Systems Agency 1995-05 LEGACY
027/8 APNIC 2010-01 whois.apnic.net ALLOCATED
028/8 DSI-North 1992-07 LEGACY
029/8 Defense Information Systems Agency 1991-07 LEGACY
030/8 Defense Information Systems Agency 1991-07 LEGACY
031/8 RIPE NCC 2010-05 whois.ripe.net ALLOCATED
032/8 AT&T Global Network Services 1994-06 LEGACY
033/8 DLA Systems Automation Center 1991-01 LEGACY
034/8 Halliburton Company 1993-03 LEGACY
035/8 Administered by ARIN 1994-04 whois.arin.net LEGACY
036/8 APNIC 2010-10 whois.apnic.net ALLOCATED
037/8 RIPE NCC 2010-11 whois.ripe.net ALLOCATED
038/8 PSINet, Inc. 1994-09 LEGACY
039/8 APNIC 2011-01 whois.apnic.net ALLOCATED
040/8 Administered by ARIN 1994-06 whois.arin.net LEGACY
041/8 AFRINIC 2005-04 whois.afrinic.net ALLOCATED
042/8 APNIC 2010-10 whois.apnic.net ALLOCATED
043/8 Administered by APNIC 1991-01 whois.apnic.net LEGACY
044/8 Amateur Radio Digital Communications 1992-07 LEGACY
045/8 Administered by ARIN 1995-01 whois.arin.net LEGACY
046/8 RIPE NCC 2009-09 whois.ripe.net ALLOCATED
047/8 Administered by ARIN 1991-01 whois.arin.net LEGACY
048/8 Prudential Securities Inc. 1995-05 LEGACY
049/8 APNIC 2010-08 whois.apnic.net ALLOCATED
050/8 ARIN 2010-02 whois.arin.net ALLOCATED
051/8 UK Government Department for Work and Pensions 1994-08 whois.ripe.net LEGACY
052/8 E.I. duPont de Nemours and Co., Inc. 1991-12 LEGACY
053/8 Cap Debis CCS 1993-10 LEGACY
054/8 Administered by ARIN 1992-03 whois.arin.net LEGACY
055/8 DoD Network Information Center 1995-04 LEGACY
056/8 US Postal Service 1994-06 LEGACY
057/8 SITA 1995-05 LEGACY
058/8 APNIC 2004-04 whois.apnic.net ALLOCATED
059/8 APNIC 2004-04 whois.apnic.net ALLOCATED
060/8 APNIC 2003-04 whois.apnic.net ALLOCATED
061/8 APNIC 1997-04 whois.apnic.net ALLOCATED
062/8 RIPE NCC 1997-04 whois.ripe.net ALLOCATED
063/8 ARIN 1997-04 whois.arin.net ALLOCATED
064/8 ARIN 1999-07 whois.arin.net ALLOCATED
065/8 ARIN 2000-07 whois.arin.net ALLOCATED
066/8 ARIN 2000-07 whois.arin.net ALLOCATED
067/8 ARIN 2001-05 whois.arin.net ALLOCATED
068/8 ARIN 2001-06 whois.arin.net ALLOCATED
069/8 ARIN 2002-08 whois.arin.net ALLOCATED
070/8 ARIN 2004-01 whois.arin.net ALLOCATED
071/8 ARIN 2004-08 whois.arin.net ALLOCATED
072/8 ARIN 2004-08 whois.arin.net ALLOCATED
073/8 ARIN 2005-03 whois.arin.net ALLOCATED
074/8 ARIN 2005-06 whois.arin.net ALLOCATED
075/8 ARIN 2005-06 whois.arin.net ALLOCATED
076/8 ARIN 2005-06 whois.arin.net ALLOCATED
077/8 RIPE NCC 2006-08 whois.ripe.net ALLOCATED
078/8 RIPE NCC 2006-08 whois.ripe.net ALLOCATED
079/8 RIPE NCC 2006-08 whois.ripe.net ALLOCATED
080/8 RIPE NCC 2001-04 whois.ripe.net ALLOCATED
081/8 RIPE NCC 2001-04 whois.ripe.net ALLOCATED
082/8 RIPE NCC 2002-11 whois.ripe.net ALLOCATED
083/8 RIPE NCC 2003-11 whois.ripe.net ALLOCATED
084/8 RIPE NCC 2003-11 whois.ripe.net ALLOCATED
085/8 RIPE NCC 2004-04 whois.ripe.net ALLOCATED
086/8 RIPE NCC 2004-04 whois.ripe.net ALLOCATED
087/8 RIPE NCC 2004-04 whois.ripe.net ALLOCATED
088/8 RIPE NCC 2004-04 whois.ripe.net ALLOCATED
089/8 RIPE NCC 2005-06 whois.ripe.net ALLOCATED
090/8 RIPE NCC 2005-06 whois.ripe.net ALLOCATED
091/8 RIPE NCC 2005-06 whois.ripe.net ALLOCATED
092/8 RIPE NCC 2007-03 whois.ripe.net ALLOCATED
093/8 RIPE NCC 2007-03 whois.ripe.net ALLOCATED
094/8 RIPE NCC 2007-07 whois.ripe.net ALLOCATED
095/8 RIPE NCC 2007-07 whois.ripe.net ALLOCATED
096/8 ARIN 2006-10 whois.arin.net ALLOCATED
097/8 ARIN 2006-10 whois.arin.net ALLOCATED
098/8 ARIN 2006-10 whois.arin.net ALLOCATED
099/8 ARIN 2006-10 whois.arin.net ALLOCATED
100/8 ARIN 2010-11 whois.arin.net ALLOCATED [5]
101/8 APNIC 2010-08 whois.apnic.net ALLOCATED
102/8 AFRINIC 2011-02 whois.afrinic.net ALLOCATED
103/8 APNIC 2011-02 whois.apnic.net ALLOCATED
104/8 ARIN 2011-02 whois.arin.net ALLOCATED
105/8 AFRINIC 2010-11 whois.afrinic.net ALLOCATED
106/8 APNIC 2011-01 whois.apnic.net ALLOCATED
107/8 ARIN 2010-02 whois.arin.net ALLOCATED
108/8 ARIN 2008-12 whois.arin.net ALLOCATED
109/8 RIPE NCC 2009-01 whois.ripe.net ALLOCATED
110/8 APNIC 2008-11 whois.apnic.net ALLOCATED
111/8 APNIC 2008-11 whois.apnic.net ALLOCATED
112/8 APNIC 2008-05 whois.apnic.net ALLOCATED
113/8 APNIC 2008-05 whois.apnic.net ALLOCATED
114/8 APNIC 2007-10 whois.apnic.net ALLOCATED
115/8 APNIC 2007-10 whois.apnic.net ALLOCATED
116/8 APNIC 2007-01 whois.apnic.net ALLOCATED
117/8 APNIC 2007-01 whois.apnic.net ALLOCATED
118/8 APNIC 2007-01 whois.apnic.net ALLOCATED
119/8 APNIC 2007-01 whois.apnic.net ALLOCATED
120/8 APNIC 2007-01 whois.apnic.net ALLOCATED
121/8 APNIC 2006-01 whois.apnic.net ALLOCATED
122/8 APNIC 2006-01 whois.apnic.net ALLOCATED
123/8 APNIC 2006-01 whois.apnic.net ALLOCATED
124/8 APNIC 2005-01 whois.apnic.net ALLOCATED
125/8 APNIC 2005-01 whois.apnic.net ALLOCATED
126/8 APNIC 2005-01 whois.apnic.net ALLOCATED
127/8 IANA – Loopback 1981-09 RESERVED [6]
128/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
129/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
130/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
131/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
132/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
133/8 Administered by APNIC 1997-03 whois.apnic.net LEGACY
134/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
135/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
136/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
137/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
138/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
139/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
140/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
141/8 Administered by RIPE NCC 1993-05 whois.ripe.net LEGACY
142/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
143/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
144/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
145/8 Administered by RIPE NCC 1993-05 whois.ripe.net LEGACY
146/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
147/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
148/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
149/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
150/8 Administered by APNIC 1993-05 whois.apnic.net LEGACY
151/8 Administered by RIPE NCC 1993-05 whois.ripe.net LEGACY
152/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
153/8 Administered by APNIC 1993-05 whois.apnic.net LEGACY
154/8 Administered by AFRINIC 1993-05 whois.afrinic.net LEGACY
155/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
156/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
157/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
158/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
159/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
160/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
161/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
162/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
163/8 Administered by APNIC 1993-05 whois.apnic.net LEGACY
164/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
165/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
166/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
167/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
168/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
169/8 Administered by ARIN 1993-05 whois.arin.net LEGACY [7]
170/8 Administered by ARIN 1993-05 whois.arin.net LEGACY
171/8 Administered by APNIC 1993-05 whois.apnic.net LEGACY
172/8 Administered by ARIN 1993-05 whois.arin.net LEGACY [8]
173/8 ARIN 2008-02 whois.arin.net ALLOCATED
174/8 ARIN 2008-02 whois.arin.net ALLOCATED
175/8 APNIC 2009-08 whois.apnic.net ALLOCATED
176/8 RIPE NCC 2010-05 whois.ripe.net ALLOCATED
177/8 LACNIC 2010-06 whois.lacnic.net ALLOCATED
178/8 RIPE NCC 2009-01 whois.ripe.net ALLOCATED
179/8 LACNIC 2011-02 whois.lacnic.net ALLOCATED
180/8 APNIC 2009-04 whois.apnic.net ALLOCATED
181/8 LACNIC 2010-06 whois.lacnic.net ALLOCATED
182/8 APNIC 2009-08 whois.apnic.net ALLOCATED
183/8 APNIC 2009-04 whois.apnic.net ALLOCATED
184/8 ARIN 2008-12 whois.arin.net ALLOCATED
185/8 RIPE NCC 2011-02 whois.ripe.net ALLOCATED
186/8 LACNIC 2007-09 whois.lacnic.net ALLOCATED
187/8 LACNIC 2007-09 whois.lacnic.net ALLOCATED
188/8 Administered by RIPE NCC 1993-05 whois.ripe.net LEGACY
189/8 LACNIC 1995-06 whois.lacnic.net ALLOCATED
190/8 LACNIC 1995-06 whois.lacnic.net ALLOCATED
191/8 Administered by LACNIC 1993-05 whois.lacnic.net LEGACY
192/8 Administered by ARIN 1993-05 whois.arin.net LEGACY [9][10]
193/8 RIPE NCC 1993-05 whois.ripe.net ALLOCATED
194/8 RIPE NCC 1993-05 whois.ripe.net ALLOCATED
195/8 RIPE NCC 1993-05 whois.ripe.net ALLOCATED
196/8 Administered by AFRINIC 1993-05 whois.afrinic.net LEGACY
197/8 AFRINIC 2008-10 whois.afrinic.net ALLOCATED
198/8 Administered by ARIN 1993-05 whois.arin.net LEGACY [11]
199/8 ARIN 1993-05 whois.arin.net ALLOCATED
200/8 LACNIC 2002-11 whois.lacnic.net ALLOCATED
201/8 LACNIC 2003-04 whois.lacnic.net ALLOCATED
202/8 APNIC 1993-05 whois.apnic.net ALLOCATED
203/8 APNIC 1993-05 whois.apnic.net ALLOCATED [12]
204/8 ARIN 1994-03 whois.arin.net ALLOCATED
205/8 ARIN 1994-03 whois.arin.net ALLOCATED
206/8 ARIN 1995-04 whois.arin.net ALLOCATED
207/8 ARIN 1995-11 whois.arin.net ALLOCATED
208/8 ARIN 1996-04 whois.arin.net ALLOCATED
209/8 ARIN 1996-06 whois.arin.net ALLOCATED
210/8 APNIC 1996-06 whois.apnic.net ALLOCATED
211/8 APNIC 1996-06 whois.apnic.net ALLOCATED
212/8 RIPE NCC 1997-10 whois.ripe.net ALLOCATED
213/8 RIPE NCC 1993-10 whois.ripe.net ALLOCATED
214/8 US-DOD 1998-03 LEGACY
215/8 US-DOD 1998-03 LEGACY
216/8 ARIN 1998-04 whois.arin.net ALLOCATED
217/8 RIPE NCC 2000-06 whois.ripe.net ALLOCATED
218/8 APNIC 2000-12 whois.apnic.net ALLOCATED
219/8 APNIC 2001-09 whois.apnic.net ALLOCATED
220/8 APNIC 2001-12 whois.apnic.net ALLOCATED
221/8 APNIC 2002-07 whois.apnic.net ALLOCATED
222/8 APNIC 2003-02 whois.apnic.net ALLOCATED
223/8 APNIC 2010-04 whois.apnic.net ALLOCATED
224/8 Multicast 1981-09 RESERVED [13]
225/8 Multicast 1981-09 RESERVED [13]
226/8 Multicast 1981-09 RESERVED [13]
227/8 Multicast 1981-09 RESERVED [13]
228/8 Multicast 1981-09 RESERVED [13]
229/8 Multicast 1981-09 RESERVED [13]
230/8 Multicast 1981-09 RESERVED [13]
231/8 Multicast 1981-09 RESERVED [13]
232/8 Multicast 1981-09 RESERVED [13]
233/8 Multicast 1981-09 RESERVED [13]
234/8 Multicast 1981-09 RESERVED [13][14]
235/8 Multicast 1981-09 RESERVED [13]
236/8 Multicast 1981-09 RESERVED [13]
237/8 Multicast 1981-09 RESERVED [13]
238/8 Multicast 1981-09 RESERVED [13]
239/8 Multicast 1981-09 RESERVED [13][15]
240/8 Future use 1981-09 RESERVED [16]
241/8 Future use 1981-09 RESERVED [16]
242/8 Future use 1981-09 RESERVED [16]
243/8 Future use 1981-09 RESERVED [16]
244/8 Future use 1981-09 RESERVED [16]
245/8 Future use 1981-09 RESERVED [16]
246/8 Future use 1981-09 RESERVED [16]
247/8 Future use 1981-09 RESERVED [16]
248/8 Future use 1981-09 RESERVED [16]
249/8 Future use 1981-09 RESERVED [16]
250/8 Future use 1981-09 RESERVED [16]
251/8 Future use 1981-09 RESERVED [16]
252/8 Future use 1981-09 RESERVED [16]
253/8 Future use 1981-09 RESERVED [16]
254/8 Future use 1981-09 RESERVED [16]
255/8 Future use 1981-09 RESERVED [16][17]

Footnotes

[1]
Indicates the status of address blocks as follows:
RESERVED: designated by the IETF for specific non-global-unicast purposes as noted.
LEGACY: allocated by the central Internet Registry (IR) prior to the Regional Internet Registries
(RIRs). This address space is now administered by individual RIRs as noted, including maintenance
of WHOIS Directory and reverse DNS records. Assignments from these blocks are distributed globally
on a regional basis.
ALLOCATED: delegated entirely to specific RIR as indicated.
UNALLOCATED: not yet allocated or reserved.
[2]
0.0.0.0/8 reserved for self-identification [RFC1122], section 3.2.1.3. 
Reserved by protocol. For authoritative registration, see [IANA registry iana-ipv4-special-registry].
[3]
Reserved for Private-Use Networks [RFC1918].
Complete registration details for 10.0.0.0/8 are found in [IANA registry iana-ipv4-special-registry].
[4]
This was reserved for Public Data Networks [RFC1356]. See [IANA registry public-data-network-numbers].
It was recovered in February 2008 and was subsequently allocated to APNIC in April 2010.
[5]
100.64.0.0/10 reserved for Shared Address Space [RFC6598]. 
Complete registration details for 100.64.0.0/10 are found in [IANA registry iana-ipv4-special-registry].
[6]
127.0.0.0/8 reserved for Loopback [RFC1122], section 3.2.1.3. 
Reserved by protocol. For authoritative registration, see [IANA registry iana-ipv4-special-registry].
[7]
169.254.0.0/16 reserved for Link Local [RFC3927].
Reserved by protocol. For authoritative registration, see [IANA registry iana-ipv4-special-registry].
[8]
172.16.0.0/12 reserved for Private-Use Networks [RFC1918]. 
Complete registration details are found in [IANA registry iana-ipv4-special-registry].
[9]
192.0.2.0/24  reserved for TEST-NET-1 [RFC5737]. 
Complete registration details for 192.0.2.0/24 are found in [IANA registry iana-ipv4-special-registry].
192.88.99.0/24 reserved for 6to4 Relay Anycast [RFC3068]
Complete registration details for 192.88.99.0/24 are found in [IANA registry iana-ipv4-special-registry].
192.88.99.2/32 reserved for 6a44 Relay Anycast [RFC6751] (possibly collocated with 6to4 Relay 
at 192.88.99.1/32 - see [RFC3068] section 2.4)
192.168.0.0/16 reserved for Private-Use Networks [RFC1918]. 
Complete registration details for 192.168.0.0/16 are found in [IANA registry iana-ipv4-special-registry].
[10]
192.0.0.0/24 reserved for IANA IPv4 Special Purpose Address Registry [RFC5736]. 
Complete registration details for 192.0.0.0/24 are found in [IANA registry iana-ipv4-special-registry].
[11]
198.18.0.0/15 reserved for Network Interconnect Device Benchmark Testing [RFC2544]. 
Complete registration details for 198.18.0.0/15 are found in [IANA registry iana-ipv4-special-registry].
198.51.100.0/24 reserved for TEST-NET-2 [RFC5737]. 
Complete registration details for 198.51.100.0/24 are found in [IANA registry iana-ipv4-special-registry].
[12]
203.0.113.0/24 reserved for TEST-NET-3 [RFC5737]. 
Complete registration details for 203.0.113.0/24 are found in [IANA registry iana-ipv4-special-registry].
[13]
Multicast (formerly "Class D") [RFC5771] registered in [IANA registry multicast-addresses]
[14]
Unicast-Prefix-Based IPv4 Multicast Addresses [RFC6034]
[15]
Administratively Scoped IP Multicast [RFC2365]
[16]
Reserved for future use (formerly "Class E") [RFC1112].
Reserved by protocol. For authoritative registration, see [IANA registry iana-ipv4-special-registry].
[17]
255.255.255.255 is reserved for "limited broadcast" destination address [RFC919] and [RFC922].
Complete registration details for 255.255.255.255/32 are found in [IANA registry iana-ipv4-special-registry].

相关资源:

 

IANA IPv4 专用地址注册表

IANA IPv4 Special-Purpose Address Registry

Created
2009-08-19

Last Updated
2013-03-03

This registry is also available in plain text.

Registry included below

* IANA IPv4 Special Purpose Address Registry

IANA IPv4 Special Purpose Address Registry

Registration Procedure(s)

IETF Review

Reference
[RFC5736][RFC-bonica-special-purpose-07]

Note

The IETF has reserved the address block of 192.0.0.0/24 for use for
special purposes relating to protocol assignments. This registry
contains the current assignments made by the IETF from this address
block.

Address prefixes listed in the Special Purpose Address Registry are
not guaranteed routability in any particular local or global context.

Address   Block Name RFC Allocation Date
0.0.0.0/8 “This” Network [RFC1122], section 3.2.1.3 1981-09
10.0.0.0/8 Private-Use [RFC1918] 1996-02
100.64.0.0/10 Shared   Address Space [RFC6598] 2012-04
127.0.0.0/8 Loopback [RFC1122], section 3.2.1.3 1981-09
169.254.0.0/16 Link   Local [RFC3927] 2005-05
172.16.0.0/12 Private-Use [RFC1918] 1996-02
192.0.0.0/24[2] IETF Protocol Assignments [RFC-bonica-special-purpose-07],   section 2.1 2010-01
192.0.0.0/29 DS-Lite [RFC6333] 2011-06
192.0.2.0/24 Documentation   (TEST-NET-1) [RFC5737] 2010-01
192.88.99.0/24 6to4   Relay Anycast [RFC3068] 2001-06
192.168.0.0/16 Private-Use [RFC1918] 1996-02
198.18.0.0/15 Benchmarking [RFC2544] 1999-03
198.51.100.0/24 Documentation   (TEST-NET-2) [RFC5737] 2010-01
203.0.113.0/24 Documentation   (TEST-NET-3) [RFC5737] 2010-01
240.0.0.0/4 Reserved [RFC1112], section 4 1989-08
255.255.255.255/32 Limited   Broadcast [RFC919], section 7 1984-10

Footnotes

[1] Several protocols have been granted exceptions to this rule.  For
examples, see [RFC4379] and [RFC5884].
[2] Not useable unless by virtue of a more specific reservation.

windows 环境变量

Getting and setting environment variables

The variables can be used both in scripts and on the command line. They are usually referenced by putting special symbols in front of or around the variable name. For instance, to display the user home directory, in most scripting environments, the user has to type:

echo $HOME

On DOS, OS/2 or Windows systems, the user has to type this:

echo %HOME%

In Windows PowerShell, the user has to type this:

Write-Output $HOME

DOS, OS/2 and Windows (Command Prompt)

In DOS, OS/2 and Windows, the set command without any arguments displays all environment variables along with their values.

To set a variable to a particular value, use:

set VARIABLE=value

However, this is temporary. Permanent change to the environment variable can be achieved through editing the registry (not recommended for novices) and using the Windows Resource Kit application setx.exe. With the introduction of Windows Vista, the setx command became part of Windows.

Users of the Windows GUI can manipulate variables via <Control Panel:System:Advanced:Environment Variables>; through the Windows Registry this is done changing the values under HKCU\Environment (for user specific variables) and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (for System variables).

To set a variable whose name is in another variable:

set %VARNAME%=value

This feature allows certain interesting applications. For example, a uni-dimensional array of elements (vector) may be generated this way:

set VECTOR[%I%]=value of element subscript %I%

:MkVec
set VECNAME=%1
set i=0
:loop
    shift
    if "%1" == "" goto exitloop
    set /a i+=1
    set %VECNAME%[%i%]=%1
    goto loop
:exitloop
exit /B %i%

call :MkVec DOWNAME=Monday Tuesday Wednesday Thursday Friday Saturday Sunday

To see the current value of a particular variable, use:

echo %VARIABLE%

or

set VARIABLE

Note: Please take note that doing so will print out all variables beginning with ‘VARIABLE’. Another example is:

C:\> set p
Path=c:\.. ..
PATHEXT=.COM;.EXE;.BAT;
PROCESSOR_ARCHITECTURE=.. ..
PROCESSOR_IDENTIFIER=x8..
PROCESSOR_LEVEL=6..
PROCESSOR_REVISION=1706..
ProgramFiles=C:\Program.. .
PROMPT=$P$G

To see the value of an array element a double expansion is required: one for the subscript value and an additional expansion for the array element. This may be achieved via Delayed !VARIABLE! Expansion this way:

set DOW=value of Day of Week (1..7)
echo !DOWNAME[%DOW%]!

To delete a variable, the following command is used:

set VARIABLE=

Windows PowerShell

To set a system variable:

Set-Content -Path Env:VARIABLE -value value
$Env:VARIABLE = value # alternate form

Examples of DOS environment variables

%COMSPEC%

This variable contains the full path to the command processor, command.com.

%PATH%

This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the Unix $PATH variable (although note that PATH on Windows additionally performs the same task as LD_LIBRARY_PATH on Unix-like systems). Note that %PATH% can also be set like this PATH=c:\dos; where SET isn’t required.

%TEMP% and %TMP%

These variables contain the path to the directory where temporary files should be stored.

Examples from Microsoft Windows

Discrete value variables

These variables generally expand to discrete values, such as the current working directory, the current date, or a random number. Some of these are true environment variables and will be expanded by all functions that handle environment variables. Others, like %CD% simply look like environment variables and will only be expanded by some functions and shells. They are not case sensitive.

%CD%

This variable points to the current directory. Equivalent to the output of the command cd when called without arguments.

%DATE%

This variable expands to the current date. The date is displayed according to the current user’s date format preferences.

The following is a way of reformatting the date and time for use in file copies. The example assumes UK format of day month year and the time is set for a 24 hour clock.

@echo off
echo %DATE% %TIME%
for /F "tokens=1-3 delims=/" %%a in ("%DATE%") do set MTH=%%a& set DAY=%%b& set YR=%%c
for /F "tokens=1-3 delims=:." %%a in ("%TIME%") do set HR=%%a& set MIN=%%b& set SEC=%%c
if "%HR:~0,1%"==" " set HR=0%HR:~1,1%
set MYDATE=%YR%%MTH%%DAY%-%HR%%MIN%%SEC%
echo %MYDATE%
%ERRORLEVEL%

This variable points to the current error level. If there was an error in the previous command, it is checked against this.

%RANDOM%

This variable returns a random number between 0 and 32767.

%TIME%

This variable points to the current time. The time is displayed according to the current user’s time format preferences.

System path variables

These variables refer to locations of critical operating system resources, and as such generally are not user-dependent.

%AppData%

Contains the full path to the Application Data directory of the logged-in user. Does not work on Windows NT 4.0 SP6 UK.

%LOCALAPPDATA%

This variable is the temporary files of Applications. Its uses include storing of Desktop Themes, Windows Error Reporting, Caching and profiles of web browsers.

%ComSpec%

This variable contains the full path to the command processor; on Windows NT based operating systems this is cmd.exe, while on Windows 9x and ME it is the DOS command processor, COMMAND.COM.

%PATH%

This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Equivalent to the Unix $PATH variable.

%ProgramFiles%

This variable points to Program Files directory, which stores all the installed program of Windows and others. The default on English-language systems is C:\Program Files. In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which defaults to C:\Program Files (x86) and %ProgramW6432% which defaults to C:\Program Files. The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).

%CommonProgramFiles%

This variable points to Common Files directory. The default is C:\Program Files\Common Files.

%SystemDrive%

The %SystemDrive% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the drive upon which the system directory was placed. Also see next item.

The value of %SystemDrive% is in most cases C:.

%SystemRoot%

The %SystemRoot% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the system directory, including the drive and path.

The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default, on a clean installation:

  • Windows NT 5.1 (Windows XP) and newer versions use \WINDOWS
  • Windows NT 5.0 (Windows 2000), Windows NT 4.0 and Windows NT 3.1 use \WINNT
  • Windows NT 3.5x uses \WINNT35
  • Windows NT 4.0 Terminal Server use \WTSRV
%WinDir%

This variable points to the Windows directory (on Windows NT-based operating systems it is identical to the %SystemRoot% variable, above). If the System is on drive C: then the default values are:

Note that Windows NT 4 Terminal Server Edition by default installs to C:\WTSRV.

User management variables

These variables store information related to resources and settings owned by various user profiles within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.

%AllUsersProfile% (%PROGRAMDATA% for Windows Vista, Windows 7)

The %AllUsersProfile%(%PROGRAMDATA%) variable expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut links copied to the All Users’ Start menu or Desktop directories will appear in every user’s Start menu or Desktop, respectively.

%UserDomain%

The variable holds the name of the Workgroup or Windows Domain to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname of the server that authenticated the current user’s logon credentials (name and password). For Home PCs, and PCs in a Workgroup, the authenticating server is usually the PC itself. For PCs in a Windows Domain, the authenticating server is a domain controller (a primary domain controller, or PDC, in Windows NT 4-based domains).

%UserProfile%

The %UserProfile% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the current user’s profile directory, in which is found that user’s HKCU registry hive (NTUSER).

Users can also use the %USERNAME% variable to determine the active users login identification.

Windows GUI forced variable expansion

In certain cases it is not possible to create file paths containing environment variables using the Windows GUI, and it is necessary to fight with the user interface to make things work as intended.

  • In Windows 7, a shortcut may not contain the variable %USERNAME% in unexpanded form. Trying to create shortcut to \\server\share\accounts\%USERNAME% or C:\users\%USERNAME% will be silently changed to replace %USERNAME% with the account name of the currently logged-in user, when the OK button is pressed on the shortcut properties.
    • This can only be overridden if the %USERNAME% variable is part of a parameter to some other program in the shortcut. For example, %SYSTEMROOT%\Explorer.exe C:\Users\%USERNAME% is not expanded when OK is clicked, but this shortcut is treated as unsafe and displays a warning when opened.
  • In Group Policy Management on Server 2008 R2, a profile directory can not be redirected to a custom directory hierarchy. For example, the desktop can not be redirected to \\server\share\accounts\%USERNAME%\custom\path\desktop. Upon pressing OK, this is silently changed to “Create a directory for each user in the root path” with the path \\server\share\accounts\ pointing to “\username\desktop”.
    • This behavior can only be overridden if the path contains a variable or drive letter that is not currently resolvable at the time of editing the GPO. For example if a mapping for drive Z: does not exist on the server, then the path Z:\directory\%username%\CustomTarget is not expanded when OK is selected.
  • A domain user account may not contain a profile path or home directory path containing an unexpanded %USERNAME% variable. Upon clicking OK, this is silently replaced with the user’s account name.
    • This causes problems for new user creation that is performed by copying an existing user account, if there are additional directories listed after the username in the path. For a pre-existing account with a profile path of \server\share\accounts\DomainUser\profile the Microsoft Management Console doesn’t know which part of the path contains the previous user’s name and doesn’t change the path during the copy, resulting in the new account pointing to the other account’s profile/home paths. The profile/home paths must be manually re-edited to point to the correct location.

Default Values on Microsoft Windows

Variable Windows XP Windows Vista/7
 %ALLUSERSPROFILE% C:\Documents and Settings\All Users C:\ProgramData
 %APPDATA% C:\Documents and Settings\{username}\Application Data C:\Users\{username}\AppData\Roaming
 %COMPUTERNAME% {computername} {computername}
 %COMMONPROGRAMFILES% C:\Program Files\Common Files C:\Program Files\Common Files
 %COMMONPROGRAMFILES(x86)% C:\Program Files (x86)\Common Files (only in 64-bit version) C:\Program Files (x86)\Common Files (only in 64-bit version)
 %COMSPEC% C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe
 %HOMEDRIVE% C: C:
 %HOMEPATH% \Documents and Settings\{username} \Users\{username}
 %LOCALAPPDATA% C:\Users\{username}\AppData\Local
 %LOGONSERVER% \\{domain_logon_server} \\{domain_logon_server}
 %PATH% C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
 %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
 %PROGRAMDATA%  %SystemDrive%\ProgramData
 %PROGRAMFILES%  %SystemDrive%\Program Files  %SystemDrive%\Program Files
 %PROGRAMFILES(X86)%  %SystemDrive%\Program Files (x86) (only in 64-bit version)  %SystemDrive%\Program Files (x86) (only in 64-bit version)
 %PROMPT% Code for current command prompt format. Code is usually $P$G Code for current command prompt format. Code is usually $P$G
 %PSModulePath%  %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
 %PUBLIC%  %SystemDrive%\Users\Public
{Drive}:\$Recycle.Bin C:\Recycle.Bin C:\$Recycle.Bin
 %SystemDrive% C: C:
 %SystemRoot% The Windows directory, usually C:\Windows, formerly C:\WINNT  %SystemDrive%\Windows
 %TEMP% and %TMP%  %SystemDrive%\Documents and Settings\{username}\Local Settings\Temp  %SystemDrive%\Users\{username}\AppData\Local\Temp
 %USERDOMAIN% {userdomain} {userdomain}
 %USERNAME% {username} {username}
 %USERPROFILE%  %SystemDrive%\Documents and Settings\{username}  %SystemDrive%\Users\{username}
 %WINDIR%  %SystemDrive%\Windows  %SystemDrive%\Windows

In this list, there is no environment variable that refers to the location of the user’s My Documents directory, so there is no standard method for setting a program’s home directory to be the My Documents directory.