【问题标题】:VBS Script to adapt in another languageVBS 脚本以适应另一种语言
【发布时间】:2014-07-16 14:41:00
【问题描述】:

我有一个脚本可以在基于英语的计算机上完美运行,但不能在另一种语言中运行。

脚本获取机器 Bitlocker 的恢复密钥,然后将其备份到 Active Directory。

我已经确定我需要将“数字密码”更新为相应语言的值,但这并不会最终更改空白变量 NumericalKeyID 的输出...

Option Explicit
Dim strNumericalKeyID 
Dim strManageBDE,strManageBDE2 
Dim oShell 
Dim StrPath 
Dim StdOut, strCommand 
Dim Result, TPM, strLine 
Dim Flag, NumericalKeyID
Set oShell = CreateObject("WSCript.Shell")
'==================================================================================== 
'This section looks for the Bitlocker Key Numerical ID
strManageBDE = "Manage-BDE.exe -protectors -get c:" 'Bitlocker command to gather the ID
Flag = False
Set Result = oShell.Exec(strManageBDE)'sees the results and places it in Result
Set TPM = Result.StdOut    'Sets the variable TPM to the output if the strManageBDe command
While Not TPM.AtEndOfStream 
   strLine = TPM.ReadLine  'Sets strLine 
   If InStr(strLine, "Numerical Password:") Then  ' This section looks for the Numerical Password 
    Flag = True 
   End If 
   If Flag = True Then 
     If InStr(strLine, "ID:") Then  'This section looks for the ID 
      NumericalKeyID = Trim(strLine)' This section trims the empty spaces from the ID {} line 
      NumericalKeyID = Right(NumericalKeyID, Len(NumericalKeyID)-4) 
      Flag = False 'Stops the other lines from being collected 
     End If 
   End If 
Wend
strManageBDE2 = "Manage-BDE.exe -protectors -adbackup C: -ID " & NumericalKeyID 
oShell.Run strManageBDE2, 0, True 'Runs the Manage-bde command to move the numerical ID to AD.

我确信这很愚蠢,但我的脚本知识很新。

非常感谢! :)

manage-bde 的英文输出:

【问题讨论】:

  • 您使用的是什么操作系统?它必须在 VBScript 中吗?
  • Windows 7。我尝试过 Powershell,但 BitLocker cmdlet 仅适用于 Windows 8 及更高版本的 Powershell v3。
  • 能否添加来自 Manage-BDE.exe 的输出(混淆敏感位)?我手边没有启用 Bitlocker 的机器
  • 为什么不使用 Manage-BDE.exe -protectors -adbackup C 将所有密钥备份到 AD:您不必指定 -ID 参数
  • 不,跳过整个脚本,只运行 Manage-BDE.exe -protectors -adbackup C:这将备份所有保护器,而不仅仅是单个保护器。您是否特别需要仅备份其中一个保护器?

标签: windows vbscript


【解决方案1】:

尽管我讨厌建议使用正则表达式的解决方案 (Obligatory XKCD link) 我认为这可能是您最好的选择

这样的事情应该可以解决问题

.*ID:.*{(.*)}.*

为你分解

.* - Match any character ID: - Match ID: .* - Match any character { - match { ( - remember anything between this and the next ) } - match } .* - Match any character

如果您不熟悉 VBScript 对正则表达式的支持,这个链接非常好Regular Expression - VBScript

Dim myRegExp, myMatches id Set myRegExp = New RegExp myRegExp.Global = True myRegExp.Pattern = ".*ID:.*{(.*)}.*" Set myMatches = myRegExp.Execute(subjectString) id = myMatches(0).SubMatches(0)

此解决方案的注意事项

  • 如果不同机器的输出差异很大,您可能需要调整正则表达式(您是否拥有多个保护器?)

如果您是 Regex 的新手,Expresso 是一个有用的测试/学习工具

【讨论】:

    【解决方案2】:

    谢谢大卫。

    我只有一个保护器要备份,还有一个驱动器。

    问题是,正如我所说,当计算机的语言是英语时,一切都可以完美运行,但只要我有一种语言将“数字密码”替换为一些带有特殊字符的单词,如“锓ñ " 它不会被识别,变量会得到一个空白值。

    可能是因为vbscript这种方式不处理unicode。

    为了说明我的说法,这里是与我的第一篇文章相同的屏幕截图,但是是法语:

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 2011-01-04
      • 2014-12-27
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 1970-01-01
      相关资源
      最近更新 更多