Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Capturing User Input


5 replies to this topic

Zachmc

Zachmc
  • Members
  • 6 posts

Posted 24 May 2001 - 22:18

Greetings --

I am relatively new to InstallShield and need to create a custom action in order to add the input to a text file. Specifically what I want to do is:
1. Pop up/Open a dialog box asking the user to enter the internet domain they are in;
2. Save that input to a variable;
3. Take the variable, append some information to it, and enter the result into a text file (in one case the HOSTS file)
4. Continue with installation

Can anyone offer any suggestions on how best to accomplish this?

Thank you!

Zach Miller-Catlin


Dave I

Dave I
  • Members
  • 195 posts

Posted 25 May 2001 - 11:07

Firstly I pressume you are using InstallShield Windows Installer.

1.) Create a New Dialog (Dialog View)
2.) Drop an "Edit Field" onto the dialog, a dialog will apper "Enter the property for this control" , enter a property in UPPERCASE (MSI help - properties that are to be set by the user interface during the installation and then passed to the execution phase of the installation must be public.) e.g. MYPROP

3.) Modify the behaviour of your dialog to fit in your dialog chain (e.g. Next button - NewDialog NextDialog 1)

InstallScript Function Something-like....

export prototype MyFunc(HWND)

Function MyFunc(hMSI)

1.) Get property, into a variable:
nBuffer=256;
MsiGetProperty(hMSI, "MYPROP", szMyProp, nBuffer);

2.) Write value to file:

OpenFileMode (FILE_MODE_APPEND);
OpenFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_FILE);
WriteLine(nvFileHandle, szMyProp+"Stuff");
CloseFile(nvFileHandle);

You now need to create the CA using the Custom Action Wizard selecting all the defaults and MyFunc() as the installscript function

Add the following entry to the Next button of your dialog

DoAction MyCA 1

If you want any more info let me know,
Dave.
   


Zachmc

Zachmc
  • Members
  • 6 posts

Posted 31 May 2001 - 22:23

Thanks for the suggestion. I have implemented your suggestions as follows:

#include "isrt.h"

// Include Iswi.h for Windows Installer API function prototypes and constants,
// and to declare code for the OnBegin and OnEnd events.
#include "iswi.h"

   // The keyword export identifies MyFunction() as an entry-point function.
   // The argument it accepts must be a handle to the Installer database.
export prototype DomainFunction(HWND);  

   // To Do:  Declare global variables, define constants, and prototype user-
   //         defined and DLL functions here.


///////////////////////////////////////////////////////////////////////////////
//                                                                          
// Function:  DomainFunction
//                                                                          
//  Purpose:  This function will be called by the script engine when
//            Windows™ Installer executes your custom action (see the "To
//            Do," above).
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function DomainFunction(hMSI)  
   // To Do:  Declare local variables.
   nBuffer = 256;
   MsiGetProperty(hMSI, "MYPROP", szMyProp, szBuffer);
   
begin            
   OpenFileMode(FILE_MODE_APPEND);
   OpenFile(nvFileHandle, WINDIR\system32\drivers\etc, HOSTS)
   WriteLine(nvFileHandle, szMyProp+"Stuff");
   CloseFile(nvFileHandle);
   // To Do:  Write script that will be executed when MyFunction is called.

end;

The compilation of that script fails with the following errors:

InstallShield Script Compiler
Version 6.21.100.1396
Copyright © 1990-1998 InstallShield Software Corporation

Compiling...
Setup.rul
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(60) : error C8017: 'nBuffer' : expected typedef (struct) name
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(60) : error C8008: '=' : identifier expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(60) : error C8008: '256' : identifier expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8017: 'msi' : expected typedef (struct) name
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8008: '.' : identifier expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8014: 'MsiGetPropertyA' : identifier already defined
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8062: 'hMSI' : constant operand required
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8008: 'MYPROP' : identifier expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(61) : error C8022: ')' : comma or semicolon expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8025: 'nvFileHandle' : undefined identifier
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8046: 'nvFileHandle' : numeric variable required
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8068: '\' : unrecognized character encountered
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8007: 'system32' : comma expected
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8068: '\' : unrecognized character encountered
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(65) : error C8068: '\' : unrecognized character encountered
C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul(67) : error C8025: 'nvFileHandle' : undefined identifier
Setup.obs - 16 error(s), 0 warning(s)
Compiled script C:\WINNT\Profiles\zmillercatlin\Personal\MySetups\DialogTest\Setup.rul

Can you perhaps suggest some resolutions for these problems?

Thanks!

Zach


Leigh Ravenhall

Leigh Ravenhall
  • Members
  • 269 posts

Posted 31 May 2001 - 23:47

The area between function and begin is used to declare variables, not  assign them a value.

For example:
NUMBER nBuffer;
STRING szMyProp;

You then set these values after the begin.  You'll also need to declare a number for the file handle.


vaqueros

vaqueros
  • Full Members
  • 53 posts

Posted 29 October 2003 - 17:46

I tried it myself and I don't get any error messages but still the property value is not written to the file. All I get is a blank line where the property value should be written. I even tried with normal property value like USERNAME with same results.
===========

nBuffer = 256;
MsiGetProperty(hMSI, "USERNAME", szUser, szBuffer);
MsiGetProperty(hMSI, "COMPANYNAME", szCompany, szBuffer);
MsiGetProperty(hMSI, "LICENSEKEY", szLicense, szBuffer);
szPath = "C:\\Test";
szFileName= "test.txt";
szLine1 = "Begin Line 1\r\n";
szLine2 = "\r\n" +
"End of entry";

// Set the file mode to append.
OpenFileMode (FILE_MODE_APPEND);

// Create a new file and leave it open.
if (CreateFile (nvFileHandle, szPath, szFileName) < 0) then
// Report the error.
MessageBox ("CreateFile failed.", SEVERE);
abort;
else
// Set the message to write to the file.
szMsg = "This line was appended by an example InstallShield script.";

// Append the message to the file.
if (WriteLine(nvFileHandle, szLine1+szUser+szLine2) < 0) then
// Report the error.
MessageBox ("WriteLine failed.", SEVERE);
else
// Report success.
szTitle = "CreateFile & WriteLine";
szMsg = "Successfully added %s to %s.";
SprintfBox (INFORMATION, szTitle, szMsg, szUser, szFileName);
endif;

endif;




Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 31 October 2003 - 10:10

Your MsiGetProperty look wrong. You must pass in nBuffer.