下午发了个帖没说清楚,再说明一下,请大家帮忙看看如何用vbs实现。写这个脚本的目的是将输入的字符串转换为二进制并写入注册表,这个注册表键值格式要求每个二进制数值之间需插入"00"、最后以"0000"结尾。例如1234字符串对应的二进制代码为:31323334,按键值格式要求修改后应为:31 00 32 00 33 00 34 00 00 00。
以下为之前写的代码,但因处理后仍为字符串无法写入注册表。对vbs也不大熟,大家帮忙看看如何才能实现,谢了。- 'Define constant
- Const HKEY_CR = &H80000000
- Const REG_BINARY = 3
- 'string varable
- strComputer = "."
- strKeyPath = "11223344"
- strValue = "BBAA"
- 'Input string1
- dim Str2Hex
- string1 = InputBox("请输入")
- Dim i, sResult
- sResult = ""
- For i = 1 To Len(string1)
- sResult = sResult & "&H" & Hex(Asc(Mid(string1, i, 1))) & "," & "&H00,"
- if i = Len(string1) then
- sResult = sResult & "&H00,&H00"
- end if
- Next
- Str2Hex = sResult
- wsh.echo Str2Hex
- 'binary array
- Dim arrData
- arrData = Array(Str2Hex)
- 'registry object
- Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
- 'create registry key
- objRegistry.CreateKey HKEY_CR, strKeyPath
- 'setup the binary keyvalue
- retcode = objRegistry.SetBinaryValue(HKEY_CR, strKeyPath, strValue, arrData)
复制代码
[ 本帖最后由 fsed 于 2009-7-14 11:42 编辑 ] |