Sign in to follow this  
Followers 0
BoogY

Help with vbscript

3 posts in this topic

#1 ·  Posted (edited)

Hello to every one.

I have a vbscript that lists all the installed software on a computer and i used the vbscript to autoti converter and still not works cause there are some things not quite converted :(.

Here is the script :

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"

Set objReg = GetObject("winmgmts://" & strComputer & _
 "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
  intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
   strEntry1a, strValue1)
  If intRet1 <> 0 Then
    objReg.GetStringValue HKLM, strKey & strSubkey, _
     strEntry1b, strValue1
  End If
  If strValue1 <> "" Then
    strSubkeysRaw = strSubkeysRaw & strValue1 & ","
  End If
Next

If Right(strSubkeysRaw, 1) = ","Then
  strSubkeysPresort = LCase(Left(strSubkeysRaw, Len(strSubkeysRaw) - 1))
End If

arrSubkeysSort = Split(strSubkeysPresort, ",")

'Sort
For i = LBound(arrSubkeysSort) to UBound(arrSubkeysSort)
  For j = LBound(arrSubkeysSort) to UBound(arrSubkeysSort)
    If j <> UBound(arrSubkeysSort) Then
      If arrSubkeysSort(j) > arrSubkeysSort(j + 1) Then
         TempValue = arrSubkeysSort(j + 1)
         arrSubkeysSort(j + 1) = arrSubkeysSort(j)
         arrSubkeysSort(j) = TempValue
      End If
    End If
  Next
Next

WScript.Echo VbCrLf & "Installed Applications" & VbCrLf

For Each strSubkeySort in arrSubkeysSort
  WScript.Echo strSubkeySort
Next

And here is the converted one:

; ----------------------------------------------------------------------------
;
; VBScript to AutoIt Converter v0.52
;
; ----------------------------------------------------------------------------



Const $HKLM = hex(80000002) ;HKEY_LOCAL_MACHINE
$strComputer = "."
$strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$strEntry1a = "DisplayName"
$strEntry1b = "QuietDisplayName"
Dim $arrSubkeys

$objReg = ObjGet("winmgmts://" & $strComputer &  "/root/default:StdRegProv")

$objReg.EnumKey($HKLM, $strKey,$arrSubkeys)
For $strSubkey In $arrSubkeys
  $intRet1 = $objReg.GetStringValue($HKLM, $strKey & $strSubkey,$strEntry1a, $strValue1)

  If $intRet1 <> 0 Then
    $objReg.GetStringValue ($HKLM, $strKey & $strSubkey,      $strEntry1b, $strValue1)

  EndIf
  If $strValue1 <> "" Then
    $strSubkeysRaw = $strSubkeysRaw & $strValue1 & ","
  EndIf
Next

If StringRight($strSubkeysRaw, 1) = ","Then
  $strSubkeysPresort = StringLower(StringLeft($strSubkeysRaw, StringLen($strSubkeysRaw) - 1))
EndIf

$arrSubkeysSort = StringSplit($strSubkeysPresort, ",")

;Sort
For $i = LBound(arrSubkeysSort) to UBound($arrSubkeysSort)
  For $j = LBound(arrSubkeysSort) to UBound($arrSubkeysSort)
    If $j <> UBound($arrSubkeysSort) Then
      If $arrSubkeysSort($j) > $arrSubkeysSort($j + 1) Then
         $TempValue = $arrSubkeysSort($j + 1)
         $arrSubkeysSort($j + 1) = $arrSubkeysSort($j)
         $arrSubkeysSort($j) = $TempValue
      EndIf
    EndIf
  Next
Next

ConsoleWrite (@CRLF & "Installed Applications" & @CRLF)

For $strSubkeySort in $arrSubkeysSort
  ConsoleWrite ($strSubkeySort)
Next

Can someone please help me so I can make'it work in autoti ?

Thank you very much.

Edited by BoogY

Share this post


Link to post
Share on other sites



Hi,

messy code you have. Non declared variables, wrong UBound use, wrong adressed array, unknown functions......

Took some time with some search on msdn and i got a running version now, but i don't know if this is given the exact result.

Try this:

#include <array.au3>
Const $HKLM = 0x80000002 ;HKEY_LOCAL_MACHINE
$strComputer = "."
$strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$strEntry1a = "DisplayName"
$strEntry1b = "QuietDisplayName"
$strvalue1 = ""
$strSubkeysRaw = ""
Dim $arrSubkeys

$objReg = ObjGet("winmgmts://" & $strComputer &  "/root/default:StdRegProv")

 $objReg.EnumKey($HKLM, $strKey, $arrSubkeys)
For $strSubkey In $arrSubkeys
  $intRet1 = $objReg.GetStringValue($HKLM, $strKey & $strSubkey,$strEntry1a, $strValue1)

  If $intRet1 <> 0 Then
    $objReg.GetStringValue ($HKLM, $strKey & $strSubkey,      $strEntry1b, $strValue1)

  EndIf
  If $strValue1 <> "" Then
    $strSubkeysRaw = $strSubkeysRaw & $strValue1 & ","
  EndIf
Next

If StringRight($strSubkeysRaw, 1) = ","Then
  $strSubkeysPresort = StringLower(StringLeft($strSubkeysRaw, StringLen($strSubkeysRaw) - 1))
EndIf

$arrSubkeysSort = StringSplit($strSubkeysPresort, ",")

;Sort
For $i = _ArrayMinIndex ($arrSubkeysSort) to UBound($arrSubkeysSort) - 1
  For $j = _ArrayMinIndex ($arrSubkeysSort) to UBound($arrSubkeysSort) - 1
    If $j <> UBound($arrSubkeysSort) - 1 Then
      If $arrSubkeysSort[$j] > $arrSubkeysSort[$j + 1] Then
         $TempValue = $arrSubkeysSort[$j + 1]
         $arrSubkeysSort[$j + 1] = $arrSubkeysSort[$j]
         $arrSubkeysSort[$j] = $TempValue
      EndIf
    EndIf
  Next
Next

ConsoleWrite (@CRLF & "Installed Applications" & @CRLF)

For $strSubkeySort in $arrSubkeysSort
  ConsoleWrite ($strSubkeySort & @CRLF)
Next

;-))

Stefan

Share this post


Link to post
Share on other sites

Perfect man thanks a lot.. your my savior :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0