【发布时间】:2017-08-19 23:59:51
【问题描述】:
我有一个工作 .vbs 文件,它读取二进制文件,更改一个字节并保存文件。在 Windows 1607 之前,这在许多不同的 Windows 系统上都可以正常工作。
但是,现在对于 1607 及更高版本的 Windows 10,它不再有效!
我已经更改了代码,因为我在 1607 中不再正常工作的读取文件代码,但我仍然遇到问题
data = Mid(data, 1, 21) & Chr(b21) & Mid(data, 23) 在 Windows 10 1607 之前完美运行的行!
我明白了
(60, 3) ADODB.Stream: 参数类型错误、超出可接受范围或相互冲突。
此代码在桌面上创建一个快捷方式,然后更改一个字节的一位,以便快捷方式以管理员身份运行。如果我注释掉有问题的行,那么它似乎可以工作。
这是 Windows 10 1607 VBScript 中的错误吗?
' Make shortcut on Desktop and Set as Run As Admin
Q = Chr(34)
Dim fso
Dim curDir
Dim WinScriptHost
If WScript.Arguments.Count < 2 Then
WScript.Echo "Please run CreateShortcuts.cmd"
WScript.Quit
End If
' --- SET Target and Desktop Link Name from command line ---
strTargetName = WScript.Arguments.Item(0)
strLinkName = WScript.Arguments.Item(1)
'Target - e.g. %windir%\system32\cmd.exe /c C:\"temp\MakePartImage_AutoRun_FAT32.cmd"
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strWinDir =WshShell.ExpandEnvironmentStrings("%windir%")
strSysDir = strWinDir & "\System32"
strMyDir = fso.GetParentFolderName(wscript.ScriptFullName)
strDesktop = WshShell.SpecialFolders("Desktop")
strCurDir = WshShell.CurrentDirectory ' e.g. C:\temp
strMyDirSpecial = Mid(strMyDir, 1, 3) & Q & Mid(strMyDir, 4) & "\" & strTargetName & Q
Set oMyShortCut= WshShell.CreateShortcut(strDesktop + "\" & strLinkName)
oMyShortCut.WindowStyle = 1 '1=default 3=max 7=Min
oMyShortCut.TargetPath = Q & strSysDir & "\cmd.exe" & Q
oMyShortCut.Arguments= " /c " & strMyDirSpecial
oMyShortcut.IconLocation = "%windir%\system32\cmd.exe"
oMyShortCut.WorkingDirectory = Q & strMyDir & Q
oMyShortCut.Save
Set fso = Nothing
'read binary geometry into byte array
Dim stream, data
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1
stream.LoadFromFile(strDesktop + "\" & strLinkName)
data = stream.Read
stream.Close
WScript.Echo "BYTES 16-23 " & Hex(Asc(Mid(data, 16, 1))) & " " & Hex(Asc(Mid(data, 17, 1))) & " " & Hex(Asc(Mid(data, 18, 1))) & " " & Hex(Asc(Mid(data, 19, 1))) & " " & Hex(Asc(Mid(data, 20, 1))) & " " & Hex(Asc(Mid(data, 21, 1))) & " " & Hex(Asc(Mid(data, 22, 1))) & " " & Hex(Asc(Mid(data, 23, 1)))
' --- PATCH .LNK FILE to set byte 21 bit 5 for Admin rights
Dim b21
b21 = Asc(Nid(data, 22, 1)) Or 32 'set bit 6 0x20
' THIS NEXT LINE CAUSES PROBLEMS!
data = Mid(data, 1, 21) & Chr(b21) & Mid(data, 23)
WScript.Echo "BYTES 16-23 " & Hex(Asc(Mid(data, 16, 1))) & " " & Hex(Asc(Mid(data, 17, 1))) & " " & Hex(Asc(Mid(data, 18, 1))) & " " & Hex(Asc(Mid(data, 19, 1))) & " " & Hex(Asc(Mid(data, 20, 1))) & " " & Hex(Asc(Mid(data, 21, 1))) & " " & Hex(Asc(Mid(data, 22, 1))) & " " & Hex(Asc(Mid(data, 23, 1)))
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.Write data
BinaryStream.SaveToFile strDesktop+"\" & strLinkName, adSaveCreateOverWrite
WScript.Echo "Shortcut " & strLinkName & " created on Desktop."
【问题讨论】:
-
是 Windows 操作系统版本、架构 (32 位与 64 位) 还是两者都发生了变化?
-
我使用的是 Win 10 64 位。直到几周前它工作正常。现在它不起作用。另一位用户说这是 1607 更新和最新的预发布更新,两者都显示出问题。我的版本现在是 1607,它不再工作,所以我认为它是 1607 中的错误。
-
在 1607 Build 14303.3.969 上失败。我尝试全新安装 Win 10 1607 Build 14393.3.0 并且 vbscript 有效。那么问题是由延迟 KB 更新引起的?
-
如果在不对代码进行任何修改的情况下修复它,那么您最好留下答案。别担心Stack Overflowencourages answering your own questions,它不会对你不利,这可能会帮助遇到同样问题的其他人。
-
我从 14303.3.0 更新到 14303.3.969,现在同样的 vbscript 失败了!所以KB4015438坏了vbscript!!!
标签: arrays vbscript binary byte