How to Edit INF File?

本文详细介绍INF文件的概念、结构和运行机制,包括如何利用INF文件进行文件操作和服务安装,并提供了多个实用示例。
1.Introduction
INF文件全称Information File文件,是Winodws操作系统下用来描述设备或文件等数据信息的文件。INF文件是纯文本文件,由标准的ASCII码组成。一般我们总是认为INF文件是系统设备的驱动程序,其实这是错误的认识,Windows之所以在安装某些硬件的驱动时提示需要INF文件是因为INF文件为该设备提供了一个全面描述硬件参数和相应驱动文件(DLL文件)的信息。就好比我们看着说明书安装电脑硬件一样,我们就是Windows系统,说明书就是INF文件。INF文件功能非常强大,几乎能完成日常操作的所有功能。您可以把它看成是Windows系统底下的超强批初理。


2.Features of INF

1 复制文件、删除文件、或重新命名文件。
2 新增或删除注册表(Registry)中的项目。
3 修改重要的系统设置文件(如 Autoexec.bat、Config.sys、.INI 等)


3.Rules of INF

  *规则一:INF文件是分节的,每一个INF文件有许多的节组成,节名用方括号"[]"括起来。这些节名有些是系统定义好的,有一些是用户自定义的。每一个节名最长为255个字符(Windows 2000/XP/2003操作系统中)或28个字符(Windows 98操作系统中)。节与节之间没有先后顺序的区别,另外,同一个INF文件中如果出现两个同样的节名,则系统会自动将这两个节名下面的条目合并到一起。

  *规则二:在节与节之间的内容叫条目,每一个节又是由许多的条目组成的,每一个条目都是由=分开,形如“signature="$CHICAGO$"”的形式组成的。如果每一个条目的等号后有多个值,则每一个值之间用“,”号分隔开。

  *规则三:INF文件对大小写不敏感。

  *规则四:“;”号后面的内容为注释。

  *规则五:如果一个条目的内容过多,在一行无法书写完全,则用“\”将一行内容书写为多行。


4.INF的运行

 
.INF文件是由Windows的SetupAPI解释执行的脚本文件,它的运行过程很简单,是一种线性的执行,线性的意思就是.INF文件的运行过程不存在分支语句,也就是没有条件语句,一旦开始执行,就是沿着固定的路线运行。它的运行是按照节为单位来执行的,从某一个[Install]节开始执行,从上到下执行该节中的条目,如果该条目是一个节,那么就一条条执行子节中的条目,如此递归执行。在WINDOW上运行只要右击这个文件,点击安装即可。

5.Version of INF
.INF文件的语法是统一的分节语法,随着操作系统的更新,微软逐渐增加了一些必要的关键字,但是整个的.INF文件的结构不会变化。从语法上来说,.INF文件都是一个类别。
按照.INF文件的版本来分类,可以分为2类:
1 AdvancedINF,在[Version]节中有“AdvancedINF=2.5,"您需要新版本的 AdvPack.dll" ”这么一行语句,表明此.INF文件需要AdvPack.dll这个动态链接库来解释执行,AdvancedINF有一些高级特性,但是在目前用的不太多。
2 普通INF,没有指明需要AdvPack.dll的.INF文件,使用SetupAPI.DLL来解释执行(win9x系列的操作系统使用Setupx.dll),系统中缺省使用的就是这种普通INF。


2.Structure
INF文件的组成有节(Sections),键(Key)和值(value)三部分。 
关键节有 
[Version]版本描述信息,主要用于版本控制。 
[Strings]字符串信息,用于常量定义。 
[DestinationDirs]定义系统路径信息。 
[SourceDisksNames]指明源盘信息。 
[SourceDisksNames]指明源盘文件名。 
[DefaultInstall]开始执行安装。 
其它的节可以自定义,下面用一实例来具体讲解。

程序代码 
[Version] 
Signature
=$Chicago$ 
Provider
=%Author% 

[Strings] 
Product
="添加文件关联演示" 
Version
="1.0" 
Author
="Xunchi" 
Copyright
="Copyright 2005" 
CustomFile
="inf" ;修改您需要的文件名后缀 
Program="NOTEPAD.EXE" ;修改您需要关联的应用程序名 

[Add.Reg] 
HKCR
,"."%CustomFile%,"",FLG_ADDREG_TYPE_SZ ,%CustomFile%File 
HKCR
,%CustomFile%File,"",FLG_ADDREG_TYPE_SZ,安装信息 
HKCR
,%CustomFile%"File\shell","",FLG_ADDREG_TYPE_SZ,open 
HKCR
,%CustomFile%"File\shell\open\command","",FLG_ADDREG_TYPE_SZ,%program% %1 

[DefaultInstall] 
AddReg
=Add.Reg 

  在
[Version]节中"Signature"项定义了该INF文件需要运行在何种操作系统版本中。有$Windows NT$, $Chicago$, or $Windows 95$三个值供选择,一般选择$Chicago$即可。项Provider中定义了该文件的创作来源,%Author%指引用Author项的值。您也可自定其它项来描述该INF文件的版本信息。该INF文件的作用是关联文件,所以主要是对注册表的操作,我们来看[Add.Reg]节,共四条语句,格式都是一样。HKCR表示根HKEY_CLASSES_ROOT,第二个参数是子键的路径名,第三个参数是表明值的类型,最后是值(具体见附表)。以上都是对操作的定义与过程,在节[DefaultInstall]中是开始执行要安装的流程,AddReg表明是对注册表进行操作,操作对象是Add.Reg节中的定义。如果您把AddReg换成DelReg则是删除注册表中的键值。当鼠标单击该INF文件在弹出的菜单中选择“安装”就开始执行您所定义的操作。该示例在系统的INF文件右键菜单中增加了查看编辑功能并设置了默认动作,因为在安装了不了解的INF文件有可能对系统产生不良的影响,这样双击文件就可打开编辑该文件了。 


再看看INF文件在文件操作方面的能力吧。请看下面的一个例子。 

程序代码 
[Version] 
Signature
=$Chicago$ 
Provider
=%Author% 
[Strings] 
Product
="文件复制和安装演示" 
Version
="1.0" 
Author
="Xunchi" 
Copyright
="Copyright 2005" 

[FileList] 
ProcessList.exe 
;此文件已在当前目录下,下同。 

[FileList1] 
Wordpad.exe 
[DestinationDirs] 
FileList
=11 ;安装到Windows的系统目录 
FileList1=10 ;安装到Windows目录 
[DefaultInstall] 
Copyfiles
=FileList,FileList1 

  相同的节的作用与上一例类似,请注意新出现的节
[FileList],这是我自定义的节名,它表示了一个文件组,[FileList1]也类似。在节[DestinationDirs]中需定义每个文件组复制到的目录(各个常量的意义见附表)。Copyfiles指明了需要进行复制的文件组。 
  INF文件的操作还包括服务(NT系统)程序的安装和卸载,INI文件的转换等。由于这些操作都比较的复杂和繁琐,且有一定的危险性故下次有机会再向大家进行深入探讨。 
  最后我们来看一下INF文件的执行机制,这时你也许要问不就是简单的执行一下“安装”吗?知其然不知其所以然知识水平是不会提高的。在“文件夹选项”中的“文件类型”找到INF文件的“安装”命令看到一串命令。“rundll32.exe setupapi
,InstallHinfSection DefaultInst_all 132 %1”它表示了运行Dll文件setupapi.dll中的命令InstallHinfSection并传递给它起始节的名字 DefaultInstall。可见起始节是可以自定义的。INF文件的执行也可用在各种支持API调用的编程工具中。至此INF文件的结构和运行机制我们已基本了解,现在就让你的思维开动起来,让它更好的为我们工作吧。 


注册表操作的常量定义: 
---------------------------------------------------------- 
常量 根值 
HKCR HKEY_CLASSES_ROOT. 
HKCU HKEY_CURRENT_USER. 
HKLM HKEY_LOCAL_MACHINE. 
HKU HKEY_USERS. 
----------------------------------------------------------- 
FLG_ADDREG_APPEND 在多字符串后添加字符 
FLG_ADDREG_TYPE_SZ 字符类型 
FLG_ADDREG_TYPE_MULTI_SZ 字符串类型 
FLG_ADDREG_TYPE_EXPAND_SZ 扩展字符串类型 
FLG_ADDREG_TYPE_BINARY 二进制值 
FLG_ADDREG_TYPE_DWORD DWord值 
FLG_ADDREG_TYPE_NONE NULL值 
---------------------------------------------------------- 


[DestinationDirs]节中所定义的常量路径 
---------------------------------------------------------- 
01 源目录(后跟路径) 
10 Windows目录 
11 Windows系统目录 
12 驱动目录 
17 INF文件目录 
18 帮助文件目录 
20 字体目录 
21 根目录 
24 应用程序目录 
25 共享目录 
30 当前根目录 
50 System目录 
51 Spool 目录 
52 Spool 驱动目录 
53 用户配置目录 
---------------------------------------------------------- 

[DefaultInstall]节中定义的操作 
---------------------------------------------------------- 
LogConfig Log日志文件配置 
Copyfiles 复制文件 
Renfiles 文件改名 
Delfiles 删除文件 
UpdateInis 更新Inis 
UpdateIniFields 更新Ini字段 
AddReg 添加注册项 
DelReg 删除注册项 
Ini2Reg Ini文件转换为Reg文件 
----------------------------------------------------------- 


INF文件应用示例
一、修改telnet服务,端口改为99,NTLM认证方式为1。 
=============================== 
 

C:\myinf\Telnet.inf 

[Version] 
Signature
="$WINDOWS NT$" 
[DefaultInstall] 
AddReg
=AddRegName 
[My_AddReg_Name] 
HKLM
,SOFTWARE\Microsoft\TelnetServer\1.0,TelnetPort,0x00010001,99 
HKLM
,SOFTWARE\Microsoft\TelnetServer\1.0,NTLM,0x00010001,1 

安装:rundll32.exe setupapi
,InstallHinfSection DefaultInstall 128 c:\myinf\telnet.inf 

说明:
[Version][DefaultInstall]是必须的,0x00010001表示REG_DWORD数据类型,0x00000000或省略该项(保留逗号)表示REG_SZ(字符串)。0x00020000表示REG_EXPAND_SZ。 
InstallHinfSection是大小写敏感的。它和setupapi之间只有一个逗号,没有空格。128表示给定路径,该参数其他取值及含义参见MSDN。 
特别注意,最后一个参数,必须是inf文件的全路径,不要用相对路径。 
inf文件中的项目都是大小写不敏感的。 

二、服务 
=============== 

增加一个服务: 

[Version] 
Signature
="$WINDOWS NT$" 
[DefaultInstall.Services] 
AddService
=inetsvr,,My_AddService_Name 
[My_AddService_Name] 
DisplayName
=Windows Internet Service 
Description
=提供对 Internet 信息服务管理的支持。 
ServiceType
=0x10 
StartType
=2 
ErrorControl
=0 
ServiceBinary
=%11%\inetsvr.exe 

保存为inetsvr.inf,然后: 

rundll32.exe setupapi
,InstallHinfSection DefaultInstall 128 c:\path\inetsvr.inf 

这个例子增加一个名为inetsvr的服务(是不是很像系统自带的服务,呵呵)。 

几点说明: 
1,最后四项分别是 
服务类型:0x10为独立进程服务,0x20为共享进程服务(比如svchost); 
启动类型:
0 系统引导时加载,1 OS初始化时加载,2 由SCM(服务控制管理器)自动启动,3 手动启动,4 禁用。 
(注意,0和1只能用于驱动程序) 
错误控制:
0 忽略,1 继续并警告,2 切换到LastKnownGood的设置,3 蓝屏。 
服务程序位置:%
11%表示system32目录,%10%表示系统目录(WINNT或Windows),%12%为驱动目录system32\drivers。其他取值参见DDK。你也可以不用变量,直接使用全路径。 
这四项是必须要有的。 
2,除例子中的六个项目,还有LoadOrderGroup、Dependencies等。不常用所以不介绍了。 
3,inetsvr后面有两个逗号,因为中间省略了一个不常用的参数flags。 

删除一个服务: 

[Version] 
Signature
="$WINDOWS NT$" 
[DefaultInstall.Services] 
DelService
=inetsvr 

很简单,不是吗? 

当然,你也可以通过导入注册表达到目的。但inf自有其优势。 
1,导出一个系统自带服务的注册表项,你会发现其执行路径是这样的: 
"ImagePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,
74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,74,
00,6c,00,6e,00,74,00,73,00,76,00,72,00,2e,00,65,00,78,00,65,00,00,00 
可读性太差。其实它就是%SystemRoot%\system32\tlntsvr.exe,但数据类型是REG_EXPAND_SZ。当手动导入注册表以增加服务时,这样定义ImagePath显然很不方便。如果用REG_SZ代替会有些问题——不能用环境变量了。即只能使用完整路径。用inf文件完全没有这个问题,ServiceBinary(即ImagePath)自动成为REG_EXPAND_SZ。 
2,最关键的是,和用SC等工具一样,inf文件的效果是即时起效的,而导入reg后必须重启才有效。 
3,inf文件会自动为服务的注册表项添加一个Security子键,使它看起来更像系统自带的服务。 

另外,AddService和DelService以及AddReg、DelReg可以同时且重复使用。即可以同时增加和删除多个服务和注册表项。 

三、组策略 
========== 

1、密码最小6位 
[version] 
signature
="$CHICAGO$" 
[System Access] 
MinimumPasswordLength 
= 6 
PasswordComplexity 
= 1 

保存为gp.inf,然后导入: 
secedit /configure /db gp.sdb /cfg gp.inf /quiet 


2、关闭所有的“审核策略 

echo 
[version] >1.inf 
echo signature
="$CHICAGO$" >>1.inf 
echo 
[Event Audit] >>1.inf 
echo AuditSystemEvents
=0 >>1.inf 
echo AuditObjectAccess
=0 >>1.inf 
echo AuditPrivilegeUse
=0 >>1.inf 
echo AuditPolicyChange
=0 >>1.inf 
echo AuditAccountManage
=0 >>1.inf 
echo AuditProcessTracking
=0 >>1.inf 
echo AuditDSAccess
=0 >>1.inf 
echo AuditAccountLogon
=0 >>1.inf 
echo AuditLogonEvents
=0 >>1.inf 
secedit /configure /db 
1.sdb /cfg 1.inf /log 1.log /quiet 
del 
1.* 


四、解决XP ipc$连接只有Guest权限 
==================== 

echo 
[version] >1.inf 
echo signature
="$CHICAGO$" >>1.inf 
echo 
[Registry Values] >>1.inf 
echo MACHINE\System\CurrentControlSet\Control\Lsa\ForceGuest
=4,0 >>1.inf 
secedit /configure /db 
1.sdb /cfg 1.inf /log 1.log 
del 
1.*


节的名称

节的作用

[Version]

INF文件头,提供有效INF文件的版本信息

[DefaultInstall]

安装包含所关联动作(文件拷贝或删除,注册表键值更新、子键增删等)在INF文件内的节名指针,默认情况下首先执行该节内容

[OtherInstall]

与[DefaultInstall]节遵循相同的语法,但必须显式的调用,常被用来定义反安装动作

[DestinationDirs]

指定罗列于一个节内将被拷贝、删除或重命名的文件在硬盘上的位置

[FileCopy/Delete/RenameSection(s)]

罗列将被拷贝、删除或重命名的文件

[RegistryUpdateSection(s)]

指定对注册表键值更新、子键增删等动作

[IniFileUpdateSection(s)]

指定对ini文件的更新、快捷方式可通过该节进行创建

[SourceDisksNames]

罗列文件所在盘盘名、盘卷标、盘序列号

[SourceDisksFiles]

罗列安装时使用的源文件及其所在盘

[Strings]

罗列本地化字符串(或称宏字符串)


表中黑体节名是保留关键字,名称固定,大小写不敏感,斜体节名名称任意,由INF文件编写者确定。每节的标题字符均用括号([])括起。 限于篇幅本文只对黑体节名做进一步的解释。

[Version]节

任何INF文件的第一个小节均是[Version],又称为INF文件头。一般有如下语句:

[Version]
Signature=“$Chicago$”
LayoutFile=filename.inf

其中,Signature的值应为“$Chicago$”、“$Windows 95$”或“$Windows NT$”中的一个(不区分大小写),否则Windows不接受该文件为INF文件,内建的动作也就不会起作用。

filename.inf文件包含安装组件必需的安装布局信息(源盘和源文件),该行是可选的,如果没有提供布局信息文件,则在INF文件内必须包含[SourceDisksNames]和[SourceDisksFiles]节。

[Install]节

[Install]节提供了一个INF文件安装过程的总览,它识别文件内其他包含安装信息节的详细动作,是Windows内建安装函数识别安装过程和内容的真正入口,用户所有的安装目的在这里表现。那些与[Install]节内容不存在关联的节的动作将被忽略。

[Install]节分[DefaultInstall]和[OtherInstall]两类,它们使用相同的格式。[DefaultInstall]节节名“DefaultInstall”如前面表格内容所述被显式地在注册表中指定,大小写不敏感。该节也是系统获取INF文件中安装信息的首要入口,当用户右击INF文件选“安装”时该节内容被执行。[OtherInstall]与[DefaultInstall]节遵循相同的语法,但必须被显式地调用,常被用来定义反安装动作。它们均可包括以下种类的可选入口:

CopyFiles=[CopyFiles-section-name]file-list-section[,file-list-section]
RenFiles=file-list-section[,file-list-section]
DelFiles=file-list-section[,file-list-section]
UpdateInis=update-ini-section[,update-ini-section]
UpdateIniFields=update-inifields-section[,update-inifields-section]
AddReg=add-registry-section[,add-registry-section]
DelReg=del-registry-section[,del-registry-section]
Ini2Reg=ini-to-registry-section[,ini-to-registry-section]
UpdateCfgSys=update-config-section
UpdateAutoBat=update-autoexec-section

上面的入口并非都必需,如果需要一个入口,则应该在等号右侧指出存在于该INF文件内的索引节名(不用指出节名的一个特例是CopyFiles入口,可使用“@”字符后跟文件名的形式,效果是直接将文件拷贝到DestinationDirs节所罗列的硬盘目录)。节名需由可打印字符组成,在中文系统平台中,可使用中文字符作为节名,这也是体现INF格式安装本地化的地方,非常直观。每类入口在一个[Install]节内只能出现一次,第二次及以后出现的同名重复入口将被忽略。每类入口的等号右侧可罗列多个节名,节名之间以逗号分开,以便列举同一类动作的不同作用对象,如删除多个注册表键、拷贝文件到多个目录路径等。

下表是各类入口的动作含义,具体语法本文不做细述:
 

CopyFiles

等号右侧是拷贝文件罗列节节名,将文件拷贝到DestinationDirs节指定的目的地,所有的源文件必须在SourceDisksFiles节列出

RenFiles

重命名文件

DelFiles

删除文件

UpdateInis

安装过程中更新INI初始化文件内容

UpdateIniField

安装过程中更新INI初始化文件值内容

AddReg

增加注册表键或键值

DelReg

删除注册表键或键值

Ini2Reg

用INI文件内容更新注册表

UpdateCfgSys

更新Config.sys文件内的设置

UpdateAutoBat

更新Autoexec.bat文件内的设置


在实际编写INF文件时,注册表根键通常采用缩写方式,如下表:

HKCR

HKEY_CLASSES_ROOT的简写

HKCU

HKEY_CURRENT_USER的简写

HKLM

HKEY_LOCAL_MACHINE的简写

HKU

HKEY_USERS的简写

HKR

相对键,对于硬件设备驱动程序类安装的

 

[DestinationDirs]节

[DestinationDirs]节指定拷贝、重命名或删除文件三类动作的目的目录路径,拷贝、重命名或删除操作对象即文件的列表在专门的节中列出,这些节名最初在“Install”的CopyFiles、RenFiles或DelFiles入口中明确。
[DestinationDirs]节内语句的语法为:
file-list-section=LDID,[Subdir]
[DefaultDestDir=LDID,[Subdir]]
其中file-list-section为必选项,是CopyFiles、RenFiles或DelFiles入口内列出的节名。
LDID(Logical disk identifier)为必选项,是逻辑盘标识码,代表各种系统或实时安装路径,逻辑盘标识码可看做一种宏字符串,随系统或实时安装路径的不同而相应改变。逻辑盘标识码机制确保了安装的灵活性和正确性,该标识码可为下表所述值之一:
Subdir为可选项,指定LDID目录下的子目录名。
DefaultDestDir为可选项,指定CopyFiles、RenFiles或DelFiles入口的缺省操作目录。

[SourceDisksNames]节

[SourceDisksNames]节罗列源文件所在盘符序列码、盘描述符、盘卷标号和盘序列号。
[SourceDisksNames]节内语句的语法为:
disk-ordinal=“disk-description”,disk-label,disk-serial-number
其中disk-ordinal为必选项,是盘符序列码,标识一个源盘,具有惟一性,一般可设置为从1开始递增的整数,0不是一个有效的盘符序列码。当存在多个源盘时,盘符序列码之间不能重复。
disk-description为必选项,是盘描述符,用双引号括起的字符串或字符串宏描述盘的内容或目的。安装引擎将该字符串显示在对话框内以提示用户。
disk-label为源盘的卷标识。
disk-serial-number未使用,但必须被设置为0。

[SourceDisksFiles]节

[SourceDisksFiles]节指定安装时使用的源文件和盘符序列码、盘描述符。 [SourceDisksFiles]节内语句的语法为:
file-name=disk-number[,subdir] [,file-size]
其中file-name为必选项,是源盘上文件的名称。
disk-number是包含file-name指定文件所在源盘的盘符序列码,该盘符序列码需在[SourceDisksNames]节中列出,并大于或等于1。
Subdir为可选项,指定文件所在源盘的子目录,如省略则源盘为缺省安装路径。
file-size为可选项,表明文件的大小,以字节为单位。

[Strings]节

[Strings]节定义一个或多个本地化字符串,或称字符串宏。尽管[Strings]节一般被放置在INF文件的末尾,字符串宏可在INF文件任何地方使用,安装引擎解释、展开字符串宏为给定的长字符串并做进一步处理。字符串宏在使用时需用百分号(%)括起。[Strings]节内语句的语法为:
strings-key=value
其中strings-key为由字母或数字等可打印字符组成的宏名。
Value为被双引号括起的长字符串,字符串可由字母、数字或其他可打印字符组成。

一个具体的安装实例

本文接下来列举一个名为“Mysetup.inf”的安装信息文件实例,以便读者熟悉INF文件语法,领略INF文件的安装效果。该“Mysetup.inf”文件可完成如下的安装任务:假设应用程序有“MyApp.exe”、“MyApp.hlp”、“MyApp.dll”等几个需安装到应用程序主目录的文件,有“Ass_1.dll”、“Ass_2.dll”等几个需安装到Windows\System子目录的文件,要求将各文件按预定目录位置拷贝到位,其中应用程序主目录可在安装过程中选定,同时,在“开始>程序”下面建立名为“我的程序组”的程序组,在该程序组下建立名为“我的应用程序”、“我的应用程序帮助”的两个程序项,分别与“MyApp.exe”和“MyApp.hlp”文件关联。
完成上述安装任务的“Mysetup.inf”文件内容如下:

[Version]
signature=“$chicago$”
[AdvSetup]
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce\Setup,“INF制作安装程序”,,“RunDll32.exe“%01%”\advpack.dll,LaunchINFSection Mysetup.inf,DefaultInstall2”
[DefaultInstallX]
[DefaultInstall]
AddReg=AdvSetup
[DefaultInstall2]
CopyFiles = 拷贝到用户指定目录,拷贝到Windows\System子目录 ,……
CustomDestination=My-path
UpdateInis = 加exe文件快捷方式,加hlp文件快捷方式,……
[SourceDisksNames]
1=“文件所在目录”,,0
[SourceDisksFiles]
MyApp.exe.exe=1,,1021
MyApp.dll=1,,1021
MyApp.hlp=1,,1021
Ass_1.dll=1,,1021
Ass_2.dll=1,,1021
[DestinationDirs]
拷贝到用户指定目录 = 49000
拷贝到Windows\System子目录 = 11
[My-path]
49000,49001,49002,49003=index-again,1
[index-again]
“”,“”,“”,,““默认安装到“C:\MyApp”目录,可选择””,“%30%\MyApp”
[拷贝到用户指定目录]
MyApp.exe
MyApp.dll
MyApp.hlp
[拷贝到Windows\System子目录]
Ass_1.dll
Ass_2.dll
[加exe文件快捷方式]
setup.ini, progman.groups,, “group1=““我的程序组”””
setup.ini, group1,,“““我的应用程序””,““““““%49000%\MyApp.exe””””””,,,,,““MyApp.exe”””
[加hlp文件快捷方式]
setup.ini, progman.groups,, “group1=““我的程序组”””
setup.ini, group1,,“““我的应用程序帮助””,““““““%49000%\MyApp.hlp””””””,,,,,““MyApp.hlp”””
读者会注意到上面的文件内许多键名使用了中文,这是因为INF格式文件支持中文提示及中文键名。这些中文键名不仅充当功能键起索引的作用,还形象化地标识了键的前后对应关系,增强了文件内容的可读性,有利于后续更改、维护。

安装时,首先确保应用程序的所有待安装文件和“Mysetup.inf” 文件处在同一个目录下,右击“Mysetup.inf”文件选“安装”或按Shift键的同时按功能键F10。待目录选择对话框出现,点击“浏览”按钮或直接在文本编辑框内键入目录名称后,屏幕显示文件安装拷贝和更新快捷方式进度,最终结束。

打开资源管理器,就可查看到所有文件均已拷贝到指定目录位置。点击“开始>程序”,可以找到“我的程序组”程序组及下属的“我的应用程序”、“我的应用程序帮助”程序项,选中程序项均能激活对应文件,说明文件安装及快捷方式关联均告成功。
请查看以下的C++代码的编写要求,请根据代码要求开始编写代码 PURPOSE: This file is a proforma for the EEET2246 Laboratory Code Submission/Test 1. This file defines the assessment task which is worth 10% of course in total - there is no other documentation. At the BASIC FUNCTIONAL REQUIREMENTS level, your goal is to write a program that takes two numbers from the command line and perform and arithmetic operations with them. Additionally your program must be able to take three command line arguments where if the last argument is 'a' an addition is performed, and if 's' then subtraction is performed with the first two arguments. At the FUNCTIONAL REQUIREMENTS level you will be required to extend on the functionality so that the third argument can also be 'm' for multiplication,'d' for division and 'p' for exponential operations, using the first two arguments as the operands. Additionally, at this level basic error detection and handling will be required. The functionality of this lab is relatively simple: + - / * and "raised to the power of" The emphasis in this lab is to achieve the BASIC FUNCTIONALITY REQUIREMENTS first. Once you a basic program functioning then you should attempt the FUNCTIONALITY REQUIREMENTS and develop your code so that it can handle a full range of error detection and handling. ___________________________________________________________________________________________ ___ GENERAL SPECIFICATIONS (mostly common to all three EEET2246 Laboratory Code Submissions): G1. You must rename your file to lab1_1234567.cpp, where 1234567 is your student number. Your filename MUST NEVER EVER contain any spaces. _under_score_is_Fine. You do not need to include the 's' in front of your student number. Canvas will rename your submission by adding a -1, -2 etc. if you resubmit your solution file - This is acceptable. G2. Edit the name/email address string in the main() function to your student number, student email and student name. The format of the student ID line is CSV (Comma Separated Variables) with NO SPACES- student_id,student_email,student_name When the program is run without any operands i.e. simply the name of the executable such as: lab1_1234567.exe the program MUST print student ID string in Comma Separated Values (CSV) format with no spaces. For example the following text should be outputted to the console updated with your student details: "1234567,s1234567@student.rmit.edu.au,FirstName_LastName" G3. All outputs are a single error character or a numerical number, as specified by the FUNCTIONAL REQURMENTS, followed by a linefeed ( endl or \n). G4. DO NOT add more than what is specified to the expected console output. Do NOT add additional information, text or comments to the output console that are not defined within the SPECIFICATIONS/FUNCTIONAL REQURMENTS. G5. DO NOT use 'cin', system("pause"), getchar(), gets(), etc. type functions. Do NOT ask for user input from the keyboard. All input MUST be specified on the command line separated by blank spaces (i.e. use the argv and argc input parameters). G6. DO NOT use the characters: * / \ : ^ ? in your command line arguments as your user input. These are special character and may not be processed as expected, potentially resulting in undefined behaviour of your program. G7. All input MUST be specified on the command line separated by blank spaces (i.e. use the argc and argv[] input parameters). All input and output is case sensitive unless specified. G8. You should use the Integrated Debugging Environment (IDE) to change input arguments during the development process. G9. When your code exits the 'main()' function using the 'return' command, you MUST use zero as the return value. This requirement is for exiting the 'main()' function ONLY. A return value other than zero will indicate that something went wrong to the Autotester and no marks will be awarded. G10. User-defined functions and/or class declarations must be written before the 'main()' function. This is a requirement of the Autotester and failure to do so will result in your code scoring 0% as it will not be compiled correctly by the Autotester. Do NOT put any functions/class definitions after the 'main()' function or modify the comments and blank lines at the end of this file. G11. You MUST run this file as part of a Project - No other *.cpp or *.h files should be added to your solution. G12. You are not permitted to add any other #includes statements to your solution. The only libraries permitted to be used are the ones predefined in this file. G13. Under no circumstances is your code solution to contain any go_to labels - Please note that the '_' has been added to this description so that this file does not flag the Autotester. Code that contains go_to label like syntax will score 0% and will be treated as code that does not compile. G14. Under no circumstances is your code solution to contain any exit_(0) type functions. Please note that the '_' has been added to this description so that this file does not flag the Autotester. Your solution must always exit with a return 0; in main(). Code that contains exit_(0); label like syntax will score 0% and will be treated as code that does not compile. G15. Under no circumstances is your code solution to contain an infinite loop constructs within it. For example usage of while(1), for(int i; ; i++) or anything similar is not permitted. Code that contains an infinite loop will result in a score of 0% for your assessment submission and will be treated as code that does not compile. G16. Under no circumstances is your code solution to contain any S_l_e_e_p() or D_e_l_a_y() like statements - Please note that the '_' has been added to this description so that this file does not flag the Autotester. You can use such statements during your development, however you must remove delays or sleeps from your code prior to submission. This is important, as the Autotester will only give your solution a limited number of seconds to complete (i.e. return 0 in main()). Failure for your code to complete the required operation/s within the allotted execution window will result in the Autotester scoring your code 0 marks for that test. To test if your code will execute in the allotted execution window, check that it completes within a similar time frame as the provided sample binary. G17. Under no circumstances is your code solution to contain any characters from the extended ASCII character set or International typeset characters. Although such characters may compile under a normal system, they will result in your code potentially not compiling under the Autotester environment. Therefore, please ensure that you only use characters: a ... z, A ... Z, 0 ... 9 as your variable and function names or within any literal strings defined within your code. Literal strings can contain '.', '_', '-', and other basic symbols. G18. All output to console should be directed to the standard console (stdout) via cout. Do not use cerr or clog to print to the console. G19. The file you submit must compile without issues as a self contained *.cpp file. Code that does not compile will be graded as a non-negotiable zero mark. G20. All binary numbers within this document have the prefix 0b. This notation is not C++ compliant (depending on the C++ version), however is used to avoid confusion between decimal, hexadecimal and binary number formats within the description and specification provided in this document. For example the number 10 in decimal could be written as 0xA in hexadecimal or 0b1010 in binary. It can equally be written with leading zeroes such as: 0x0A or 0b00001010. For output to the console screen you should only ever display the numerical characters only and omit the 0x or 0b prefixes (unless it is specifically requested). ___________________________________________________________________________________________ ___ BASIC FUNCTIONAL REQUIREMENTS (doing these alone will only get you to approximately 40%): M1. For situation where NO command line arguments are passed to your program: M1.1 Your program must display your correct student details in the format: "3939723,s3939723@student.rmit.edu.au,Yang_Yang" M2. For situation where TWO command line arguments are passed to your program: M2.1 Your program must perform an addition operation, taking the first two arguments as the operands and display only the result to the console with a new line character. Example1: lab1_1234567.exe 10 2 which should calculate 10 + 2 = 12, i.e. the last (and only) line on the console will be: 12 M3. For situations where THREE command line arguments are passed to your program: M3.1 If the third argument is 'a', your program must perform an addition operation, taking the first two arguments as the operands and display only the result to the console with a new line character. M3.2 If the third argument is 's', your program must perform a subtraction operation, taking the first two arguments as the operands and display only the result to the console with a new line character. The second input argument should be subtracted from the first input argument. M4. For situations where less than TWO or more than THREE command line arguments are passed to your program, your program must display the character 'P' to the console with a new line character. M5. For specifications M1 to M4 inclusive: M5.1 Program must return 0 under all situations at exit. M5.2 Program must be able to handle integer arguments. M5.3 Program must be able to handle floating point arguments. M5.4 Program must be able to handle one integer and one floating point argument in any order. Example2: lab1_1234567.exe 10 2 s which should calculate 10 - 2 = 8, i.e. the last (and only) line on the console will be: 8 Example3: lab1_1234567.exe 10 2 which should calculate 10 + 2 = 12, i.e. the last (and only) line on the console will be: 12 Example4: lab1_1234567.exe 10 4 a which should calculate 10 + 4 = 14, i.e. the last (and only) line on the console will be: 14 ___________________________________________________________________________________________ ___ FUNCTIONAL REQUIREMENTS (to get over approximately 50%): E1. For situations where THREE command line arguments (other than 'a' or 's') are passed to your program: E1.1 If the third argument is 'm', your program must perform a multiplication operation, taking the first two arguments as the operands and display only the result to the console with a new line character. E1.2 If the third argument is 'd', your program must perform a division operation, taking the first two arguments as the operands and display only the result to the console with a new line character. E1.3 If the third argument is 'p', your program must perform an exponential operation, taking the first argument as the base operand and the second as the exponent operand. The result must be display to the console with a new line character. Hint: Consider using the pow() function, which has the definition: double pow(double base, double exponent); Example5: lab1_1234567.exe 10 2 d which should calculate 10 / 2 = 5, i.e. the last (and only) line on the console will be: 5 Example6: lab1_1234567.exe 10 2 p which should calculate 10 to power of 2 = 100, i.e. the last (and only) line on the console will be: 100 NOTE1: DO NOT use the character ^ in your command line arguments as your user input. Question: Why don't we use characters such as + - * / ^ ? to determine the operation? Answer: Arguments passed via the command line are processed by the operating system before being passed to your program. During this process, special characters such as + - * / ^ ? are stripped from the input argument stream. Therefore, the input characters: + - * / ^ ? will not be tested for by the autotester. See sections G6 and E7. NOTE2: the pow() and powl() function/s only work correctly for given arguments. Hence, your code should output and error if there is a domain error or undefined subset of values. For example, if the result does not produce a real number you code should handle this as an error. This means that if the base is negative you can't accept and exponent between (but not including) -1 and 1. If you get this then, output a MURPHY's LAW error: "Y" and return 0; NOTE3: zero to the power of zero is also undefined, and should also be treated MURPHY's LAW error. So return "Y" and return 0; In Visual Studio, the 0 to the power of 0 will return 1, so you will need to catch this situation manually, else your code will likely calculate the value as 1. ___ REQUIRED ERROR HANDLING (to get over approximately 70%): The following text lists errors you must detect and a priority of testing. NB: order of testing is important as each test is slight more difficult than the previous test. All outputs should either be numerical or upper-case single characters (followed by a new line). Note that case is important: In C, 'V' is not the same as 'v'. (No quotes are required on the output). E2. Valid operator input: If the third input argument is not a valid operation selection, the output shall be 'V'. Valid operators are ONLY (case sensitive): a addition s subtraction m multiplication d division p exponentiation i.e. to the power of: 2 to the power of 3 = 8 (base exponent p) E3. Basic invalid number detection (Required): Valid numbers are all numbers that the "average Engineering graduate" in Australia would consider valid. Therefore if the first two arguments are not valid decimal numbers, the output shall be 'X'. For example: -130 is valid +100 is valid 1.3 is valid 3 is valid 0.3 is valid .3 is valid ABC123 is not valid 1.3.4 is not valid 123abc is not valid ___ ERROR HANDLING (not marked by the autotester): E4. Intermediate invalid number detection (NOT TESTED BY AUTOTESTER - for your consideration only): If the first two arguments are not valid decimal numbers, the output shall be 'X'. Using comma punctuated numbers and scientific formatted numbers are considered valid. For example: 0000.111 is valid 3,000 is valid - NB: atof() will read this as '3' not as 3000 1,000.9 is valid - NB: atof() will read this as '1' not as 1000.9 1.23e2 is valid 2E2 is valid -3e-0.5 is not valid (an integer must follow after the e or E for floating point number to be valid) 2E2.1 is not valid e-1 is not valid .e3 is not valid E5. Advanced invalid number detection (NOT TESTED BY AUTOTESTER - for your consideration only): If the first two arguments are not valid decimal numbers, the output shall be 'X'. 1.3e-1 is valid 1,00.0 is valid - NB: if the comma is not removed atof() will read this as '1' not as 100 +212+21-2 is not valid - NB: mathematical operation on a number of numbers, not ONE number 5/2 is not valid - NB: mathematical operation on a number of numbers, not ONE number HINT: consider the function atof(), which has the definition: double atof (const char* str); Checking the user input for multiple operators (i.e. + or -) is quite a difficult task. One method may involve writing a 'for' loop which steps through the input argv[] counting the number of operators. This process could also be used to count for decimal points and the like. The multiple operator check should be considered an advanced task and developed once the rest of the code is operational. E6. Input number range checking: All input numbers must be between (and including) +2^16 (65536) or -2^16 (-65536). If the operand is out of range i.e. too small or too big, the output shall be 'R'. LARGE NUMBERS: is 1.2e+999 acceptable input ? what happens if you enter such a number ? try and see. Hint: #INF error - where and when does it come up ? SMALL NUMBERS: is 1.2e-999 acceptable input ? what happens if you enter such a number ? try and see. Test it by writing your own test program. E7. ERROR checks which will NOT be performed are: E7.1 Input characters such as: *.* or / or \ or : or any of these characters: * / ^ ? will not be tested for. E7.2 Range check: some computer systems accept numbers of size 9999e999999 while others flag and infinity error. An infinity error becomes an invalid input Therefore: input for valid numbers will only be tested to the maximum 9.9e99 (Note: 9.9e99 is out of range and your program should output 'R') E8. Division by zero should produce output 'M' E9. Error precedence: If multiple errors occur during a program execution event, your program should only display one error code followed by a newline character and then exit (using a return 0; statement). In general, the precedence of the error reported to the console should be displayed in the order that they appear within this proforma. However to clarify the exact order or precedence for the error characters, the precedence of the displayed error code should occur in this order: 'P' - Incorrect number of input command line arguments (see M4) 'X' - Invalid numerical command line argument 'V' - Invalid third input argument 'R' - operand (command line argument) value out of range 'M' - Division by zero 'Y' - MURPHY'S LAW (undefined error) Therefore if an invalid numerical command line argument and an invalid operation argument are passed to the program, the first error code should be displayed to the console, which in this case would be 'X'. Displaying 'V' or 'Y' would be result in a loss of marks. E10. ANYTHING ELSE THAT CAN GO WRONG (MURPHY'S LAW TEST): If there are any other kinds of errors not covered here, the output shall be 'Y'. Rhetorical question: What for example are the error codes that the Power function returns ? If this happens then the output shall be 'Y'. See section E1.3, NOTE2. ___________________________________________________________________________________________ ___ HINTS: - Use debug mode and a breakpoint at the return statement prior to program finish in main. - What string conversion routines, do you know how to convert strings to number? Look carefully as they will be needed to convert a command line parameter to a number and also check for errors. - ERROR CHECKING: The basic programming rules are simple (as covered in lectures): 1) check that the input is valid. 2) check that the output is valid. 3) if any library function returns an error code USE IT !!! CHECK FOR IT !!! - Most conversion routines do have inbuilt error checking - USE IT !!! That means: test for the error condition and take some action if the error is true. If that means more than 50% of your code is error checking, then that's the way it has to be. ____________________________________________________________________________________________ */ // These are the libraries you are allowed to use to write your solution. Do not add any // additional libraries as the auto-tester will be locked down to the following: #include <iostream> #include <cstdlib> #include <time.h> #include <math.h> #include <errno.h> // leave this one in please, it is required by the Autotester! // Do NOT Add or remove any #include statements to this project!! // All library functions required should be covered by the above // include list. Do not add a *.h file for this project as all your // code should be included in this file. using namespace std; const double MAXRANGE = pow(2.0, 16.0); // 65536 const double MINRANGE = -pow(2.0, 16.0); // All functions to be defined below and above main() - NO exceptions !!! Do NOT // define function below main() as your code will fail to compile in the auto-tester. // WRITE ANY USER DEFINED FUNCTIONS HERE (optional) // all function definitions and prototypes to be defined above this line - NO exceptions !!! int main(int argc, char *argv[]) { // ALL CODE (excluding variable declarations) MUST come after the following 'if' statement if (argc == 1) { // When run with just the program name (no parameters) your code MUST print // student ID string in CSV format. i.e. // "studentNumber,student_email,student_name" // eg: "3939723,s3939723@student.rmit.edu.au,Yang_Yang" // No parameters on command line just the program name // Edit string below: eg: "studentNumber,student_email,student_name" cout << "3939723,s3939723@student.rmit.edu.au,Yang_Yang" << endl; // Failure of your program to do this cout statement correctly will result in a // flat 10% marks penalty! Check this outputs correctly when no arguments are // passed to your program before you submit your file! Do it as your last test! // The convention is to return Zero to signal NO ERRORS (please do not change it). return 0; } //--- START YOUR CODE HERE. // The convention is to return Zero to signal NO ERRORS (please do not change it). // If you change it the AutoTester will assume you have made some major error. return 0; } // No code to be placed below this line - all functions to be defined above main() function. // End of file.
最新发布
08-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值