Does anyone know why this doesn't work? I found the VBScript below that access the registry and extracts the Install key for windows. The VBScript produces the correct results on WinXP and Win7 64bit.
I tried dumping this into a form and compiling it into an EXE. The VB Code is below. As you can see the code is pretty much the same. The VB code runs fine on WinXP but on Win7 I'm getting an Unable to read registry key error.
I assume it is probably a premissions issue but I'm not sure. I'm running the EXE as an Administrator (right click and run as) and that is the same way I run the VBScript.
Does anyone know why the EXE with pretty much the same code cannot read a registery value that VBScript can?
VBScriptVB6 CodeCode:Set WshShell = CreateObject("WScript.Shell") key = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" digitalId = WshShell.RegRead(key & "DigitalProductId") ProductName = "Product Name : " & WshShell.RegRead(key & "ProductName") & vbNewLine ProductId = "Product Id : " & WshShell.RegRead(key & "ProductId") & vbNewLine ProductKey = "Install Key : " & Converted(digitalId) ProductId = ProductName & ProductId & ProductKey MsgBox ProductId Function Converted(id) Const OFFSET = 52 i = 28 Chars = "BCDFGHJKMPQRTVWXY2346789" Do Cur = 0 x = 14 Do Cur = Cur * 256 Cur = id(x + OFFSET) + Cur id(x + OFFSET) = (Cur \ 24) And 255 Cur = Cur Mod 24 x = x -1 Loop While x >= 0 i = i - 1 Converted = Mid(Chars, Cur + 1, 1) & Converted If (((29 - i) Mod 6) = 0) And (i <> -1) Then i = i -1 Converted = "-" & Converted End If Loop While i >= 0 End FunctionCode:Option Explicit Private Sub Form_Load() Me.AutoRedraw = True Me.Print DecryptKey End Sub Private Function DecryptKey() Const OFFSET = 52 Dim WshShell As Object Dim key As String Dim digitalid Dim i Dim Chars Dim Cur Dim x Dim Converted Set WshShell = CreateObject("WScript.Shell") key = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" digitalid = WshShell.RegRead(key & "DigitalProductId") Set WshShell = Nothing i = 28 Chars = "BCDFGHJKMPQRTVWXY2346789" Do Cur = 0 x = 14 Do Cur = Cur * 256 Cur = digitalid(x + OFFSET) + Cur digitalid(x + OFFSET) = (Cur \ 24) And 255 Cur = Cur Mod 24 x = x - 1 Loop While x >= 0 i = i - 1 Converted = Mid(Chars, Cur + 1, 1) & Converted If (((29 - i) Mod 6) = 0) And (i <> -1) Then i = i - 1 Converted = "-" & Converted End If Loop While i >= 0 DecryptKey = Converted End Function




Reply With Quote