Check if psqlodbc has been unistalled or not from the system - delphi

Im working on software that required psqlodbc drivers and postgresSQl 9.0 database,
we have a installer designed using delphi 7 to install both psqlodbc and postgreSQl 9 silently
one after the other on click of a single button, here everything runs fine,
but the problem is during uninstall,
i first want to unistall psqlodbc and then postgreSQl 9 also on a sinlge button click,
i want to run the postgreSQl 9 unistaller using shellpApi only after psqlodbc has been unstalled,
as of now im checking for 'cmd.exe' is running or not to start postgreSQl uninstaller, but sometimes after unstalling psqlodbc the 'cmd.exe' remain n the postgreSQl unistaller cannot be executed,
so any please tell me
how to check if psqlodbc uninstall process is completely.
the files are
1.psqlodbc.msi
2.postgresql-9.0.2-1-windows.exe
install/uninstall is handled wit bat file
thanks in advanced:)

You can check registry if driver is available. When it is installed you will get:
c:\tmp\pg>reg query "hklm\SOFTWARE\ODBC\ODBCINST.INI\PostgreSQL ANSI"
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\PostgreSQL ANSI
APILevel REG_SZ 1
ConnectFunctions REG_SZ YYN
Driver REG_SZ C:\Program Files\psqlODBC\0900\bin\psqlodbc30a.dll
DriverODBCVer REG_SZ 03.00
FileUsage REG_SZ 0
Setup REG_SZ C:\Program Files\psqlODBC\0900\bin\psqlodbc30a.dll
SQLLevel REG_SZ 1
UsageCount REG_DWORD 0x1
And when you unistall it you will get (localized version):
c:\tmp\pg>reg query "hklm\SOFTWARE\ODBC\ODBCINST.INI\PostgreSQL ANSI"
Błąd: system nie może odnaleźć określonego klucza rejestru lub wartości.
c:\tmp\pg>
(this menas: Error: system cannot find key or value in registry)
See: reg /? on how to use it and for return code you can use in batch.
You can also search registry uninstall information under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall

I got how to check if psqlodbc has been uninstalled completely so that i can start unistalling postgres
For that i found the solution
On stackoverflow itself
function TForm1.ExecAndWait(const CommandLine: string) : Boolean;
var
StartupInfo: Windows.TStartupInfo; // start-up info passed to process
ProcessInfo: Windows.TProcessInformation; // info about the process
ProcessExitCode: Windows.DWord; // process's exit code
begin
// Set default error result
Result := False;
// Initialise startup info structure to 0, and record length
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
StartupInfo.cb := SizeOf(StartupInfo);
// Execute application commandline
if Windows.CreateProcess(nil, PChar(CommandLine),
nil, nil, False, 0, nil, nil,
StartupInfo, ProcessInfo) then
begin
try
// Now wait for application to complete
if Windows.WaitForSingleObject(ProcessInfo.hProcess, INFINITE)
= WAIT_OBJECT_0 then
// It's completed - get its exit code
if Windows.GetExitCodeProcess(ProcessInfo.hProcess,
ProcessExitCode) then
// Check exit code is zero => successful completion
if ProcessExitCode = 0 then
Result := True;
finally
// Tidy up
Windows.CloseHandle(ProcessInfo.hProcess);
Windows.CloseHandle(ProcessInfo.hThread);
end;
end;
end;
so step # 1
if ExecAndWait('msiexec /x C:\psqlodbc09\psqlodbc.msi') then
begin
//uninstall postgresNow...!!
end;

Related

tdb2.tdbcompact command line tool returns Failed to get a lock: file

I'm running apache-jena-fuseki-3.13-1 and just found tdb2.tdbcompact from its bin-directory. I should run tdb2.tdbcompact nightly to prevent my jena-fuseki from running out of disk space, but now I get error message( Failed to get a lock: file) when running it:
miettinj#ramen:~/jena> ./apache-jena-3.13.1/bin/tdb2.tdbcompact --loc=./apache-jena-fuseki- 3.13.1/run/databases/test_TDB2
org.apache.jena.dboe.DBOpEnvException: Failed to get a lock: file='/srv/work/miettinj/jena/apache-jena-fuseki-3.13.1/run/databases/test_TDB2/tdb.lock': held by process 6136
ps -x|grep 6136
6136 ? Sl 30:48 /usr/lib64/jvm/java/bin/java -Xmx1200M -cp /srv/work/miettinj/jena/apache-jena-fuseki-3.13.1/fuseki-server.jar
"held by process 6136"
Another process is using the database. Compaction has to happen from the process using the database.
Apache Jena Fuseki Jena 3.17.0 added a function endpoint so that the administrator can ask for compaction on a running Fuseki server.

How can we connect with a website? Getting SSL error 1409442E

I am using Delphi 10.2 Tokyo, trying to download some information from a web server.
I pass the command URL https://poloniex.com/public?command=returnCurrencies through this function using Indy 10.6.2.5366 (the command works if I paste it in a browser):
function ReadHTTPS(const url: string): string;
var
IdHTTP: TIdHTTP;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
IdHTTP := TIdHTTP.Create;
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
IdHTTP.IOHandler := IdSSL;
result := IdHTTP.Get(url);
if IdHTTP.ResponseText <> '' then
OutputDebugString(PWideChar('ReadHTTPS: ' + IdHTTP.ResponseText));
finally
IdHTTP.Free;
end;
end{ ReadHTTPS};
That gives the following error:
Error connecting with SSL.
error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version
I have tried installing the latest DLLs for OpenSSL in the same directory as the exe, but that didn't solve it.
Any ideas?
Make sure you are using an up-to-date version of the OpenSSL DLLs that support TLS v1.2 (the latest version that Indy currently supports is 1.0.2u), and then you need to enable the sslvTLSv1_2 flag in the SSLIOHandler's SSLOptions.SSLVersions property:
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
Or:
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2];
Indy enables only TLS v1.0 by default, and apparently https://poloniex.com does not allow TLS versions prior to TLS v1.2.

How to set a global environment variable from Inno Setup installer?

How do I set a global environment variable in Inno Setup?
Background: I am using the Inno install utility and need to set a global environment variable before I do the actual install.
Try this:
[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "VARIABLE_NAME"; \
ValueData: "new_value"; Flags: preservestringtype
You might need to add this:
[Setup]
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
Alternatively try:
[Run]
Filename: "{app}\MyProg.exe"; BeforeInstall: SetEnvPath
[Code]
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
function SetEnvironmentVariable(lpName: string; lpValue: string): BOOL;
external 'SetEnvironmentVariable{#AW}#kernel32.dll stdcall';
procedure SetEnvPath;
begin
if not SetEnvironmentVariable('VARIABLE_NAME', 'new_value') then
MsgBox(SysErrorMessage(DLLGetLastError), mbError, MB_OK);
end;
Reference: Inno Setup Frequently Asked Questions - Setting Environment Variables
If the variable change is not propagated (see Environment variable not recognized [not available] for [Run] programs in Inno Setup)
[Run]
...; AfterInstall: RefreshEnvironment
[Code]
const
SMTO_ABORTIFHUNG = 2;
WM_WININICHANGE = $001A;
WM_SETTINGCHANGE = WM_WININICHANGE;
type
WPARAM = UINT_PTR;
LPARAM = INT_PTR;
LRESULT = INT_PTR;
function SendTextMessageTimeout(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: PAnsiChar; fuFlags: UINT;
uTimeout: UINT; out lpdwResult: DWORD): LRESULT;
external 'SendMessageTimeoutA#user32.dll stdcall';
procedure RefreshEnvironment;
var
S: AnsiString;
MsgResult: DWORD;
begin
S := 'Environment';
SendTextMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
PAnsiChar(S), SMTO_ABORTIFHUNG, 5000, MsgResult);
end;
More details:
Inno Setup: Setting a System Environment Variable
Under more modern (in other words, proper) operating systems, such as
Windows 2000, XP, and Windows 2003 Server, environment variables are
stored in the Registry under the following key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\
Environment
Variables are added by creating a new value under this key or by
modifying a value if it already exists. To delete a variable, you
simply delete its Registry value, unless you are removing part of an
expanded value, such as PATH, in which case you only remove the part
you want.
At this point, Windows will not be aware of your changes unless you
log off or reboot. To get around this, SetEnv will broadcast a
WM_SETTINGCHANGE to all of the windows in the system. This allows
other running applications—for example, Explorer.exe—to be notified of
your change. If you run SetEnv from a command prompt, this will not
update the environment variable for the current DOS window. This is
mainly due to the fact that a process (SetEnv) cannot change the
environment of its parent (The Command Prompt). However, any new
DOS/Command Prompts that you open will show the new variable/value.
The solutions in #Adrian's answer (actually copied from #TLama's answer to similar question) are correct for many situations.
But it won't work for [Run] tasks with runasoriginaluser flag (what is implied by postinstall flag). I.e. the variable won't be propagated to an application run with common "Run My Program" check box on the "Finished" page.
The reason is that the tasks with runasoriginaluser are executed by a un-elevated hidden parent process of the Inno Setup installer. The SetEnvironmentVariable will change environment for the installer, but not for its parent process. Unfortunately, the parent process of the installer cannot be controlled (imo).
As a workaround, to set the variable for the runasoriginaluser tasks, you have to inject an intermediate process between the installer parent process and the task, and have the intermediate process set the variable.
Such an intermediate process can easily be the cmd.exe with its set command:
[Run]
Filename: "{cmd}"; Parameters: "/C set MYVAR=MyValue & ""{app}\MyProg.exe"""; \
Description: "Run My Program"; Flags: postinstall runhidden
The runhidden flag hides the cmd.exe console window, not the application (assuming it's a GUI application). If it's a console application, use start to start it in its own (visible) console window.
What would be wrong with running two setup.exe with the first one doing the setting of the environment variables, and the second doing the things needed for the true setup. The first one would be run with setup.exe /VERYSILENT
I am doing to add an system wide environment variable:
[Setup]
; Tell Windows Explorer to reload the environment
ChangesEnvironment=True
[Registry]
Root: "HKLM"; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "EGPL_GeoLibrarian_Drive"; ValueData: "L"; Flags: createvalueifdoesntexist preservestringtype

Is there a handy tool for just localizing APKs (resources.arsc) besides apktool?

I wanted to localize my Android 4.0.4 (3G) Pad into Uighur language.
I decompiled, added a new values-ug-rCN translation in res folder, compiled back to get resources.arsc file.
All APKs went fine excep Phone.apk.
I can decompile to get xmls, but when compiling, it gave me the following errors:
(The error was reproduced using the latest ApkTool1.5.2, both with/without installing framework.apk)
E:\apktool152\x>apktool.bat if framework-res.apk
I: Framework installed to: C:\Documents and Settings\Administrator\apktool\frame
work\1.apk
E:\apktool152\x>apktool d Phone.apk
I: Baksmaling...
I: Loading resource table...
W: Skipping "android" package group
I: Loaded.
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Documents and Settings\Administrator\apk
tool\framework\1.apk
I: Loaded.
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Done.
I: Copying assets and libs...
E:\apktool152\x>apktool b Phone
I: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
E:\apktool152\x\Phone\res\values-de\strings.xml:194: error: Multiple substitutio
ns specified in non-positional format; did you mean to add the formatted="false"
attribute?
E:\apktool152\x\Phone\res\values-de\strings.xml:195: error: Unexpected end tag s
tring
E:\apktool152\x\Phone\res\values-es\strings.xml:194: error: Multiple substitutio
ns specified in non-positional format; did you mean to add the formatted="false"
attribute?
E:\apktool152\x\Phone\res\values-es\strings.xml:195: error: Unexpected end tag s
tring
E:\apktool152\x\Phone\res\values-es-rUS\strings.xml:197: error: Multiple substit
utions specified in non-positional format; did you mean to add the formatted="fa
lse" attribute?
E:\apktool152\x\Phone\res\values-es-rUS\strings.xml:198: error: Unexpected end t
ag string
E:\apktool152\x\Phone\res\values-it\strings.xml:194: error: Multiple substitutio
ns specified in non-positional format; did you mean to add the formatted="false"
attribute?
E:\apktool152\x\Phone\res\values-it\strings.xml:195: error: Unexpected end tag s
tring
aapt: warning: string 'modem_power' has no default translation in E:\apktool152\
x\Phone\res; found: en_GB zh_CN
aapt: warning: string 'modem_power_summary' has no default translation in E:\apk
tool152\x\Phone\res; found: en_GB zh_CN
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.Androl
ibException: brut.common.BrutException: could not exec command: [aapt, p, --min-
sdk-version, 15, --target-sdk-version, 15, -F, C:\DOCUME~1\ADMINI~1\LOCALS~1\Tem
p\APKTOOL187345540728029844.tmp, -0, arsc, -I, C:\Documents and Settings\Adminis
trator\apktool\framework\1.apk, -S, E:\apktool152\x\Phone\res, -M, E:\apktool152
\x\Phone\AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:358)
at brut.androlib.Androlib.buildResources(Androlib.java:283)
at brut.androlib.Androlib.build(Androlib.java:206)
at brut.androlib.Androlib.build(Androlib.java:176)
at brut.apktool.Main.cmdBuild(Main.java:228)
at brut.apktool.Main.main(Main.java:79)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not
exec command: [aapt, p, --min-sdk-version, 15, --target-sdk-version, 15, -F, C:
\DOCUME~1\ADMINI~1\LOCALS~1\Temp\APKTOOL187345540728029844.tmp, -0, arsc, -I, C:
\Documents and Settings\Administrator\apktool\framework\1.apk, -S, E:\apktool152
\x\Phone\res, -M, E:\apktool152\x\Phone\AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:357)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sd
k-version, 15, --target-sdk-version, 15, -F, C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
APKTOOL187345540728029844.tmp, -0, arsc, -I, C:\Documents and Settings\Administr
ator\apktool\framework\1.apk, -S, E:\apktool152\x\Phone\res, -M, E:\apktool152\x
\Phone\AndroidManifest.xml]
at brut.util.OS.exec(OS.java:89)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:355)
... 6 more
E:\apktool152\x>
I just wanted to translate the xmls inside values, and compile back to get resources.arsc.
I can go past the errors relevant to values xmls, by removing de, es, it translations if need be.
But I don't know the other errors.
So how can I solve this problem?
Or is there another alternative tools just for the task?
I switched to a modefied version of ApkTool called something like ApkTool 1.5 b-sf found in a Chinese site, and after installing framework-res.apk, it complied correctly!
Hope this helps some people.

StartService(), and 'sc start', return ERROR_FILE_NOT_FOUND

My remote Service works fine on my Server 2008, 32 bit, but when I try to run it on my Windows 7 machine StartService() fails with ERROR_FILE_NOT_FOUND.
OpenSCManager(), CreateService(), QueryServiceStatus() and OpenService() all return success, but StartService() fails.
I even compiled the Service from the SDK Samples\WinBase\Service and copied it to Windows\system32 directory on my Win 7 machine, and ran it with '-install'. When I tried to start it with 'SC start' it returns the same error.
Here is the info from SC:
C:\Windows\System32>sc query SimpleService
SERVICE_NAME: SimpleService
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\Windows\System32>sc qc SimpleService
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: SimpleService
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\Windows\System32\ServiceSvc.exe
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Simple Service
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem
C:\Windows\System32>sc start SimpleService
[SC] StartService FAILED 2:
The system cannot find the file specified.
I even ran xCmd.exe on my Win 7 machine, it runs a similar type of remote Service, it gives virus warnings, but even that returns the same error.
I'm sure that if it was a permissions issue that it would probably return ERROR_ACCESS_DENIED.
I've searched all over the net and can't find anything on why it's returning that.
I'm pretty sure I found the problem.
I found code to detect if the app was running in WOW64
and it returned true, it was running on a 64 bit Windows 7 machine.
When it's running in WOW64 it goes to Windows\SysWOW64 not system32.
Once I copied the 32 bit Service .exe into Windows\SysWOW64
and ran it the Service started! :-)
Run the service executable from \windows\system32

Resources