Windows 用另一种语言改编的VBS脚本

Windows 用另一种语言改编的VBS脚本,windows,vbscript,Windows,Vbscript,我有一个脚本,它在基于英语的计算机上运行得非常好,但在另一种语言中不会运行一次 该脚本获取计算机Bitlocker的恢复密钥,然后将其备份到Active Directory中 我已经确定需要将“数字密码”更新为相应语言中的值,但这不会改变最终空变量NumericalKeyID的输出 Option Explicit Dim strNumericalKeyID Dim strManageBDE,strManageBDE2 Dim oShell Dim StrPath Dim StdOut,

我有一个脚本,它在基于英语的计算机上运行得非常好,但在另一种语言中不会运行一次

该脚本获取计算机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的输出:


尽管我不喜欢建议使用正则表达式的解决方案() 我想这可能是你最好的选择

像这样的东西应该能奏效

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

为你把它分解


.*-匹配任何字符
ID:-匹配ID:
.*-匹配任何字符
{匹配{
(-记住这一次和下一次之间的任何事情)
}-匹配}
*-匹配任何字符

如果您不熟悉VBScript对正则表达式的支持,此链接非常好


Dim myRegExp,myid
设置myRegExp=newregexp
myRegExp.Global=True
myRegExp.Pattern=“.*ID:.*{(.*)}.*”
Set myMatches=myRegExp.Execute(subjectString)
id=myMatches(0)。子匹配(0)

此解决方案的警告

  • 如果不同机器的输出差异很大,您可能需要调整正则表达式(您是否有过多个保护器?)
如果您是新手,那么Regex是测试/学习的有用工具

谢谢David

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

问题是,正如我所说,当计算机语言为英语时,一切都能完美工作,但只要我有一种语言,用一些带有特殊字符(如“锓ñ”)的单词替换“数字密码”,它就不会被识别,变量就会得到一个空值

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

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


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