Jump to content

Recommended Posts

Posted (edited)

In windows installer/msi, we can add custom actions using vbscript directly.

Now, they provide support for powershell also.

pgw56lk2nfd6sxwzg.jpg

Where, we can access data in the installer using this code like properties,product code, installation folder,etc.

But there is no option to use by AutoIT directly.(As far as I know)

So, till now, I am compiling the autoit exe and calling it in msi using below option of launching an exe.

1mow9c7palqc3z7zg.jpg

But, this way, I can't access msi properties inside it.

Any idea on how to access msi data inside it, so that I can disable some msi UI buttons using the autoit code.

 

Edited by ur
  • Developers
Posted

Please simply post the code here in a codebox instead of external images. I for one am reluctant to click on external links to have to look at an image. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Hi @Jos

Sure, but above snaps not of code, I am showing the options in Installshield tool.

And, is there any possibility to increase my attachment limit as it is exceeded.

Posted

If using vbscript we can use properties as in msi embedded code using.

var1 = Session.Property("PROPERTY1")

Session.Property("PROPERTY2")="somedata"

Is there any alternate in autoit for msi like that?

Posted

In the below AutoIT code, I have compiled it as exe and using in the msi customaction type "launch exe from binary table"

The below code will check whether the credentials provided in the installer screens by user are correct or not.

I am passing the data using command line arguments as I don't find option to access msi database from autoit.

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

if ($CmdLine[0]<2) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

if ((StringLen(StringStripWS($CmdLine[1], $STR_STRIPLEADING + $STR_STRIPTRAILING))=0) or (StringLen(StringStripWS($CmdLine[2], $STR_STRIPLEADING + $STR_STRIPTRAILING))=0)) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

$user = StringStripWS($CmdLine[1], $STR_STRIPLEADING + $STR_STRIPTRAILING)
$password = StringStripWS($CmdLine[2], $STR_STRIPLEADING + $STR_STRIPTRAILING)

if ((StringLen($user)=0) or (StringLen($password)=0)) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

$domain = @ComputerName
if(StringInStr($user,"\",2) > 0) then
    if not (StringCompare ( StringSplit($user,"\")[1], ".")=0) then
        $domain = StringSplit($user,"\")[1]
    EndIf
    $user = StringSplit($user,"\")[2]
EndIf

;MsgBox(0,$domain&"\"&$user,$password)

if _ValidUserPass($user,$domain,$password) Then
    Msg("Credentials are working",False)
Else
    Msg("Credentials are Invalid!")
EndIf


Func _ValidUserPass($username, $computer, $password)
    Local $valid = True
    RunAs($username, $computer, $password, 0, @ComSpec & " /c  echo test", @SystemDir, @SW_Hide)
    If @error Then $valid = False
    Return $valid
EndFunc

Func Msg($sMsg,$error=True)
    if ($error=True) then
        MsgBox($MB_ICONERROR,"Authentication Failed!",$sMsg)
    Else
        MsgBox($MB_ICONINFORMATION,"Authentication Successful!",$sMsg)
    EndIf
EndFunc

But now, the user is asking to disable next button if it fails instead of error messages.

So far, so how to achieve this, i.e., to control msi tables data from autoit

Posted

No, I think you mistook me.

In simple words, windows installer (.msi files) are used to install our resources on windows machine.

As installer format provided by Microsoft.

Internally, it is just a set of tables.

Like, file table will  have details where to install and what to install.

Registry table contains what are the registries to apply.

If we need more logic, we can embed any vbscript or powershell files inside it.

As, we can write this vbscript code directly, we can access these msi tables from our vbscript code.Like below.

 var1 = Session.Property("ProductCode")

Like this, is there any option in autoit to access the proerties/any msi table data from autoit code.?

Posted (edited)
1 hour ago, ur said:

As, we can write this vbscript code directly, we can access these msi tables from our vbscript code.Like below.

 var1 = Session.Property("ProductCode")

Like this, is there any option in autoit to access the proerties/any msi table data from autoit code.?

Like this

$sMSI = "YourProduct.msi"
$oInstaller = ObjCreate("WindowsInstaller.Installer")
$oDB = $oInstaller.OpenDataBase($sMSI, 0)
$oView = $oDB.OpenView("SELECT Property,Value FROM Property WHERE Property = 'ProductCode'")
$oView.Execute()
$oRecords = $oView.Fetch
if not IsObj ($oRecords) then Exit MsgBox ($MB_SYSTEMMODAL,"","Error reading msi Table")
$sValue = $oRecords.StringData(2)
ConsoleWrite($sValue & @CRLF)

 

Edited by Nine
Posted
3 hours ago, Nine said:

Like this

$sMSI = "YourProduct.msi"
$oInstaller = ObjCreate("WindowsInstaller.Installer")
$oDB = $oInstaller.OpenDataBase($sMSI, 0)
$oView = $oDB.OpenView("SELECT Property,Value FROM Property WHERE Property = 'ProductCode'")
$oView.Execute()
$oRecords = $oView.Fetch
if not IsObj ($oRecords) then Exit MsgBox ($MB_SYSTEMMODAL,"","Error reading msi Table")
$sValue = $oRecords.StringData(2)
ConsoleWrite($sValue & @CRLF)

 

This is for opening an external msi.
But is there any code for running inside msi itself through custom action?

Posted
2 hours ago, ur said:

But is there any code for running inside msi itself through custom action?

It is like asking to have AutoIt being part of Excel scripting language inside itself.  Can you understand, it is not possible ? But you can do pretty much do all you want outside of it.

  • Developers
Posted

I am still missing the requested  VBS code (not the oneliner) that gets you the information from the installer so we can understand what you do exactly.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I don't have any vbscript code for that.

Just I am telling vbscript as an example.

vbscript and powershell has direct access to msi database if we embed them as custom action(embedded code) inside msi.

 

But, autoit (when I embed the exe launching inside msi custom action), how to get access to the database?

  • Developers
Posted

As i have no knowledge of what you are talking about, and you haven't provided any example of what you say is working in vbs & powershell, there isn't much I can do here as I am not going to spent time of researching this myself. ;)

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

 

On 10/25/2019 at 1:18 PM, ur said:

Is there any alternate in autoit for msi like that?

I dont think you will find any built autoit snippets that deal with msi properties :unsure:

Try maybe  ORCS MSI Editor or searching  msfn

Maybe you will find there some old posts that relate with what you are looking for

 

Posted (edited)

It seems, no support to interact with msi database through autoit directly.

So, at present, I created a vbscript through which I am calling autoit and using the return values from autoit, I am setting the properties of msi (like disabling next button using) using vbscript.

 

My vbscript code.

 

Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim outputFile : outputFile = Session.Property("SUPPORTDIR") & "\autoitexe.exe"

If oFSO.fileExists(outputFile) Then 
    Dim objShell : Set objShell = CreateObject("WScript.Shell") 
    user = Session.Property("SCHEDULERLOCALSYSTEM_USER")
    password = Session.Property("SCHEDULERLOCALSYSTEM_PASSWORD")
    iReturn = objShell.Run(""""&outputFile&""" "& user &" "& password,0,True)
    if (iReturn = 1) then
       'MsgBox iReturn
       Session.Property("SCHEDULER_ENABLE_NEXT") = "0"
       'MsgBox iReturn
    else
        Session.Property("SCHEDULER_ENABLE_NEXT") = "1"
    end if
    Set objShell = Nothing
End If

Set oFSO = Nothing

and the code for my autoit exe.

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

if ($CmdLine[0]<2) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

if ((StringLen(StringStripWS($CmdLine[1], $STR_STRIPLEADING + $STR_STRIPTRAILING))=0) or (StringLen(StringStripWS($CmdLine[2], $STR_STRIPLEADING + $STR_STRIPTRAILING))=0)) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

$user = StringStripWS($CmdLine[1], $STR_STRIPLEADING + $STR_STRIPTRAILING)
$password = StringStripWS($CmdLine[2], $STR_STRIPLEADING + $STR_STRIPTRAILING)

if ((StringLen($user)=0) or (StringLen($password)=0)) Then
  Msg("Please enter both username and password")
  Exit(1)
EndIf

$domain = @ComputerName
if(StringInStr($user,"\",2) > 0) then
    if not (StringCompare ( StringSplit($user,"\")[1], ".")=0) then
        $domain = StringSplit($user,"\")[1]
    EndIf
    $user = StringSplit($user,"\")[2]
EndIf

;MsgBox(0,$domain&"\"&$user,$password)

if _ValidUserPass($user,$domain,$password) Then
    Msg("Credentials are working",False)
    Exit(0)
Else
    Msg("Credentials are Invalid!")
    Exit(1)
EndIf


Func _ValidUserPass($username, $computer, $password)
    Local $valid = True
    RunAs($username, $computer, $password, 0, @ComSpec & " /c  echo test", @SystemDir, @SW_Hide)
    If @error Then $valid = False
    Return $valid
EndFunc

Func Msg($sMsg,$error=True)
    if ($error=True) then
        MsgBox($MB_ICONERROR,"Authentication Failed!",$sMsg)
    Else
        ;MsgBox($MB_ICONINFORMATION,"Authentication Successful!",$sMsg)
    EndIf
EndFunc

 

Thank you very much guys, for your help

Edited by ur
Posted (edited)

why cant the installer use custom actions and do it there in code? or just do it in vbscript--as that looks like your package manager uses (ugh)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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
  • Recently Browsing   0 members

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