Skip to content

Commit 668386a

Browse files
committed
Add Command Prompt shortcut.
1 parent fec3855 commit 668386a

File tree

4 files changed

+153
-1
lines changed

4 files changed

+153
-1
lines changed

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ ES_SERVICE_EXE=$(ES_HOME)/bin/elasticsearchw-$(ES_BITS).exe
2828
ES_SERVICE_UPDATE_CMD_SRC=elasticsearchw-update.cmd
2929
ES_SERVICE_UPDATE_CMD=$(ES_HOME)/lib/elasticsearchw-update-$(ES_BITS).cmd
3030

31+
ES_CMD_CMD_SRC=elasticsearch-cmd.cmd
32+
ES_CMD_CMD=$(ES_HOME)/lib/elasticsearch-cmd.cmd
33+
3134
ISCC?= '/c/Program Files (x86)/Inno Setup 5/ISCC.exe'
3235

3336
ifneq ($(X64),false)
@@ -52,11 +55,15 @@ setup-helper-console.exe: src/setup-helper-console.c src/setup-helper.c
5255
gcc -o $@ -std=gnu99 -pedantic -Os -Wall -m32 src/setup-helper-console.c -lnetapi32 -ladvapi32 -luserenv
5356
strip $@
5457

55-
setup: setup-helper.dll vendor $(ES_SERVICE_UPDATE_CMD) $(ES_SERVICE_EXE)
58+
setup: setup-helper.dll vendor $(ES_CMD_CMD) $(ES_SERVICE_UPDATE_CMD) $(ES_SERVICE_EXE)
5659
$(ISCC) elasticsearch.iss $(ISCCOPT)
5760

5861
vendor: $(ES_JAR) $(COMMONS_DAEMON_PRUNSRV) $(JRE)
5962

63+
$(ES_CMD_CMD): $(ES_CMD_CMD_SRC)
64+
sed -e "s,@@ES_VERSION@@,$(ES_VERSION),g" \
65+
$(ES_CMD_CMD_SRC) > $(ES_CMD_CMD)
66+
6067
$(ES_SERVICE_UPDATE_CMD): $(ES_SERVICE_UPDATE_CMD_SRC)
6168
sed -e "s,@@ES_BITS@@,$(ES_BITS),g" \
6269
-e "s,@@ES_VERSION@@,$(ES_VERSION),g" \

elasticsearch-cmd.cmd

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@echo off
2+
3+
for %%I in ("%~dp0..") do set ES_HOME=%%~dpfI
4+
5+
set JAVA_HOME=%ES_HOME%\jre
6+
set PATH=%ES_HOME%\bin;%JAVA_HOME%\bin;%PATH%
7+
8+
TITLE Elasticsearch @@ES_VERSION@@ Command Prompt
9+
10+
echo From here you can run administrative commands.
11+
echo.
12+
echo Stop the service:
13+
echo.
14+
echo net stop elasticsearch
15+
echo.
16+
echo Start the service:
17+
echo.
18+
echo net start elasticsearch
19+
echo.
20+
echo View installed plugins:
21+
echo.
22+
echo plugin --list
23+
echo.
24+
echo Install a plugin, e.g. Marvel:
25+
echo.
26+
echo plugin install elasticsearch/marvel/latest
27+
echo.
28+
29+
cmd /k "cd %ES_HOME%"

elasticsearch.iss

+16
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Source: "{#ESPath}\config\logging.yml"; DestDir: "{app}\config"
9393
Source: "{#ESPath}\README.textile"; DestDir: "{app}"; DestName: "README.txt"; Flags: isreadme
9494
Source: "{#ESPath}\NOTICE.txt"; DestDir: "{app}"
9595
Source: "{#ESPath}\LICENSE.txt"; DestDir: "{app}"
96+
Source: "{#ESPath}\lib\elasticsearch-cmd.cmd"; DestDir: "{app}\lib"
9697
Source: "{#ESPath}\lib\elasticsearchw-update-{#Bits}.cmd"; DestDir: "{app}\lib"; DestName: "elasticsearchw-update.cmd"
9798
Source: "elasticsearchw-uninstall.cmd"; DestDir: "{app}\lib"
9899
Source: "Elasticsearch Home.url"; DestDir: "{app}"
@@ -121,6 +122,7 @@ Filename: "{app}\lib\elasticsearchw-uninstall.cmd"; WorkingDir: "{app}"; Flags:
121122
#include "service.pas"
122123
#include "service-account.pas"
123124
#include "java.pas"
125+
#include "shortcut.pas"
124126
125127
const
126128
SERVICE_ACCOUNT_NAME = '{#ServiceAccountName}';
@@ -174,6 +176,9 @@ var
174176
ServicePath: string;
175177
Password: string;
176178
Status: integer;
179+
CmdPath: string;
180+
IconPath: string;
181+
WorkingDirectoryPath: string;
177182
begin
178183
case CurStep of
179184
ssInstall:
@@ -199,6 +204,14 @@ begin
199204
begin
200205
MsgBox('Failed to install the ' + SERVICE_NAME + ' service.' #13#13 'You need to install it manually.', mbError, MB_OK)
201206
end
207+
end;
208+
ssPostInstall:
209+
begin
210+
CmdPath := ExpandConstant('{app}\lib\elasticsearch-cmd.cmd');
211+
IconPath := ExpandConstant('{uninstallexe}');
212+
WorkingDirectoryPath := ExpandConstant('{app}');
213+
CreateShortcut(ExpandConstant('{app}\bin\Elasticsearch Command Prompt.lnk'), CmdPath, IconPath, WorkingDirectoryPath, True);
214+
CreateShortcut(ExpandConstant('{group}\Elasticsearch Command Prompt.lnk'), CmdPath, IconPath, WorkingDirectoryPath, True);
202215
end
203216
end
204217
end;
@@ -210,6 +223,9 @@ begin
210223
case CurUninstallStep of
211224
usPostUninstall:
212225
begin
226+
DeleteFile(ExpandConstant('{app}\bin\Elasticsearch Command Prompt.lnk'));
227+
DeleteFile(ExpandConstant('{group}\Elasticsearch Command Prompt.lnk'));
228+
213229
// NB the service should already be uinstalled (by elasticsearchw-uninstall.cmd)
214230
215231
Status := DestroyServiceAccount(SERVICE_ACCOUNT_NAME);

shortcut.pas

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// IShellLink descriptions code came from https://github.com/jrsoftware/issrc/blob/master/Examples/CodeAutomation2.iss
2+
3+
// procedure CreateShortcut(AtPath: string; ToPath: string; RunAsAdministrator: boolean);
4+
5+
const
6+
CLSID_ShellLink = '{00021401-0000-0000-C000-000000000046}';
7+
8+
const
9+
// IShellLinkDataList::GetFlags()/SetFlags()
10+
SLDF_HAS_ID_LIST = $00000001; // Shell link saved with ID list
11+
SLDF_HAS_LINK_INFO = $00000002; // Shell link saved with LinkInfo
12+
SLDF_HAS_NAME = $00000004;
13+
SLDF_HAS_RELPATH = $00000008;
14+
SLDF_HAS_WORKINGDIR = $00000010;
15+
SLDF_HAS_ARGS = $00000020;
16+
SLDF_HAS_ICONLOCATION = $00000040;
17+
SLDF_UNICODE = $00000080; // the strings are unicode
18+
SLDF_FORCE_NO_LINKINFO = $00000100; // don't create a LINKINFO (make a dumb link)
19+
SLDF_HAS_EXP_SZ = $00000200; // the link contains expandable env strings
20+
SLDF_RUN_IN_SEPARATE = $00000400; // Run the 16-bit target exe in a separate VDM/WOW
21+
SLDF_HAS_LOGO3ID = $00000800; // this link is a special Logo3/MSICD link
22+
SLDF_HAS_DARWINID = $00001000; // this link is a special Darwin link
23+
SLDF_RUNAS_USER = $00002000; // Run this link as a different user
24+
SLDF_HAS_EXP_ICON_SZ = $00004000; // contains expandable env string for icon path
25+
SLDF_NO_PIDL_ALIAS = $00008000; // don't ever resolve to a logical location
26+
SLDF_FORCE_UNCNAME = $00010000; // make GetPath() prefer the UNC name to the local name
27+
SLDF_RUN_WITH_SHIMLAYER = $00020000; // Launch the target of this link w/ shim layer active
28+
SLDF_RESERVED = $80000000; // Reserved-- so we can use the low word as an index value in the future
29+
30+
type
31+
IShellLinkW = interface(IUnknown)
32+
'{000214F9-0000-0000-C000-000000000046}'
33+
procedure Dummy;
34+
procedure Dummy2;
35+
procedure Dummy3;
36+
function GetDescription(pszName: String; cchMaxName: Integer): HResult;
37+
function SetDescription(pszName: String): HResult;
38+
function GetWorkingDirectory(pszDir: String; cchMaxPath: Integer): HResult;
39+
function SetWorkingDirectory(pszDir: String): HResult;
40+
function GetArguments(pszArgs: String; cchMaxPath: Integer): HResult;
41+
function SetArguments(pszArgs: String): HResult;
42+
function GetHotkey(var pwHotkey: Word): HResult;
43+
function SetHotkey(wHotkey: Word): HResult;
44+
function GetShowCmd(out piShowCmd: Integer): HResult;
45+
function SetShowCmd(iShowCmd: Integer): HResult;
46+
function GetIconLocation(pszIconPath: String; cchIconPath: Integer; out piIcon: Integer): HResult;
47+
function SetIconLocation(pszIconPath: String; iIcon: Integer): HResult;
48+
function SetRelativePath(pszPathRel: String; dwReserved: DWORD): HResult;
49+
function Resolve(Wnd: HWND; fFlags: DWORD): HResult;
50+
function SetPath(pszFile: String): HResult;
51+
end;
52+
53+
IShellLinkDataList = interface(IUnknown)
54+
'{45E2B4AE-B1C3-11D0-B92F-00A0C90312E1}'
55+
function AddDataBlock(pDataBlock: cardinal): HResult;
56+
function CopyDataBlock(dwSig: DWORD; var ppDataBlock: cardinal): HResult;
57+
function RemoveDataBlock(dwSig: DWORD): HResult;
58+
function GetFlags(var pdwFlags: DWORD): HResult;
59+
function SetFlags(dwFlags: DWORD): HResult;
60+
end;
61+
62+
IPersist = interface(IUnknown)
63+
'{0000010C-0000-0000-C000-000000000046}'
64+
function GetClassID(var classID: TGUID): HResult;
65+
end;
66+
67+
IPersistFile = interface(IPersist)
68+
'{0000010B-0000-0000-C000-000000000046}'
69+
function IsDirty: HResult;
70+
function Load(pszFileName: String; dwMode: Longint): HResult;
71+
function Save(pszFileName: String; fRemember: BOOL): HResult;
72+
function SaveCompleted(pszFileName: String): HResult;
73+
function GetCurFile(out pszFileName: String): HResult;
74+
end;
75+
76+
procedure CreateShortcut(AtPath, ToPath, IconPath, WorkingDirectoryPath: string; RunAsAdministrator: boolean);
77+
var
78+
Obj: IUnknown;
79+
SL: IShellLinkW;
80+
PF: IPersistFile;
81+
DL: IShellLinkDataList;
82+
Flags: DWORD;
83+
begin
84+
Obj := CreateComObject(StringToGuid(CLSID_ShellLink));
85+
86+
SL := IShellLinkW(Obj);
87+
OleCheck(SL.SetPath(ToPath));
88+
OleCheck(SL.SetWorkingDirectory(WorkingDirectoryPath));
89+
OleCheck(Sl.SetIconLocation(IconPath, 0));
90+
91+
if RunAsAdministrator then
92+
begin
93+
DL := IShellLinkDataList(Obj);
94+
OleCheck(DL.GetFlags(Flags));
95+
OleCheck(Dl.SetFlags(Flags or SLDF_RUNAS_USER));
96+
end;
97+
98+
PF := IPersistFile(Obj);
99+
OleCheck(PF.Save(AtPath, True));
100+
end;

0 commit comments

Comments
 (0)