rm4453 Posted March 22, 2019 Share Posted March 22, 2019 10 minutes ago, AasimPathan said: Hi, Well I got it work but i'll paste the script here just in case you want to see if i might get any issues. expandcollapse popup#include <AutoItConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <Misc.au3> #include <Crypt.au3> #include <File.au3> #include <StringConstants.au3> ;Minimum required version of the Matrix Code Base is 1.0.3.0 ;This script will not function if the version is lower than the above Global $Username = "ServerAdmin" Global $UsernameEncrypted = StringEncrypt(True, $Username, 'rando') MsgBox("", "", "ENCRYPTED USERNAME: " & $UsernameEncrypted & " DECRYPTED USERNAME: " & StringEncrypt(False, $UsernameEncrypted, 'rando')) Global $Password = "PasswordInPlain" ;I am trying to see if we can encypt this and any passwords we use in AutoIt but for now its set as plain text Global $Domain = "Domain" ;The above login is required to execute the installer, if the credentials are not provided then the installer will prompt each user to enter a username & password and therefore fail to install since standard users do not have any rights to install a software Global $MSIPath = "A:\SomePath\SomeFolder\SomeSubFolder\MatrixCodeBase.msi" ; MSI Package path Global $GetMSIVersion = QueryMSIPackage($MSIPath, 'ProductVersion') ; get the version info of the msi installer Global $GetInstalledVersion = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8B3DFDFF-D894-4A31-AA92-824729385F15}", "DisplayVersion") ; get the version info of the installed software. While 1 Sleep(25) If $GetInstalledVersion = @error Then InstallMatrixCodeBase() ElseIf $GetMSIVersion = $GetInstalledVersion Then Exit ElseIf $GetMSIVersion <> $GetInstalledVersion Then InstallMatrixCodeBase() EndIf ExitLoop WEnd Func CloseRunningOfficePrograms() ;Closes all Running Microsoft Office Programs If ProcessExists("EXCEL.EXE") Then ProcessClose("EXCEL.EXE") If ProcessExists("OUTLOOK.EXE") Then ProcessClose("OUTLOOK.EXE") If ProcessExists("POWERPNT.EXE") Then ProcessClose("POWERPNT.EXE") If ProcessExists("VISIO.EXE") Then ProcessClose("VISIO.EXE") If ProcessExists("WINWORD.EXE") Then ProcessClose("WINWORD.EXE") InstallMatrixCodeBase() EndFunc ;==>CloseRunningOfficePrograms Func InstallMatrixCodeBase() ;Install Matrix Code Base FileCopy("A:\SomePath\SomeFolder\SomeSubFolder\MatrixCodeBase.msi", "C:\Install") RunAsWait($user, $Domain, $pass, 0, "msiexec /i C:\Install\MatrixCodeBase.msi /passive") EndFunc ;==>InstallMatrixCodeBase Func QueryMSIPackage($sMSI, $PropertyName) ; Query the MSI installer to get installer properties If FileExists($MSIPath) And $PropertyName <> '' Then Local $Query = "SELECT Value FROM Property WHERE Property = '" & $PropertyName & "'" $oInstaller = ObjCreate("WindowsInstaller.Installer") $oDB = $oInstaller.OpenDataBase($sMSI, 0) $oView = $oDB.OpenView($Query) $oView.Execute() $oRecords = $oView.Fetch $oPropValue = $oRecords.StringData(1) If $oPropValue <> "" Then Return $oPropValue EndIf EndIf Return "" EndFunc ;==>QueryMSIPackage Func _ComError($oMyError) ;COM Error function defined in COM Error Handler used in COM functions. MsgBox(16, "AutoItCOM ERROR!", "COM Error Intercepted!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext) EndFunc Func StringEncrypt($bEncrypt, $sData, $sPassword) _Crypt_Startup() ; Start the Crypt library. Local $vReturn = '' If $bEncrypt Then ; If the flag is set to True then encrypt, otherwise decrypt. $vReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_RC4) Else $vReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_RC4)) EndIf _Crypt_Shutdown() ; Shutdown the Crypt library. Return $vReturn EndFunc ;==>StringEncrypt 4 I updated your code in above quote to include encryption... (i recommend running it how it is with correct user / pass etc to initially encrypt and output the encrypted text via a msgbox from there modify your code to only decrypt the already encoded user / pass etc) if that makes sense... Link to comment Share on other sites More sharing options...
AasimPathan Posted March 27, 2019 Author Share Posted March 27, 2019 On 3/22/2019 at 4:38 PM, rm4453 said: I updated your code in above quote to include encryption... (i recommend running it how it is with correct user / pass etc to initially encrypt and output the encrypted text via a msgbox from there modify your code to only decrypt the already encoded user / pass etc) if that makes sense... #include <AutoItConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <Misc.au3> #include <Crypt.au3> #include <File.au3> #include <StringConstants.au3> Local $Username = "UsernameToEncrypt" Local $UsernameEncrypted = StringEncrypt(True, $Username, 'rando') MsgBox("", "", "ENCRYPTED USERNAME: " & $UsernameEncrypted & " DECRYPTED USERNAME: " & StringEncrypt(False, $UsernameEncrypted, 'rando')) Local $Password = "PasswordToEncrypt" Local $PasswordEncrypted = StringEncrypt(True, $Password, 'rando') MsgBox("", "", "ENCRYPTED Password: " & $PasswordEncrypted & " DECRYPTED Password: " & StringEncrypt(False, $PasswordEncrypted, 'rando')) The Above doesnot work as you provided the code in the above post. Error (12) : ==> Unknown function name.: Local $UsernameEncrypted = StringEncrypt(True, $Username, 'rando') Local $UsernameEncrypted = ^ ERROR Link to comment Share on other sites More sharing options...
AasimPathan Posted March 28, 2019 Author Share Posted March 28, 2019 (edited) Solved it.. Thanks. It was my mistake didn't past the Func() 😩 Edited March 29, 2019 by AasimPathan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now