I have the path to an executable which is a running service application.
For example: C:\Program Files (x86)\Someapp\somesvc.exe
I want to stop and start it, and for that I suppose I need to get the name of the service as it is outlined in [this] answer.
I might get this by iterating trough all the registry entries of all the services at HKLM\System\CurrentControlSet\Services, and checking if the ImagePath registry key matches my executable path.
This solution should work, but it seems wrong to me. Is there a better way to do this?
Use EnumServicesStatus() or EnumServicesStatusEx() to enumerate installed services. That will give you the name of each service, but not its ImagePath. To retrieve that, you can open each service using OpenService(SERVICE_QUERY_CONFIG) and then get its ImagePath using QueryServiceConfig().
You can query to WMI for services that PathName is like your path.
NOTE: Some path include params. You can't use equal (use Like).
You can use some code like this to query WMI:
//-----------------------------------------------------------------------------------------------------
// This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.9.9.350
// http://code.google.com/p/wmi-delphi-code-creator/
// Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
// Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2015
//-----------------------------------------------------------------------------------------------------
//
// LIABILITY DISCLAIMER
// THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
// YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
// DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
//
//----------------------------------------------------------------------------------------------------
program GetWMI_Info;
{$APPTYPE CONSOLE}
uses
SysUtils,
ActiveX,
ComObj,
Variants;
// La clase Win32_Service representa un servicio en un sistema Win32. Un
// aplicación de servicio cumple las reglas de la interfaz del Administrador de
// control de servicios (SCM, Service Control Manager) y un usuario la puede
// iniciar automáticamente al arrancar el sistema a través del programa Servicios
// del Panel de control o mediante una aplicación que utilice las funciones de
// servicio de la API de Win32. Los servicios se pueden ejecutar aunque ningún
// usuario haya iniciado sesión en el sistema.
procedure GetWin32_ServiceInfo(sPath:String);
const
WbemUser ='';
WbemPassword ='';
WbemComputer ='localhost';
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_Service WHERE PathName like "%' + sPath + '%"','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('Caption %s',[String(FWbemObject.Caption)]));// String
Writeln(Format('DisplayName %s',[String(FWbemObject.DisplayName)]));// String
Writeln(Format('Name %s',[String(FWbemObject.Name)]));// String
Writeln(Format('PathName %s',[String(FWbemObject.PathName)]));// String
Writeln('');
FWbemObject:=Unassigned;
end;
end;
begin
try
CoInitialize(nil);
try
GetWin32_ServiceInfo(ExtractFileName('c:\windows\system\locator.exe'));
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
If you need more properties, add to precedure.
For query with: 'c:\windows\system\locator.exe', you obtain:
For query with: 'C:\Program Files (x86)\Skype\Updater\Updater.exe', you obtain:
For Start and Stop the service, tou need the property Name.
Related
I built a program in pascal using FPC but after this I installed lazarus. So now I'm editing this same pascal program in Lazarus.
It works very well to insert, modify and list: name, surname and telephone in a array of record of this type.
But the read command is not working for me in this modify procedure.
But the read command works well on my Delete procedure for example.
Main problem:
**These 3 read command did not work so I modified to readln which fixed it for me and now each one reads my inputs but only with readln, but not with read. **
But why ?
gotoxy(24,8);
read(modificar_nome);
gotoxy(24,9);
read(modificar_sobrenome);
gotoxy(24,10);
read(modificar_telefone);
Complete Procedure
//---------------------------------------
// MODIFICAR escolha
//---------------------------------------
procedure modificar_pessoa(var pessoa: type_pessoas);
var i,achou: integer;
var buscar_pessoa, modificar_nome, modificar_sobrenome, modificar_telefone: string;
begin
clrscr;
writeln('****************************************************************************************');
writeln('* Modificar pessoa *');
writeln('****************************************************************************************');
writeln('* Nome: *');
writeln('****************************************************************************************');
gotoxy(9,4); readln(buscar_pessoa);
for i:=0 to length(pessoa)-1 do
begin
if (pessoa[i].primeiro_nome = buscar_pessoa) then
begin
achou := 1;
break;
end;
end;
if achou = 1 then
begin
writeln('****************************************************************************************');
writeln('* Preencher so o que deseja modificar (ou ENTER para ignorar): *');
writeln('****************************************************************************************');
writeln('* Novo Primeiro Nome? *');
writeln('* Novo Sobrenome? *');
writeln('* Novo Telefone? *');
writeln('****************************************************************************************');
gotoxy(24,8);
read(modificar_nome); // not waiting for my input ???????????
gotoxy(24,9);
read(modificar_sobrenome);
gotoxy(24,10);
read(modificar_telefone);
if modificar_nome <> '' then
pessoa[i].primeiro_nome := modificar_nome;
if modificar_sobrenome <> '' then
pessoa[i].ultimo_nome := modificar_sobrenome;
if modificar_telefone <> '' then
pessoa[i].telefone := modificar_telefone;
gotoxy(1,13);
writeln;
writeln('Pessoa ''', buscar_pessoa, ''' modificada com sucesso!');
end
else
begin
gotoxy(1,13);
writeln;
writeln('ERRO: Pessoa ''', buscar_pessoa, ''' não foi localizada!');
end;
writeln;
writeln('Pressione qualquer tecla para retornar ao menu...'); ReadAnyKey;
end;
Funny is this other procedure to delete (exclude) people, the read command works fine and waits for my input
//---------------------------------------
// EXCLUIR escolha
//---------------------------------------
procedure excluir_pessoa(var pessoa: type_pessoas);
var i,achou: integer;
var del_pessoa: string;
begin
clrscr;
writeln('****************************************************************************************');
writeln('* Excluir pessoa *');
writeln('****************************************************************************************');
writeln('* Nome: *');
writeln('****************************************************************************************');
gotoxy(9,4); read(del_pessoa);
for i:=0 to length(pessoa)-1 do
begin
if (pessoa[i].primeiro_nome = del_pessoa) then
begin
achou := 1;
pessoa[i].primeiro_nome := '';
pessoa[i].ultimo_nome := '';
pessoa[i].telefone := '';
break;
end;
end;
gotoxy(1,6);
if achou = 1 then
writeln('Pessoa ''', del_pessoa, ''' excluida com sucesso!')
else
writeln('ERRO: Pessoa ''', del_pessoa, ''' nao foi localizada!');
writeln;
writeln('Pressione qualquer tecla para retornar ao menu...'); ReadAnyKey;
end;
I think that the short answer to this is that your observation is correct and that the reason is that Read is working as designed. Once FPC's runtime has executed the firstRead it behaves as if it has seen an Eol after what the user typed, and therefore the second and subsequent calls to Read return immediately without waiting for any further user input.
The reason it behaves this was seems to be historical. FPC was based on the Object Pascal of the commercial RAD system Delphi, and although the two have diverged somewhat over the years (e.g. in their different implementations of generics), FPC faithfully reproduces many of the basic details of the Object Pascal language and runtime, including its file handling, of which keyboard input is a special case.
I think that it is legitimate. therefore, to look at the Delphi/Object Pasval documentation of Read. In the online help of Delphi 7, which dates from 20 years ago, the section on Read includes
Description
The Read procedure can be used in Delphi code in the following ways.
For typed files, it reads a file component into a variable.
For text files, it reads one or more values into one or more variables.
With a type string variable:
Read reads all characters up to, but not including, the next end-of-line marker or until Eof(F) becomes true; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.
After the first Read, each subsequent Read sees the end-of-line marker and returns a zero-length string.
Use multiple Readln calls to read successive string values.[emphasis added]
So, the Delphi OLH documents exactly the behaviour you are seeing (that the second and subsequent calls to Read return immediately without gathering any user input) and describes the remedy, which is to use Readln instead. And that's why you see the same behaviour + remedy in FPC.
I'm following an internet course on the basics of programming. After making a diagram I convert it to code, right now this is PASCAL language.
I'm having a problem with procedures and can't find an answer, nor in the course, nor with some google-ing.
I want to get a variavble back form a procedure. Right now iIhave a working piece of code but I think this is not the good way of working. Here's an extract of the code:
program WELKEWAGEN;
// declare your variables here
var T, N, KM, vari, prijsDW, prijsBW, jrenGEBR, taksDW, taksBW, prijsB, verbrBW, prijsD, verbrDW : real;
procedure OPHALEN(para : string);
begin
repeat
writeln('geef de ', para , ' op');
readln(vari);
until (vari > 0);
end;
begin
//this is the main program but there is more code ofcourse
OPHALEN('prijs benzinewagen');
prijsBW := vari;
//...
end.
Now the internet course says I should program it like this:
begin
//...
prijsBW := OPHALEN('prijs benzinewagen');
//...
end.
But this is not working.
I get following errors:
WELKEWAGEN.pas(24,14) Error: Incompatible types: got "untyped" expected "Real"
WELKEWAGEN.pas(50) Fatal: There were 1 errors compiling module, stopping
pas(24,14) is this line: prijsBW := OPHALEN('prijs benzinewagen');
Procedures don't return values, so the syntax
prijsBW := OPHALEN('prijs benzinewagen');
is invalid.
If you want to return a value, you need to define a function instead:
function OPHALEN(para : string): Real;
var
Res: Real;
begin
Res := 0;
repeat
writeln('geef de ', para , ' op');
readln(Res);
until (Res > 0);
OPHALEN := Res;
end;
Note that the (bad) global variables you're using mean you don't have to return anything at all, because a procedure can access and change that global variable directly (but you have no way of knowing when the procedure is finished):
procedure OPHALEN(para : string);
begin
vari := 0;
repeat
writeln('geef de ', para , ' op');
readln(vari);
until (vari > 0);
end;
Modern Pascal dialects (such as Delphi and FreePascal) allow a cleaner syntax for the return value of functions by using an automatically declared function result variable of the proper type for you, named Result (because that's what it is - the result of the function):
function OPHALEN(para : string): Real;
begin
Result := 0;
repeat
writeln('geef de ', para , ' op');
readln(Result);
until (Result > 0);
end;
If you need to return multiple values, you can use var parameters, which allow them to be changed inside the function.
procedure OPHALEN(para: string; var RetVal: Real);
begin
RetVal := 0;
repeat
writeln('geef de ', para , ' op');
readln(RetVal);
until (RetVal > 0);
end;
Your original code (and the examples I've provided above) all fail to allow the user to cancel, BTW. There should be some way to exit the loop for the user; otherwise, your code just endlessly loops, writing para to the screen and then waiting for input. This has a tendency to annoy users.
I'm starting to use Inno Setup, and I have some problems with my INI file encoding.
I want to save user input in the INI file, and this input can contain accents.
I use Inno Setup Unicode, my setupScript.iss is UTF-8 encoded, and here is my code (a part) :
[INI]
Filename: "{app}\www\conf\config.ini"; Section: "Settings"; Key: "ca.plafondAnnuel"; String: "{code:GetUser|Plafond}"
Filename: "{app}\www\conf\config.ini"; Section: "Settings"; Key: "app.siren"; String: "{code:GetUser|Siren}"
Filename: "{app}\www\conf\config.ini"; Section: "Settings"; Key: "app.adresse"; String: "{code:GetUser|Adresse}"
[Code]
var
UserPage: TInputQueryWizardPage;
ExamplePage : TInputOptionWizardPage;
ImmatriculationPage : TInputOptionWizardPage;
FakeElemIndex: Integer;
FakeElem: TCustomEdit;
AdresseTextarea: TNewMemo;
procedure InitializeWizard;
begin
UserPage := CreateInputQueryPage(wpWelcome,
'Configuration de l''application', '',
'Configurez ici votre application. Une fois installée, vous pourrez modifier ces valeurs.');
UserPage.Add('Siren :', False);
UserPage.Add('Plafond annuel (utilisé par les auto-entreprises, mettre 0 si vous ne souhaitez pas plafonner votre chiffre d''affaire.):', False);
FakeElemIndex := UserPage.Add('Votre adresse complète (telle qu''elle s''affichera sur les devis et factures, avec nom complet):', False);
FakeElem := UserPage.Edits[FakeElemIndex];
AdresseTextarea := TNewMemo.Create(WizardForm);
AdresseTextarea.Parent := FakeElem.Parent;
AdresseTextarea.SetBounds(FakeElem.Left, FakeElem.Top, FakeElem.Width, ScaleY(50));
// Hide the original single-line edit
FakeElem.Visible := False;
end;
function GetUser(Param: String): String;
begin
if Param = 'Adresse' then
Result := AdresseTextarea.Text
else if Param = 'Siren' then
Result := UserPage.Values[0]
else if Param = 'Plafond' then
Result := UserPage.Values[1];
end;
The value returned by getUser|Adresse in the [INI] part is not UTF-8 encoded: I open the INI file with Notepad++ and I see the file is UTF-8 encoded. But the value adresse is ANSI encoded (If I change the encoding of the file to ANSI, this value is readable)
Someone can help me understand how can I save this user input in UTF-8 ?
Thanks a lot !
The INI functions of Inno Setup ([INI] section and SetIni* functions) use internally the Windows API function WritePrivateProfileString.
This function does not support UTF-8 at all. All it supports is the ANSI encoding and UTF-16.
See How to read/write Chinese/Japanese characters from/to INI files?
So it's even questionable whether the target application will be able to read UTF-8-encoded INI file, if it relies on the Windows API function to read it.
Anyway, if you need the UTF-8, you would have to format the entries to INI format yourself and use SaveStringsToUTF8File function to write it.
The last option is to hack it by using the system call WritePrivateProfileString to write seemingly ANSI-encoded string, which will be in fact UTF-8-encoded.
For that you need to convert the string to UTF-8 in your code. You can use WideCharToMultiByte for that.
function WideCharToMultiByte(CodePage: UINT; dwFlags: DWORD;
lpWideCharStr: string; cchWideChar: Integer; lpMultiByteStr: AnsiString;
cchMultiByte: Integer; lpDefaultCharFake: Integer;
lpUsedDefaultCharFake: Integer): Integer;
external 'WideCharToMultiByte#kernel32.dll stdcall';
const
CP_UTF8 = 65001;
function GetStringAsUtf8(S: string): AnsiString;
var
Len: Integer;
begin
Len := WideCharToMultiByte(CP_UTF8, 0, S, Length(S), Result, 0, 0, 0);
SetLength(Result, Len);
WideCharToMultiByte(CP_UTF8, 0, S, Length(S), Result, Len, 0, 0);
end;
function WritePrivateProfileString(
lpAppName, lpKeyName, lpString, lpFileName: AnsiString): Integer;
external 'WritePrivateProfileStringA#kernel32.dll stdcall';
procedure CurStepChanged(CurStep: TSetupStep);
var
IniFileName: string;
begin
if CurStep = ssInstall then
begin
Log('Writting INI file');
if not ForceDirectories(ExpandConstant('{app}\www\conf')) then
begin
MsgBox('Error creating directory for INI file', mbError, MB_OK);
end
else
begin
IniFileName := ExpandConstant('{app}\www\conf\config.ini');
if (WritePrivateProfileString(
'Settings', 'ca.plafondAnnuel', GetStringAsUtf8(GetUser('Plafond')),
IniFileName) = 0) or
(WritePrivateProfileString(
'Settings', 'app.siren', GetStringAsUtf8(GetUser('Siren')),
IniFileName) = 0) or
(WritePrivateProfileString(
'Settings', 'app.adresse', GetStringAsUtf8(GetUser('Adresse')),
IniFileName) = 0) then
begin
MsgBox('Error writting the INI file', mbError, MB_OK);
end;
end;
end;
end;
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am making an installer that needs to edit an INI file during the installation. In this case I need to edit only two keys from that ini file.
These two:
filename: rev.ini; Section: Emulator; Key: Language;
filename: rev.ini; Section: steamclient; Key: PlayerName;
I Want The installer to give me the option to select the laguage or use the default language that I already selected from the start in the lenguage menu, and for the PlayerName. Give the option to write any name i want. I didnt see anything like this. only read or put established values in inifiles.
this is my code:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#include "botva2.iss"
#include "BASS_Module.iss"
#define MyAppName "XXX"
#define MyAppVersion "XXX"
#define MyAppPublisher "XXX"
#define MyAppURL "example.com"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppID={{AA8DB34C-8DE2-468C-8A3A-0DADD1A9C38E}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\
DefaultGroupName={#MyAppName}
LicenseFile=Log1.rtf
InfoBeforeFile=Log2.rtf
InfoAfterFile=Log3.rtf
OutputDir=Output Installer\
OutputBaseFilename=XXX 2xxx-2xxx
SetupIconFile=xxx.ico
Compression=lzma2/Ultra64
SolidCompression=true
InternalCompressLevel=Ultra64
Uninstallable=false
WizardImageFile=fondosetup.bmp
WizardSmallImageFile=0.bmp
CreateAppDir=true
UsePreviousAppDir=true
DirExistsWarning=no
AllowCancelDuringInstall=false
[Languages]
Name: "default"; MessagesFile: "compiler:Default.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
[CustomMessages]
default.AppCheckError=xxx was not found, please select the Installation Folder of xxx!
spanish.AppCheckError=xxx no fué encontrado, porfavor selecciona la Carpeta de Instalación de xxx!
french.AppCheckError=xxx n'a pas été trouvé, s'il vous plaît sélectionnez le dossier d'installation de xxx!
german.AppCheckError=xxx nicht gefunden wurde, wählen Sie bitte das Installationsverzeichnis von xxx!
catalan.AppCheckError=xxx no s'ha trobat, si us plau, seleccioneu la carpeta d'instal · lació de xxx!
italian.AppCheckError=xxx non è stato trovato, si prega di selezionare la cartella di installazione di xxx!
portuguese.AppCheckError=xxx não foi encontrado, selecione a pasta de instalação do xxx!
[Files]
Source: "xxx\*"; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: ISSkin.dll; DestDir: {tmp}; Flags: dontcopy;
Source: Styles\LegendsIV.cjstyles; DestDir: {tmp}; Flags: dontcopy
Source: IsUtilsHb.dll; DestDir: {tmp}; Flags: dontcopy;
Source: SplashScreen.png; DestDir: {tmp}; Flags: dontcopy;
Source: "BASS_Files\*"; DestDir: {tmp}; Flags: dontcopy
Source: Music.mp3; DestDir: {tmp}; Flags: dontcopy
Source: logo.png; Flags: dontcopy; DestDir: {tmp};
Source: ISLogo.dll; Flags: dontcopy; DestDir: {tmp};
; --- Generated by InnoSetup Script Joiner version 3.0, Jul 22 2009, (c) Bulat Ziganshin <Bulat.Ziganshin#gmail.com>. More info at http://issjoiner.codeplex.com/
; --- Source: Verificar ExE.iss ------------------------------------------------------------
[code]
function NextButtonClick1(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\left4dead2.exe')) then begin
MsgBox(ExpandConstant('{cm:AppCheckError}'), mbInformation, MB_OK);
Result := False;
exit;
end;
end;
[Setup]
; --- Source: About.iss ------------------------------------------------------------
[Code]
{ RedesignWizardFormBegin } // Don't remove this line!
// Don't modify this section. It is generated automatically.
var
AboutButton: TNewButton;
URLLabel: TNewStaticText;
procedure AboutButtonClick(Sender: TObject); forward;
procedure URLLabelClick(Sender: TObject); forward;
procedure RedesignWizardForm;
begin
{ AboutButton }
AboutButton := TNewButton.Create(WizardForm);
with AboutButton do
begin
Name := 'AboutButton';
Parent := WizardForm;
Left := ScaleX(10);
Top := ScaleY(327);
Width := ScaleX(75);
Height := ScaleY(23);
Caption := 'Info'; // aqui se escribe lo que quiero ver en el about
OnClick := #AboutButtonClick;
end;
{ URLLabel }
URLLabel := TNewStaticText.Create(WizardForm);
with URLLabel do
begin
Name := 'URLLabel';
Parent := WizardForm;
Cursor := crHand;
Caption := 'WEB'; // nombre q desea poner q redirecciona al enlace
Font.Color := clRed; // color
Font.Height := -11;
Font.Name := 'Tele-Marines'; //nombre del font
ParentFont := False;
OnClick := #URLLabelClick;
Left := ScaleX(105);
Top := ScaleY(335);
Width := ScaleX(97);
Height := ScaleY(14);
end;
AboutButton.TabOrder := 5;
URLLabel.TabOrder := 6;
end;
procedure URLLabelClick(Sender: TObject);
var
ErrorCode: Integer;
begin
ShellExecAsOriginalUser('open', 'www.example.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end; //aqui ponen el enlace de su perfil o pagina
procedure AboutButtonClick(Sender: TObject);
begin
MsgBox('Version 2xxx XXX', mbInformation, mb_Ok);
end; //edit the version file here
procedure InitializeWizard2();
begin
RedesignWizardForm;
end;
[Setup]
; --- Source: Audio.iss ------------------------------------------------------------
[code]
procedure InitializeWizard3();
begin
ExtractTemporaryFile('BASS.dll');
ExtractTemporaryFile('Music.mp3');
BASS_Init(ExpandConstant('{tmp}\Music.mp3')) // se copea en los temporarles de tu pc
end;
[Setup]
; --- Source: LOGO XXX.iss ------------------------------------------------------------
[Code]
procedure Logo_Init(Wnd :HWND); external 'ISLogo_Init#files:ISLogo.dll stdcall';
procedure Logo_Draw(FileName: PChar; X, Y: Integer); external 'ISLogo_Draw#files:ISLogo.dll stdcall';
procedure Logo_Free(); external 'ISLogo_Free#files:ISLogo.dll stdcall';
procedure InitializeWizard4();
var
LogoPanel: TPanel;
begin
LogoPanel := TPanel.Create(WizardForm);
with LogoPanel do begin
Top := 326;
Left := 140;
Width := 100;
Height := 37;
Parent := WizardForm;
BevelOuter := bvNone;
end
ExtractTemporaryFile('logo.png');
Logo_Init(LogoPanel.Handle)
Logo_Draw (ExpandConstant('{tmp}\logo.png'), 0 , 0);
end;
[Setup]
; --- Source: Skin Setup.iss ------------------------------------------------------------
[Code]
// Importing LoadSkin API from ISSkin.DLL
procedure LoadSkin(lpszPath: String; lpszIniFileName: String);
external 'LoadSkin#files:isskin.dll stdcall';
// Importing UnloadSkin API from ISSkin.DLL
procedure UnloadSkin();
external 'UnloadSkin#files:isskin.dll stdcall';
// Importing ShowWindow Windows API from User32.DLL
function ShowWindow(hWnd: Integer; uType: Integer): Integer;
external 'ShowWindow#user32.dll stdcall';
function InitializeSetup5(): Boolean;
begin
ExtractTemporaryFile('LegendsIV.cjstyles');
LoadSkin(ExpandConstant('{tmp}\LegendsIV.cjstyles'), '');
Result := True;
end;
procedure DeinitializeSetup5();
begin
// Hide Window before unloading skin so user does not get
// a glimse of an unskinned window before it is closed.
ShowWindow(StrToInt(ExpandConstant('{wizardhwnd}')), 0);
UnloadSkin();
end;
[Setup]
; --- Source: Splashpng.iss ------------------------------------------------------------
[Code]
function SplashScreen(hWnd: Integer; pathPng: String; nSleep: Integer): Integer;
external 'SplashScreen#files:IsUtilsHb.dll stdcall';
procedure InitializeWizard6();
var SplashFileName: String;
begin
SplashFileName := ExpandConstant('{tmp}\SplashScreen.png');
ExtractTemporaryFile('SplashScreen.png');
SplashScreen (StrToInt(ExpandConstant('{hwnd}')), SplashFileName, 2000);
end;
[Setup]
; --- Source: Texto Transparente Banner.iss ------------------------------------------------------------
[code]
var
PageNameLabel, PageDescriptionLabel: TLabel;
procedure InitializeWizard7();
begin
PageNameLabel := TLabel.Create(WizardForm);
with PageNameLabel do
begin
Left := ScaleX(10); // mover el titulo de arriba (menor izq o mayor der)
Top := ScaleY(10);
Width := ScaleX(300); // ancho del titulo de texto arriba
Height := ScaleY(14); // altura del titulo de texto de arriba
AutoSize := False;
WordWrap := True;
Font.Color := clWhite; // color de texto
Font.Style := [fsBold];
ShowAccelChar := False;
Transparent := True;
Parent := WizardForm.MainPanel;
end;
PageDescriptionLabel := TLabel.Create(WizardForm);
with PageDescriptionLabel do
begin
Left := ScaleX(15); // mover la descripcion de abajo (menor izq o mayor der)
Top := ScaleY(25);
Width := ScaleX(475); // ancho de la descripcion de texto abajo
Height := ScaleY(30); // altura de la descripcion de texto abajo
AutoSize := False;
WordWrap := True;
Font.Color := clWhite; // color de texto
ShowAccelChar := False;
Transparent := True;
Parent := WizardForm.MainPanel;
end;
with WizardForm do
begin
PageNameLabel.Hide;
PageDescriptionLabel.Hide;
with MainPanel do
begin
with WizardSmallBitmapImage do
begin
Left := ScaleX(0); // mover la imagen (menor izq o mayor der)
Top := ScaleY(0);
Width := Mainpanel.Width;
Height := MainPanel.Height;
end;
end;
end;
end;
procedure CurPageChanged7(CurPageID: Integer);
begin
PageNameLabel.Caption := WizardForm.PageNameLabel.Caption;
PageDescriptionLabel.Caption := WizardForm.PageDescriptionLabel.Caption;
end;
[Setup]
; --- Source: Texto Transparente Menú.iss ------------------------------------------------------------
[code]
function NextButtonClick8(CurPageID: Integer): Boolean;
begin
Result := True;
end;
function GetCustomSetupExitCode8(): Integer;
begin
Result := 1;
end;
procedure InitializeWizard8();
var
WLabel1, WLabel2,
FLabel1, FLabel2: TLabel;
begin
WizardForm.WelcomeLabel1.Hide;
WizardForm.WelcomeLabel2.Hide;
WizardForm.FinishedHeadingLabel.Hide;
WizardForm.FinishedLabel.Hide;
WizardForm.WizardBitmapImage.Width := 500; // tamaño de imagen bienvendia ancho
WizardForm.WizardBitmapImage.Height := 315; // tamaño de imagen bienvendia altura
WLabel1 := TLabel.Create(WizardForm); // PAGINA BIENVENIDO..
WLabel1.Left := ScaleX(40); // mover el titulo de arriba (menor izq o mayor der)
WLabel1.Top := ScaleY(30);
WLabel1.Width := ScaleX(301); // ancho del cuadro de texto arriba
WLabel1.Height := ScaleY(65); // altura del cuadro de texto de arriba
WLabel1.AutoSize := False;
WLabel1.WordWrap := True;
WLabel1.Font.Name := 'Arial'; // nombre del font
WLabel1.Font.Size := 13; // tamaño de texto
WLabel1.Font.Style := [fsBold];
WLabel1.Font.Color:= clWhite; // color de texto
WLabel1.ShowAccelChar := False;
WLabel1.Caption := WizardForm.WelcomeLabel1.Caption;
WLabel1.Transparent := True;
WLabel1.Parent := WizardForm.WelcomePage;
WLabel2 :=TLabel.Create(WizardForm);
WLabel2.Top := ScaleY(110);
WLabel2.Left := ScaleX(40); // mover el titulo de abajo (menor izq o mayor der)
WLabel2.Width := ScaleX(301); // ancho del cuadro de texto abajo
WLabel2.Height := ScaleY(300); // altura del cuadro de texto de abajo
WLabel2.AutoSize := False;
WLabel2.WordWrap := True;
WLabel2.Font.Name := 'arial'; // nombre del font
WLabel2.Font.Color:= clWhite; // color de texto
WLabel2.ShowAccelChar := False;
WLabel2.Caption := WizardForm.WelcomeLabel2.Caption;
WLabel2.Transparent := True;
WLabel2.Parent := WizardForm.WelcomePage;
WizardForm.WizardBitmapImage2.Width := 500; // tamaño de imagen final ancho
WizardForm.WizardBitmapImage2.Height := 315; // tamaño de imagen final altura
FLabel1 := TLabel.Create(WizardForm); // PAGINA FINAL..
FLabel1.Left := ScaleX(40); // mover el titulo de arriba (menor izq o mayor der)
FLabel1.Top := ScaleY(100);
FLabel1.Width := ScaleX(301); // ancho del cuadro de texto arriba
FLabel1.Height := ScaleY(75); // altura del cuadro de texto de arriba
FLabel1.AutoSize := False;
FLabel1.WordWrap := True;
FLabel1.Font.Name := 'arial'; // nombre del font
FLabel1.Font.Size := 16; // tamaño de texto
FLabel1.Font.Style := [fsBold];
FLabel1.Font.Color:= clWhite; // color de texto
FLabel1.ShowAccelChar := False;
FLabel1.Caption := WizardForm.FinishedHeadingLabel.Caption;
FLabel1.Transparent := True;
FLabel1.Parent := WizardForm.FinishedPage;
FLabel2 :=TLabel.Create(WizardForm);
FLabel2.Top := ScaleY(110);
FLabel2.Left := ScaleX(40); // mover el titulo de abajo (menor izq o mayor der)
FLabel2.Width := ScaleX(301); // ancho del cuadro de texto abajo
FLabel2.Height := ScaleY(300); // altura del cuadro de texto de abajo
FLabel2.AutoSize := False;
FLabel2.WordWrap := True;
FLabel2.Font.Name := 'arial'; // nombre del font
FLabel2.Font.Color:= clWhite; // color de texto
FLabel2.ShowAccelChar := False;
FLabel2.Caption := WizardForm.FinishedLabel.Caption;
FLabel2.Transparent := True;
FLabel2.Parent := WizardForm.FinishedPage;
end;
[Setup]
; --- Dispatching code ------------------------------------------------------------
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := NextButtonClick1(CurPageID); if not Result then exit;
Result := NextButtonClick8(CurPageID); if not Result then exit;
end;
procedure InitializeWizard();
begin
InitializeWizard2();
InitializeWizard3();
InitializeWizard4();
InitializeWizard6();
InitializeWizard7();
InitializeWizard8();
end;
procedure DeinitializeSetup();
begin
DeinitializeSetup5();
end;
function InitializeSetup(): Boolean;
begin
Result := InitializeSetup5(); if not Result then exit;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
CurPageChanged7(CurPageID);
end;
function GetCustomSetupExitCode(): Integer;
begin
Result := GetCustomSetupExitCode8(); if Result>0 then exit;
end;
[Registry]
Root: HKCU; SubKey: {app}\XXXTeam; ValueType: string; ValueName: InstallPath;
Root: HKCU; SubKey: {app}\XXXTeam; ValueType: string; ValueName: Version;
[Ini]
Filename: "rev.ini"; Section: Emulator; Key: Language;
Filename: "rev.ini"; Section: steamclient; Key: PlayerName;
If you put the lines from the [Languages] section into a separate file (in this case the c:\Languages.txt), the following preprocessor script will generate the script that will add to the combo box placed on a custom page list of available languages and select the current one. On that custom page will also be the edit box for entering player's name. The name of the language along with the entered name will then be stored in the Setup.ini file into a selected application directory. The preprocessed script is saved as c:\PreprocessedScript.iss file.
Languages.txt content:
Note, that each item in the Languages.txt file must have the exact format:
the name and language file (path) must be enclosed by the "" chars
the file (path) must contain only one file (you cannot use delimited list of files)
Name: "default"; MessagesFile: "compiler:Default.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Script file:
The ConvertLanguageName function is borrowed (and modified) from the InnoSetup source...
#define LanguageFile "c:\Languages.txt"
#define LanguageName
#define LanguageIndex
#define LanguageCount
#define FileLine
#define FileHandle
#dim LanguageList[65536]
#sub ProcessFileLine
#if FileLine != ""
#expr LanguageList[LanguageCount] = FileLine
#expr LanguageCount = ++LanguageCount
#endif
#endsub
#for {FileHandle = FileOpen(LanguageFile); \
FileHandle && !FileEof(FileHandle); \
FileLine = FileRead(FileHandle)} \
ProcessFileLine
#if FileHandle
#expr FileClose(FileHandle)
#endif
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Languages]
#sub AddLanguageItemSection
#emit LanguageList[LanguageIndex]
#endsub
#for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageItemSection
[INI]
Filename: "{app}\Setup.ini"; Section: "Emulator"; Key: "Language"; String: "{code:GetLanguageName}"; Flags: createkeyifdoesntexist
Filename: "{app}\Setup.ini"; Section: "SteamClient"; Key: "PlayerName"; String: "{code:GetPlayerName}"; Flags: createkeyifdoesntexist
[Code]
var
NameEdit: TNewEdit;
LanguageCombo: TNewComboBox;
LanguageNames: TStringList;
function ConvertLanguageName(const Value: string): string;
var
I: Integer;
WideCharCode: Word;
begin
Result := '';
I := 1;
while I <= Length(Value) do
begin
if Value[I] = '<' then
begin
WideCharCode := StrToInt('$' + Copy(Value, I + 1, 4));
I := I + 6;
end
else
begin
WideCharCode := Ord(Value[I]);
I := I + 1;
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result)] := Chr(WideCharCode);
end;
end;
function GetLanguageName(const Value: string): string;
begin
Result := LanguageNames[LanguageCombo.ItemIndex];
end;
function GetPlayerName(const Value: string): string;
begin
Result := NameEdit.Text;
end;
procedure InitializeWizard;
var
PlayerSettingsPage: TWizardPage;
NameLabel: TLabel;
LanguageLabel: TLabel;
begin
PlayerSettingsPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
NameLabel := TLabel.Create(WizardForm);
NameLabel.Parent := PlayerSettingsPage.Surface;
NameLabel.Left := 0;
NameLabel.Top := 0;
NameLabel.Caption := 'Name';
NameEdit := TNewEdit.Create(WizardForm);
NameEdit.Parent := PlayerSettingsPage.Surface;
NameEdit.Left := 0;
NameEdit.Top := NameLabel.Top + NameLabel.Height + 4;
NameEdit.Width := 250;
LanguageNames := TStringList.Create;
#sub AddLanguageInternalNames
#define GetLanguageInternalName(str S) \
Local[0] = Copy(S, Pos("Name:", S) + Len("Name:")), \
Local[1] = Copy(Local[0], Pos("""", Local[0]) + 1), \
Copy(Local[1], 1, Pos("""", Local[1]) - 1)
#emit ' LanguageNames.Add(''' + GetLanguageInternalName(LanguageList[LanguageIndex]) + ''');'
#endsub
#for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageInternalNames
LanguageLabel := TLabel.Create(WizardForm);
LanguageLabel.Parent := PlayerSettingsPage.Surface;
LanguageLabel.Left := 0;
LanguageLabel.Top := NameEdit.Top + NameEdit.Height + 8;
LanguageLabel.Caption := 'Language';
LanguageCombo := TNewComboBox.Create(WizardForm);
LanguageCombo.Parent := PlayerSettingsPage.Surface;
LanguageCombo.Left := 0;
LanguageCombo.Top := LanguageLabel.Top + LanguageLabel.Height + 4;
LanguageCombo.Width := NameEdit.Width;
LanguageCombo.Style := csDropDownList;
#sub AddLanguageDisplayNames
#define GetLanguageDisplayName(str S) \
ReadIni(S, "LangOptions", "LanguageName")
#define GetLanguageFile(str S) \
Local[0] = Copy(S, Pos("MessagesFile:", S) + Len("MessagesFile:")), \
Local[1] = Copy(Local[0], Pos("""", Local[0]) + 1), \
StringChange(Copy(Local[1], 1, Pos("""", Local[1]) - 1), "compiler:", CompilerPath)
#expr LanguageName = GetLanguageDisplayName(GetLanguageFile(LanguageList[LanguageIndex]))
#emit ' LanguageCombo.Items.Add(ConvertLanguageName(''' + LanguageName + '''));'
#endsub
#for {LanguageIndex = 0; LanguageIndex < LanguageCount; LanguageIndex++} AddLanguageDisplayNames
LanguageCombo.ItemIndex := LanguageNames.IndexOf(ActiveLanguage);
end;
procedure DeinitializeSetup;
begin
LanguageNames.Free;
end;
#expr SaveToFile("c:\PreprocessedScript.iss")
I'm looking for a windows api function or another way to get the content (folder and files) of a folder located in a machine on my LAN. off course which I have a valid windows user and password for every machine which I want to access.
You can use the WMI , check the CIM_DataFile and CIM_Directory classes.
Some Notes
1.First you must enable the wmi remote access in the client machines. Read these articles to see how do this and the differences between windows versions Connecting to WMI on a Remote Computer, Securing a Remote WMI Connection.
2.Always you must use filters (Where conditions) to restrict the result of these WMI classes.
3.Always you must use the Drive field as condition, because these classes return the files of all drives.
4.The Wmi interprets the \ (Backslash) character as a reserverd symbol so you must need to escape that character to avoid problems with the WQL sentence.
Delphi Code
{$APPTYPE CONSOLE}
uses
SysUtils,
ActiveX,
ComObj,
Variants;
procedure GetRemoteFolderContent(Const WbemComputer,WbemUser,WbemPassword,Path:string);
const
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
WmiPath : string;
Drive : string;
begin;
//The path
//Get the drive
Drive :=ExtractFileDrive(Path);
//get the path and add a backslash to the end
WmiPath :=IncludeTrailingPathDelimiter(Copy(Path,3,Length(Path)));
//escape the backslash character
WmiPath :=StringReplace(WmiPath,'\','\\',[rfReplaceAll]);
Writeln('Connecting');
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
//Establish the connection
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
Writeln('Files');
Writeln('-----');
//Get the files from the specified folder
FWbemObjectSet:= FWMIService.ExecQuery(Format('SELECT * FROM CIM_DataFile Where Drive="%s" AND Path="%s"',[Drive,WmiPath]),'WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('%s',[FWbemObject.Name]));
FWbemObject:=Unassigned;
end;
Writeln('Folders');
Writeln('-------');
//Get the folders from the specified folder
FWbemObjectSet:= FWMIService.ExecQuery(Format('SELECT * FROM CIM_Directory Where Drive="%s" AND Path="%s"',[Drive,WmiPath]),'WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('%s',[FWbemObject.Name]));
FWbemObject:=Unassigned;
end;
end;
begin
try
CoInitialize(nil);
try
GetRemoteFolderContent('remote_machine','user','password','C:\');
GetRemoteFolderContent('remote_machine','user','password','C:\Program Files');
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
Without the authorization part, it's simple enough. The right way to do the authorization is to call Windows.pas method WNetAddConnection2 and go that way.
However, because I'm in a simple hack mode, I tried this, and it basically works:
uses Types, IOUtils, ShellApi; // Works in Delphi XE.
procedure TForm5.Button1Click(Sender: TObject);
var
dirs:TStringDynArray;
files:TStringDynArray;
apath, dir,filename:String;
begin
ListBox1.Items.Clear;
apath := '\\hostname\sharename';
// This should be calling WNetAddConnection2:
// instead It's an evil (portable) hack.
ShellExecute(HWND(0), 'open', PChar('net use /delete '+ apath),
nil,nil,SW_SHOW );
ShellExecute(HWND(0), 'open', PChar('net use '+ apath+' /user:uid pswd'),
nil,nil,SW_SHOW );
dirs := TDirectory.GetDirectories(apath);
if Length(dirs)=0 then
ListBox1.Items.Add('None found.')
else
for dir in dirs do
ListBox1.Items.Add('Directory: '+dir);
files := TDirectory.GetFiles(apath);
for filename in files do
ListBox1.Items.Add('File: '+filename );
end;
Abject Apologies for the ugly hack of ShellExecute "net use". (Grin) Note that I have elected to "mount" this shared folder without giving it a drive letter, avoiding the problem of what to do if that drive is already mapped.
Here's a good link with a WNetAddConnection2 code sample that I will link to instead of poaching. It shows a sample of the non-evil way to do it. :-) Then you can use the Directory enumeration code as I have shown above.
I suppose this is included in Warren's answer, but to cut to the chase, IOUtils.TDirectory supports UNCs:
implementation
uses IOUtils,types;
procedure GetFiles;
var
i: integer;
files: TStringDynArray;
begin
files := TDirectory.GetFiles('\\aServer\aPath\aShare\', '*.aFileFilter');
for i := Low(files)to High(files) do
memo1.Lines.Add(files[i]);
end;
etc, etc...