本帖最后由 ahkang 于 2010-3-29 10:06 编辑
仿深度小兵早期获取磁盘分区的脚本(自定义变量名是胡编乱造的, 可能有些费解)
其实, 深度小兵也是借助了第三方的工具: DsptW 来实现的, 本人在模拟实现其功能的基础上, 再加入了自动判断当前目录如果是光盘, 则不复制临时目录的 Ghost.ini 文件到脚本目录和读取磁盘隐藏分区功能, 这也借助了 "无忧启动论坛 123 MM 编写的一个小程序 ShowDrive, 由于考虑到害怕病毒感染, 在调用之前, 本人已将这2个文件均改了扩展名, 看起来像是系统扩展控件.
有了这2个文件, 论坛上的高手们一定写出更加精简的更优秀的脚本, 好了, 贴源码如下:#InClude <File.Au3>
#NoTrayIcon
;=========== 取本机磁盘最后分区 =============
Global $DwptW=@TempDir&'\DsptW.eXe'
Global $ShowDrive=@TempDir&'\ShowDrive.eXe'
Global $Part=@TempDir&'\Part.Txt'
Global $GhostIni=@TempDir&'\Ghost.InI'
Global $W=@DesktopWidth
Global $H=@DesktopHeight
Global $X=$W/2
Global $Y=$H/2
If FileExists($GhostIni) Then FileDelete($GhostIni)
ToolTip('正在获取本地磁盘分区信息, 请稍候!',$X,$Y,'正在智能判断本地磁盘分区:',1,6)
FileInstall('ShowDrive.Vxd',$ShowDrive,1)
RunWait($ShowDrive&' /S','',@Sw_Hide)
FileDelete($ShowDrive)
FileInstall('DsptW.Vxd',$DwptW,1)
If FileExists($Part) Then FileDelete($Part)
RunWait(@ComSpec&' /C '&$DwptW&' 0 /L >'&$Part,'',@Sw_Hide)
$SerailNumber=StringMid(FileReadLine($Part,3),59)
FileDelete($Part)
For $i=1 To 26
RunWait(@ComSpec&' /C '&$DwptW&' '&$i&' /Find:All /GhostStyle >>'&$Part,'',@Sw_Hide)
If StringInStr(FileRead($Part),'Error') Then ExitLoop
Next
FileDelete($DwptW)
Dim $v
_FileReadToArray($Part,$v)
FileWrite($GhostIni,'[HardDisk]')
IniWrite($GhostIni,'HardDisk','HDD-SN',$SerailNumber)
For $i=1 To $v[0]
$ReadLine=FileReadLine($Part,$i)
If StringInStr($ReadLine,'Error') Then ExitLoop
If Not StringInStr($ReadLine,'No.') And StringInStr($ReadLine,':') Then
$GhostStr=StringLeft($ReadLine,3)&'='&StringMid($ReadLine,6,2)
If StringMid($GhostStr,1,1)=1 And StringMid($ReadLine,6,2)=' ' Then
FileWriteLine($GhostIni,StringReplace($GhostStr&'C:',' ',''))
Else
FileWriteLine($GhostIni,$GhostStr)
EndIf
ExitLoop
EndIf
Next
For $i=1 To $v[0]
$ReadLine=FileReadLine($Part,$i)
If StringInStr($ReadLine,'Error') Then ExitLoop
If Not StringInStr($ReadLine,'No.') And StringInStr($ReadLine,':') Then
$GhostStr=StringLeft($ReadLine,3)&'='&StringMid($ReadLine,6,2)
If StringMid($ReadLine,6,2)<>'' And Not StringInStr($GhostStr,'1:1') Then FileWriteLine($GhostIni,$GhostStr)
EndIf
Next
FileDelete($Part)
_FileReadToArray($GhostIni,$v)
For $i=2 To $v[0]
$ReadLine=StringLeft(FileReadLine($GhostIni,$i),3)
If StringLeft($ReadLine,1)=1 Then
FileWriteLine($GhostIni,'LoadP='&$ReadLine)
ExitLoop
EndIf
Next
$Var=IniReadSection($GhostIni,'HardDisk')
If @Error Then
MsgBox(262144, '', '出错了啦! 当前目录找不到 Ghost.InI 文件.')
Else
For $i = 1 To $Var[0][0]
$GetLastP=StringMid($Var[$i][0],1,1)
If StringInStr($GetLastP,'H') Then $GetLastP=StringMid($Var[$i+1][0],1,1)
If $GetLastP<>1 Then
; MsgBox(262144, '', '键: ' & $Var[$i-1][0])
FileWriteLine($GhostIni,'LastP='&$Var[$i-1][0])
ExitLoop
EndIf
Next
EndIf
IniWrite($GhostIni,'HardDisk','BackP',IniRead($GhostIni,'HardDisk','LoadP',''))
IniWrite($GhostIni,'HardDisk','BackZ',3)
FileWriteLine($GhostIni,'')
IniWrite($GhostIni,'Setting','Mode',3)
$DriveType=DriveGetType(StringLeft(@ScriptDir,2))
If $DriveType='Fixed' Or $DriveType='ReMovAble' Then FIlecopy($GhostIni,@ScriptDir,1)
;================================================================================================
$GhostStrC=IniRead($GhostIni,'HardDisk','LoadP','')
$GhostStrL=IniRead($GhostIni,'HardDisk','LastP','')
$HomeDrive=IniRead($GhostIni,'HardDisk',$GhostStrC,'')
$LastDrive=IniRead($GhostIni,'HardDisk',$GhostStrL,'')
FIlecopy($GhostIni,@ScriptDir,1)
FileDelete($GhostIni)
;================================================================================================
ToolTip('')
MsgBox(262144,'','本机系统分区对应盘符 == '&$HomeDrive&@Cr&@Cr& _
'系统分区 Ghost 表示 == '&$GhostStrC&@Cr&@Cr& _
'本机最后分区对应盘符 == '&$LastDrive&@Cr&@Cr& _
'最后分区 Ghost 表示 == '&$GhostStrL,5)
;=========== 取本机磁盘最后分区 =============
所要用到的文件(包含编译时用到的图标)均在附件里. |