Save entered text to TXT file in Inno Setup - inno-setup

I have to save username and password which typed by user to text file but it create text file and save the texts before user type it. (So empty text file is created).
I think I have to do somethings with procedure but although I search the solution, I couldn't find.
My code:
[Code]
var
Page: TInputQueryWizardPage;
username: String;
password: String;
procedure InitializeWizard;
begin
{ Create the page }
Page := CreateInputQueryPage(wpWelcome,
'Username & Password', 'Username like : e201600',
'Please enter your username and password.');
{ Add items (False means it's not a password edit) }
Page.Add('Username:', False);
Page.Add('Password:', True);
{ Set initial values (optional) }
Page.Values[0] := ExpandConstant('hello5');
Page.Values[1] := ExpandConstant('');
{ Read values into variables }
username := Page.Values[0];
password := Page.Values[1];
SaveStringToFile('c:\filename.txt', username+#13#10+password+#13#10, False);
end;

You are creating the input page when installer starts and immediately saving the fields into text file.
You need to wait while user enters the data and clicks Next button on correct page:
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if(CurPageID = Page.ID) then
begin
{ Process the page }
{ Read values into variables }
username := Page.Values[0];
password := Page.Values[1];
SaveStringToFile('c:\filename.txt', username+#13#10+password+#13#10, False);
end;
Result := True;
end;
And few tips: saving names/passwords is not safe! Also using hardcoded path is reallly unusual...

Related

Getting "You must enter a name" and "Cannot focus a disabled or invisible window" on some machines with hidden UserInfoPage Inno Setup page

I have made a quick installer and in some PC I have found problems when installing. I have "serial number" system and when I press "Next" it gives me an error
You must enter a name
and then:
Cannot focus a disabled or invisible window
But in many other PCs with same SO this works normal. This is the code that I am using:
[Setup]
WizardStyle=modern
UserInfoPage=yes
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpUserInfo then begin
WizardForm.UserInfoOrgLabel.Hide();
WizardForm.UserInfoOrgEdit.Hide();
WizardForm.UserInfoNameLabel.Hide();
WizardForm.UserInfoNameEdit.Hide();
end;
end;
// Presence of the CheckSerial event function displays the serial number box.
// But here we accept any non-empty serial.
// We will validate it only in the NextButtonClick,
// as the online validation can take long.
function CheckSerial(Serial: String): Boolean;
begin
Result := (Serial <> '');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
WinHttpReq: Variant;
Url: string;
begin
Result := True;
if CurPageID = wpUserInfo then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
Url := 'Link that i use to check the serial number' +
WizardForm.UserInfoSerialEdit.Text;
WinHttpReq.Open('GET', Url, False);
WinHttpReq.Send('');
// Depending on implementation of the server,
// use either HTTP status code (.Status)
// or contents of returned "page" (.ResponseText)
// Here we use the HTTP status code:
// 200 = serial is valid, anything else = serial is invalid,
// and when invalid, we display .ResponseText
Result := (WinHttpReq.Status = 200);
if not Result then
MsgBox(WinHttpReq.ResponseText, mbError, MB_OK);
end;
end;
With UserInfoPage enabled, filling in the "User name" box is mandatory. The box is pre-filled with a value of RegisteredOwner registry value. If that value happens to be empty, and consequently the box, you cannot leave the page, until you fill it in manually. You get the "You must enter a name" error and Inno Setup moves the focus to the box. That fails with "Cannot focus a disabled or invisible window", as you have the box hidden.
If you do not care about the username, just fill in some dummy value:
WizardForm.UserInfoNameEdit.Text := 'foo';

Install App in VERYSILENT mode with command line which written with inno setup script

How Should i modify my code so i can let user detemine the path of second directory (path of java in script)
I used this Command befor i try in mode:
mysetup.exe /DIR="C:\test"
installation path
second path
And how to let user to choose one of these Component1 or component2 or both.
choose component to be installed
#define AppName "My App"
[Setup]
AppName={#AppName}
AppVersion=1
DefaultDirName={code:getInstallDir}\{#AppName}
;DefaultDirName={pf}\My App
DisableDirPage=yes
[Files]
[Code]
#include 'System.iss'
var
Page: TInputDirWizardPage;
UsagePage: TInputOptionWizardPage;
function InputDirPageNextButtonClick(Sender: TWizardPage): Boolean;
begin
{ Use the first path as the "destination path" }
WizardForm.DirEdit.Text := Page.Values[0];
Result := True;
end;
procedure InitializeWizard;
begin
Page := CreateInputDirPage(wpWelcome,
'Destination', '',
'Where should App be installed?',
False, 'New Folder');
Page.Add('App path');
Page.Values[0] := WizardForm.DirEdit.Text;
UsagePage := CreateInputOptionPage(wpWelcome,
'Installation', 'choose component',
'please choose one!:',
False, False);
UsagePage.Add('Component1');
UsagePage.Add('Component2');
Page.OnNextButtonClick := #InputDirPageNextButtonClick;
Page := CreateInputDirPage(wpSelectDir,
'Java path', '',
'please specify Java Folder:', False, '');
Page.Add('Java');
Page.OnNextButtonClick := #InputDirPageNextButtonClick;
end;
If I understand your question: You are looking for a way to use a custom command-line parameter to populate the directory value on a custom directory page. Here's one way:
[Code]
var
CustomPage: TInputDirWizardPage;
CustomPath: string;
function InitializeSetup(): Boolean;
begin
result := true;
CustomPath := ExpandConstant('{param:CustomPath}');
end;
procedure InitializeWizard();
begin
CustomPage := CreateInputDirPage(wpSelectDir,
'Select Custom Path',
'What custom path do you want?',
'Select a directory.',
false,
'');
CustomPage.Add('Custom path:');
CustomPage.Values[0] := CustomPath;
end;
With this in your [Code] section, running the setup program with a /CustomPath="directory name" parameter will set the value on the form to the parameter from the command line.

Inno Setup: CreateInputQueryPage isn't returning any value

Here is the script I'm using on Inno Setup. It is my first script, please understand if I'm asking something obvious.
It seems that the variable ServerAddress never has a value, even if I fill the input field. It looks like Page.Values[0] always returns an empty result. What is wrong with my code?
As you can see, I have made a test with a testvar variable to exclude it was a matter of variable scope, but it's not the case.
[Code]
var
Page: TInputQueryWizardPage;
ServerAddress: String;
testvar: String;
procedure InitializeWizard();
begin
Page := CreateInputQueryPage(wpWelcome,
'Server Informations', '',
'Please specify the IP address, then click Next.');
{ Add items (False means it's not a password edit) }
Page.Add('IP Address:', False);
ServerAddress := Page.Values[0];
testvar := 'testvalue';
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then begin
MsgBox(ExpandConstant('{app} '+testvar+' : '+ServerAddress),mbInformation,MB_OK);
SaveStringToFile(ExpandConstant('{app}')+'\config.txt', 'test'+ServerAddress, True);
end;
end;
The InitializeWizard event function is called (and finishes) before the wizard window is even shown.
So a value (that the user will enter in the future) can hardly be known at that point. You have to read the value only after the custom page is shown. Like in your CurStepChanged(ssPostInstall):
procedure CurStepChanged(CurStep: TSetupStep);
var
ServerAddress: string;
begin
if CurStep = ssPostInstall then
begin
{ This is the right time to read the value }
ServerAddress := Page.Values[0];
SaveStringToFile(ExpandConstant('{app}') + '\config.txt', ServerAddress, True);
end;
end;

The Inno Setup action I want after CreateInputQueryPage happens before. Why?

When Running my Inno Setup built installer, the action that I want to have happen as a result of selections in the CreateInputQueryPage happens before the CreateInputQueryPage opens and gets input from the user. What concept am I missing?
Is it that I need to use NextButtonClick?
Here is my Pascal code based on code taken from (http://www.jrsoftware.org/ishelp):
[Code]
procedure UserGroup;
Var Page : TInputQueryWizardPage;
GroupName : String;
Message: String;
ResultCode: Integer;
begin
// Create page
Page := CreateInputQueryPage(wpWelcome,
'Users Group Required',
'Please specify group, then click Next',
'A Windows security group must be created.'
);
// Add items (False means it's not a password edit)
Page.Add('GroupName:', False);
Page.Values[0] := 'SomeGroup';
// Read values into variables
GroupName := Page.Values[0];
if Exec('net.exe', Format( 'localgroup %s /add',[GroupName]), '', SW_SHOW,
ewWaitUntilTerminated, ResultCode) then
begin
// success
Message := Format('The user group %s has been added to the local machine.', [GroupName]);
MsgBox( Message, mbInformation, MB_OK);
end
else begin
// failure i
Message := Format('The installer was not able to set up the %s security group. Please do so manually. (Inno Error Code: %i)', [GroupName, ResultCode]);
MsgBox( Message, mbInformation, MB_OK);
end;
end;
But the MsgBox shows before the CreateInputQueryPage does.

Inno Setup: How to pass variable from [Code] to [Run] (or other section)

How can I pass a variable from [Code] section to parameters in [Run] section in Inno Setup?
Basically, I want to do the following.
Get and save user input to a variable in a procedure InitializeWizard.
Pass the user input to an executable in [Run] section
Here is my code.
[Run]
Filename: "someProgram.exe"; Parameters: ??userInput??
[Code]
procedure InitializeWizard;
var
ConfigPage: TInputQueryWizardPage;
UserInput: String;
begin
{ Create the page }
ConfigPage :=
CreateInputQueryPage(
wpWelcome, 'User input', 'User input',
'Please specify the following information, then click Next.');
{ Add items (False means it's not a password edit) }
ConfigPage.Add('Input here:', False);
{ Set initial values (optional) }
ConfigPage.Values[0] := ExpandConstant('hello');
{ Read values into variables }
UserInput := ConfigPage.Values[0];
end;
Thanks.
You're looking for the scripted constant. See the following example:
[Run]
Filename: "SomeProgram.exe"; Parameters: {code:GetParams}
[Code]
var
ConfigPage: TInputQueryWizardPage;
function GetParams(Value: string): string;
begin
Result := ConfigPage.Values[0];
end;
procedure InitializeWizard;
begin
{ Create the page }
ConfigPage :=
CreateInputQueryPage(
wpWelcome, 'User input', 'User input',
'Please specify the following information, then click Next.');
{ Add items (False means it's not a password edit) }
ConfigPage.Add('Input here:', False);
{ Set initial values (optional) }
ConfigPage.Values[0] := ExpandConstant('hello');
end;

Resources