Jump to content

Vbscript Conversion Help


Recommended Posts

sComputer = "."   '  use "." for local computer 
iOfficeVer = GetOfficeVer(sComputer) 

If iOfficeVer = -1 Then 
  WScript.Echo "Version of Office installed is unknown, could not connect to the remote computer." 
Elseif iOfficeVer = 0 Then 
  WScript.Echo "Not Installed" 
Else 
  WScript.Echo "Microsoft Office " & iOfficeVer 
End If 

Function GetOfficeVer(sNode) 
  On Error Resume Next 
  Const HKLM = &H80000002 ' HKEY_LOCAL_MACHINE 
  Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sNode & "/root/default:StdRegProv") 
  If Err.Number <> 0 Then 
    GetOfficeVer = -1 
    Exit Function  '-------> 
  End If 

  sValueName = "Path" 
  sRegPre = "SOFTWARE\Microsoft\Office\" 
  sRegPost = "\Common\InstallRoot" 

  If oReg.GetStringValue(HKLM, sRegPre & "11.0" & sRegPost, sValueName, sValue) = 0 Then 
    GetOfficeVer = 2003 
  Elseif oReg.GetStringValue(HKLM, sRegPre & "10.0" & sRegPost, sValueName, sValue) = 0 Then 
    GetOfficeVer = 2002 
  Elseif oReg.GetStringValue(HKLM, sRegPre & "9.0" & sRegPost, sValueName, sValue) = 0 Then 
    GetOfficeVer = 2000 
  Elseif oReg.GetStringValue(HKLM, sRegPre & "8.0" & sRegPost, sValueName, sValue) = 0 Then 
    GetOfficeVer = 97 
  Else 
    GetOfficeVer = 0 
  End If 
End Function

I've tried, but to no avail. Wondering if any of you gurus can make it happen. Thanks!

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

Here's some pointers on how to do it on your own:

Look in the helpfile at the following functions.

RegRead and MsgBox

That appears to be the only funtions you need...

Also, all variables in au3 start with $

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Here's some pointers on how to do it on your own:

Look in the helpfile at the following functions.

RegRead and MsgBox

That appears to be the only funtions you need...

Also, all variables in au3 start with $

I've got that much, I actually have it converted, so I thought... Here's the code. It errors, and I'm not sure what I did wrong.

Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20
$sComputer = "."  ;Use "." for local computer
$iOfficeVer = GetOfficeVer($sComputer)

If $iOfficeVer = -1 Then
  MsgBox(16, "", "Version of Office installed is unknown, could not connect to the remote computer.")
Elseif iOfficeVer = 0 Then
  MsgBox(16, "", "Not Installed")
Else
  MsgBox(16, "", "Microsoft Office " & $iOfficeVer)
EndIf

Func GetOfficeVer($sNode)
 ; On Error Resume Next
  Const $HKLM = "&H80000002"; HKEY_LOCAL_MACHINE

  $objRegistry = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sNode & "\root\default:StdRegProv")
  If @Error <> 0 Then
    $GetOfficeVer = -1
    Return
  EndIf

  $sValue = ""
  $sValueName = "Path"
  $sRegPre = "SOFTWARE\Microsoft\Office\"
  $sRegPost = "\Common\InstallRoot"

  If $objRegistry.GetStringValue($HKLM, $sRegPre & "11.0" & $sRegPost, $sValueName, $sValue) = 0 Then
    $GetOfficeVer = 2003
  Elseif $objRegistry.GetStringValue($HKLM, $sRegPre & "10.0" & $sRegPost, $sValueName, $sValue) = 0 Then
    $GetOfficeVer = 2002
  Elseif $objRegistry.GetStringValue($HKLM, $sRegPre & "9.0" & $sRegPost, $sValueName, $sValue) = 0 Then
    $GetOfficeVer = 2000
  Elseif $objRegistry.GetStringValue($HKLM, $sRegPre & "8.0" & $sRegPost, $sValueName, $sValue) = 0 Then
    $GetOfficeVer = 97
  Else
    $GetOfficeVer = 0
  EndIf
EndFunc
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

You didnt do what cdkid said.

You are using $objRegistry.GetStringValue instead of RegRead.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

cdkid was completely correct in that, sure, WMI scripting is extremely useful for some things, but in this case, AutoIt has a built in function, RegRead() which accomplishes the same task:

If RegRead("HKLM\Software\Microsoft\Office\11.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2003")
ElseIf RegRead("HKLM\Software\Microsoft\Office\10.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2002")
ElseIf RegRead("HKLM\Software\Microsoft\Office\9.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2000")
ElseIf RegRead("HKLM\Software\Microsoft\Office\8.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 97")
Else
    MsgBox(0,"Office Version", "Office Version could not be determined.")
EndIf

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

cdkid was completely correct in that, sure, WMI scripting is extremely useful for some things, but in this case, AutoIt has a built in function, RegRead() which accomplishes the same task:

If RegRead("HKLM\Software\Microsoft\Office\11.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2003")
ElseIf RegRead("HKLM\Software\Microsoft\Office\10.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2002")
ElseIf RegRead("HKLM\Software\Microsoft\Office\9.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 2000")
ElseIf RegRead("HKLM\Software\Microsoft\Office\8.0\Common\InstallRoot", "Path") <> "" Then 
    MsgBox(0,"Office Version", "Microsoft Office 97")
Else
    MsgBox(0,"Office Version", "Office Version could not be determined.")
EndIf
I thought RegRead would only do local, not remote computers... Does it work well remotely?

Edit: Right, thanks all!

Edited by RagnaroktA
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...