Inno Setup check if a machine is joined to a Domain - inno-setup

Is there a way of checking whether the machine you are installing on is joined to a Domain or in a Workgroup?
I found this article about how to do this in Delphi, but I am unable to get this working within Inno Setup. Can anyone assist with this? Is this even possible?
http://delphi.about.com/od/delphitips2009/qt/computer-in-a-domain.htm

I would translate (and shorten) it this way:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
const
NERR_BASE = 2100;
NERR_SetupNotJoined = NERR_BASE + 592;
type
NET_API_STATUS = DWORD;
function NetRenameMachineInDomain(lpServer: WideString;
lpNewMachineName: WideString; lpAccount: WideString;
lpPassword: WideString; fRenameOptions: DWORD): NET_API_STATUS;
external 'NetRenameMachineInDomain#netapi32.dll stdcall';
function IsInDomain: Boolean;
begin
Result := NetRenameMachineInDomain('', '', '', '', 0) <> NERR_SetupNotJoined;
end;
procedure InitializeWizard;
begin
if IsInDomain then
MsgBox('Is in domain.', mbInformation, MB_OK)
else
MsgBox('Is not in domain.', mbInformation, MB_OK);
end;

Related

How do I copy the Inno Setup log file to a certain destination after setup is done?

I have asked chat.openai how to copy the log path to a certain path after it's done setupping.
It proposed this, but I think it's wrong. It expects the log file to be in {app}\SetupLog.log", but I don't think it's there.
Here is what it proposed.
Can somebody correct it?
I do not set the log path from outside. It will be the default path.
I can not change that unfortunately. And when the installation is done, the temp installation folder is deleted, so I don't have a chance to view the log file.
Thank you!
#define LogFileName "SetupLog.log"
#define LogDestination "C:\MyLogs"
[Setup]
DefaultDirName={pf}\My Application
DefaultGroupName=My Application
[Files]
Source: "MyApp.exe"; DestDir: "{app}"
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
LogPath: string;
DestinationPath: string;
begin
if CurStep = ssPostInstall then
begin
LogPath := ExpandConstant('{app}\SetupLog.log');
DestinationPath := ExpandConstant(LogDestination + '\SetupLog.log');
if FileCopy(LogPath, DestinationPath, false) then
MsgBox('Log file was copied successfully to ' + DestinationPath, mbInformation, MB_OK)
else
MsgBox('Failed to copy log file to ' + DestinationPath, mbError, MB_OK);
end;
end;
There is a Q & A about this because I asked at one time. I can't find it.
But, this is the code I am now using:
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: integer;
strLogFilePathName, strLogFileName, strNewFilePathName: string;
begin
if (CurStep = ssDone) then
begin
strLogFilePathName := ExpandConstant('{log}');
strLogFileName := ExtractFileName(strLogFilePathName);
strNewFilePathName := ExpandConstant('{#CommonDataDir}\Installation Logs\') + strLogFileName;
FileCopy(strLogFilePathName, strNewFilePathName, false);
end;
end;
Change the folder to copy the log to as required. Notice that I am using ssDone.

Open external program inside Inno Setup window

I have some animations in Exe format, I need to load them inside a panel in Inno Setup.
I have found these about Delphi:
http://www.delphipages.com/forum/archive/index.php/t-200729.html
How to shell to another app and have it appear in a delphi form
How to implement such thing in Inno Setup?
An equivalent code for Inno Setup will be like:
[Code]
function SetParent(hWndChild: HWND; hWndNewParent: HWND): HWND;
external 'SetParent#User32.dll stdcall';
function ShowWindow(hWnd: HWND; nCmdShow: Integer): BOOL;
external 'ShowWindow#User32.dll stdcall';
procedure InitializeWizard();
var
Page: TWizardPage;
ResultCode: Integer;
ProgHandle: HWND;
begin
Page := CreateCustomPage(wpWelcome, 'Test', '');
Exec('notepad.exe', '', '', SW_HIDE, ewNoWait, ResultCode);
while ProgHandle = 0 do
ProgHandle := FindWindowByWindowName('Untitled - Notepad');
SetParent(ProgHandle, Page.Surface.Handle);
ShowWindow(ProgHandle, SW_SHOWMAXIMIZED);
end;
Though I suggest you do not do this. It's an unreliable hack. Display the images by the Pascal Code in the installer itself.

Conditional reboot in innosetup installer [duplicate]

My Inno Setup script is used to install a driver. It runs my InstallDriver.exe after this file was copied during step ssInstall.
I need to ask the user to restart in some cases according to the value returned by InstallDriver.exe.
This means that I cannot put InstallDriver.exe in section [Run] because there's no way to monitor it's return value.
So I put it in function CurStepChanged() as follows:
procedure CurStepChanged(CurStep: TSetupStep);
var
TmpFileName, ExecStdout, msg: string;
ResultCode: Integer;
begin
if (CurStep=ssPostInstall) then
begin
Log('CurStepChanged(ssPostInstall)');
TmpFileName := ExpandConstant('{app}') + '\InstallDriver.exe';
if Exec(TmpFileName, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then .......
However, I can't find a way to make my script restart at this stage.
I thought of using function NeedRestart() to monitor the output of the driver installer, but it is called earlier in the process.
Does it make sense to call the driver installer from within NeedRestart()?
NeedRestart does not look like the right place to install anything. But it would work, as it's fortunately called only once. You will probably want to present a progress somehow though, as the wizard form is almost empty during a call to NeedRestart.
An alternative is to use AfterInstall parameter of the InstallDriver.exe or the driver binary itself (whichever is installed later).
#define InstallDriverName "InstallDriver.exe"
[Files]
Source: "driver.sys"; DestDir: ".."
Source: "{#InstallDriverName}"; DestDir: "{app}"; AfterInstall: InstallDriver
[Code]
var
NeedRestartFlag: Boolean;
const
NeedRestartResultCode = 1;
procedure InstallDriver();
var
InstallDriverPath: string;
ResultCode: Integer;
begin
Log('Installing driver');
InstallDriverPath := ExpandConstant('{app}') + '\{#InstallDriverName}';
if not Exec(InstallDriverPath, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
Log('Failed to execute driver installation');
end
else
begin
Log(Format('Driver installation finished with code %d', [ResultCode]))
if ResultCode = NeedRestartResultCode then
begin
Log('Need to restart to finish driver installation');
NeedRestartFlag := True;
end;
end;
end;
function NeedRestart(): Boolean;
begin
if NeedRestartFlag then
begin
Log('Need restart');
Result := True;
end
else
begin
Log('Do not need restart');
Result := False;
end;
end;

How to get the full computer name in Inno Setup

I would like to know how to get the Full computer name in Inno Setup, for example Win8-CL01.cpx.local in the following image.
I already know how to get the computer name with GetComputerNameString but I also would like to have the Domain name of the computer. How can I get this full computer name or this domain name ?
There's no built-in function for this in Inno Setup. You can use the GetComputerNameEx Windows API function:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
const
ERROR_MORE_DATA = 234;
type
TComputerNameFormat = (
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
);
function GetComputerNameEx(NameType: TComputerNameFormat; lpBuffer: string; var nSize: DWORD): BOOL;
external 'GetComputerNameEx{#AW}#kernel32.dll stdcall';
function TryGetComputerName(Format: TComputerNameFormat; out Output: string): Boolean;
var
BufLen: DWORD;
begin
Result := False;
BufLen := 0;
if not Boolean(GetComputerNameEx(Format, '', BufLen)) and (DLLGetLastError = ERROR_MORE_DATA) then
begin
SetLength(Output, BufLen);
Result := GetComputerNameEx(Format, Output, BufLen);
end;
end;
procedure InitializeWizard;
var
Name: string;
begin
if TryGetComputerName(ComputerNameDnsFullyQualified, Name) then
MsgBox(Name, mbInformation, MB_OK);
end;
With built-in functions you can get the full name this way:
[Code]
procedure InitializeWizard;
begin
MsgBox(GetComputerNameString + '.' + GetEnv('UserDnsDomain'), mbInformation, MB_OK);
end;
Although TLama's solution gives you wider possibilities of further development.

Playing mp3 through Inno Media Player fails

I tried to add mp3 audio playback (LAME encoded) to my Inno setup program using Inno Media Player and following #TLama's decription -> https://stackoverflow.com/a/12360780/3838926. I use Windows 7 64bit with Unicode Inno.
Unfortunately it fails: When opening the installer I get the following error message: TDirectShowPlayer error: -2147220890; Searching through Google didn't help.
What do I do wrong? Is it a bug in the program? I'm clueless...
Here's the exact code:
const
EC_COMPLETE = $01;
type
TDirectShowEventProc = procedure(EventCode, Param1, Param2: Integer);
function DSGetLastError(var ErrorText: WideString): HRESULT;
external 'DSGetLastError#files:mediaplayer.dll stdcall';
function DSPlayMediaFile: Boolean;
external 'DSPlayMediaFile#files:mediaplayer.dll stdcall';
function DSStopMediaPlay: Boolean;
external 'DSStopMediaPlay#files:mediaplayer.dll stdcall';
function DSSetVolume(Value: LongInt): Boolean;
external 'DSSetVolume#files:mediaplayer.dll stdcall';
function DSInitializeAudioFile(FileName: WideString;
CallbackProc: TDirectShowEventProc): Boolean;
external 'DSInitializeAudioFile#files:mediaplayer.dll stdcall';
procedure OnMediaPlayerEvent(EventCode, Param1, Param2: Integer);
begin
if EventCode = EC_COMPLETE then
begin
// playback is done, so you can e.g. play the stream again, play another
// one using the same code as in InitializeWizard (in that case would be
// better to wrap that in some helper function) or do just nothing
end;
end;
procedure InitializeWizard;
var
ErrorCode: HRESULT;
ErrorText: WideString;
begin
ExtractTemporaryFile('InDeep.mp3');
if DSInitializeAudioFile(ExpandConstant('{tmp}\InDeep.mp3'),
#OnMediaPlayerEvent) then
begin
DSSetVolume(-2500);
DSPlayMediaFile;
end
else
begin
ErrorCode := DSGetLastError(ErrorText);
MsgBox('TDirectShowPlayer error: ' + IntToStr(ErrorCode) + '; ' +
ErrorText, mbError, MB_OK);
end;
end;
procedure DeinitializeSetup;
begin
DSStopMediaPlay;
end;
InDeep.mp3 is my audio file.
Thanks in advance!!

Resources