Board logo

标题: [已解决] 批处理智能输出文件除错 [不公开] [打印本页]

作者: chishingchan     时间: 2008-5-1 23:38    标题: [已解决] 批处理智能输出文件除错 [不公开]

以下是原程序,首先解释说明一下:这个是 BeTwin 系列版本补丁生成程序。
309、348、362 是 BeTwin 的版本号,5.00、5.1、5.2 分别是 Windows2000、WindowsXP、Windows2003 的版本号。
流程:
@echo off
:: 检测 BeTwin 的版本号
for /f "tokens=1-3 delims=." %%a in ('REG QUERY "HKLM\SOFTWARE\BeTwin" /v ProductVersion ^|findstr "ProductVersion"') do set PV=%%c
if "%PV%"=="" exit else goto %%PV%%

:309
:: 309 版本的输出文件
for /f "tokens=2*" %%a in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion ^|findstr "CurrentVersion"') do set CV=%%b
if %CV%*==5.00* set win2000=174235
if %CV%*==5.1* set winxp=193915
if %CV%*==5.2* set win2003=192659
call :cs&call :%%CV%%&call :ce&exit

:348
:: 348 版本的输出文件
for /f "tokens=2*" %%a in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion ^|findstr "CurrentVersion"') do set CV=%%b
if %CV%*==5.00* set win2000=171916
if %CV%*==5.1* set winxp=191196
if %CV%*==5.2* set win2003=190020
call :cs&call :%%CV%%&call :ce&exit

:362
:: 362 版本的输出文件
for /f "tokens=2*" %%a in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion ^|findstr "CurrentVersion"') do set CV=%%b
if %CV%*==5.00* set win2000=175435
if %CV%*==5.1* set winxp=194555
if %CV%*==5.2* set win2003=193539
call :cs&call :%%CV%%&call :ce&exit

:cs
:: 公用开头程序行
>%PV%.vbs echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%PV%.vbs echo set ado_stream = CreateObject("ADODB.Stream")
>>%PV%.vbs echo ado_stream.Type = 1

:5.00
>>%PV%.vbs echo iFile = fso.GetSpecialFolder(1) ^& "\BeTwinService2K.exe"
>>%PV%.vbs echo if fso.FileExists(iFile) Then
>>%PV%.vbs echo ado_stream.open
>>%PV%.vbs echo ado_stream.LoadFromFile iFile
>>%PV%.vbs echo ado_stream.position = %win2000%
>>%PV%.vbs echo ado_stream.Write HexToByte("EB")
>>%PV%.vbs echo ado_stream.SaveToFile iFile,2
>>%PV%.vbs echo ado_stream.Close
>>%PV%.vbs echo End if

:5.2
>>%PV%.vbs echo iFile = fso.GetSpecialFolder(1) ^& "\BeTwinService2003.exe"
>>%PV%.vbs echo if fso.FileExists(iFile) Then
>>%PV%.vbs echo ado_stream.open
>>%PV%.vbs echo ado_stream.LoadFromFile iFile
>>%PV%.vbs echo ado_stream.position = %win2003%
>>%PV%.vbs echo ado_stream.Write HexToByte("EB")
>>%PV%.vbs echo ado_stream.SaveToFile iFile,2
>>%PV%.vbs echo ado_stream.Close
>>%PV%.vbs echo End if

:5.1
>>%PV%.vbs echo iFile = fso.GetSpecialFolder(1) ^& "\BeTwinServiceXP.exe"
>>%PV%.vbs echo if fso.FileExists(iFile) Then
>>%PV%.vbs echo ado_stream.open
>>%PV%.vbs echo ado_stream.LoadFromFile iFile
>>%PV%.vbs echo ado_stream.position = %winxp%
>>%PV%.vbs echo ado_stream.Write HexToByte("EB")
>>%PV%.vbs echo ado_stream.SaveToFile iFile,2
>>%PV%.vbs echo ado_stream.Close
>>%PV%.vbs echo End if

:ce
:: 公用结尾程序行
>>%PV%.vbs echo set ado_stream = Nothing
>>%PV%.vbs echo Function HexToByte(hexStr)
>>%PV%.vbs echo set xmldom = Wscript.CreateObject("Microsoft.XMLDOM")
>>%PV%.vbs echo set byteObj= xmldom.createElement("byteObj")
>>%PV%.vbs echo byteObj.dataType = "bin.hex"
>>%PV%.vbs echo byteObj.nodeTypedValue = hexStr
>>%PV%.vbs echo HexToByte=byteObj.nodeTypedValue
>>%PV%.vbs echo End Function
例如:系统是WindowsXP、BeTwin 版本号是 362,生成的文件应该如下:

  Quote:
Set fso = CreateObject("Scripting.FileSystemObject")

set ado_stream = CreateObject("ADODB.Stream")
ado_stream.Type = 1

iFile = fso.GetSpecialFolder(1) & "\BeTwinServiceXP.exe"
if fso.FileExists(iFile) Then
ado_stream.open
ado_stream.LoadFromFile iFile
ado_stream.position = 194555
ado_stream.Write HexToByte("EB")
ado_stream.SaveToFile iFile,2
ado_stream.Close
End if

set ado_stream = Nothing

Function HexToByte(hexStr)
set xmldom = Wscript.CreateObject("Microsoft.XMLDOM")
set byteObj= xmldom.createElement("byteObj")
byteObj.dataType = "bin.hex"
byteObj.nodeTypedValue = hexStr
HexToByte=byteObj.nodeTypedValue
End Function

请问如何修改?谢谢!

[ Last edited by chishingchan on 2008-5-2 at 01:27 AM ]