Postgres failed to install - windows

I'm installing PostgreSQL 10.10 on my windows 10 PC. But I'm getting the following error immediately after running the exe file.
Not sure where exactly things are going wrong. Whether it is windows user level or postgres level.
This is the installation log file...
Log started 08/13/2019 at 20:37:56
Preferred installation mode : qt
Trying to init installer in mode qt
Mode qt successfully initialized
Executing icacls "C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /inheritance:r
Script exit code: 0
Script output:
processed file:
C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1
Successfully processed 1 files; Failed processing 0 files
Script stderr:
Executing icacls "C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /T /Q /grant "subbu:(OI)(CI)F"
Script exit code: 5
Script output:
Successfully processed 1 files; Failed processing 1 files
Script stderr:
C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1\*: Access is denied.
Error running icacls:
"C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /T /Q /grant "subbu:(OI)(CI)F": C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1*: Access is denied.
Cannot delete file C:/Users/subbu/AppData/Local/Temp/postgresql_installer_d8432abdb1

Just run the installer again as Administrator (Right click the installer to do so).

Related

Run PowerShell script on remote server as different user without any pre-requisites

I need to trigger the execution of a powershell script on remote server under different user. This script uses 'gpg.exe' so the execution has to be on the remote server with a path pointing to 'gpg.exe'.
I created a bat file on remote server with following commands:
REM RUNTEST.BAT
time /T
SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%"
echo started
start /wait powershell.exe "Start-Transcript -Path D:\logs\testlog.txt;import-module
'\\ServerName\FolderName\Script\AutomationScript.ps1';Stop-Transcript"
time /T
echo done
exit /b
Then invoked this bat file from PowerShell on another machine:
runas /user:DOMAIN\serviceuser "\\ServerName\FolderName\Script\Execute.bat"
These steps do execute the PowerShell script successfully and the output is also as expected. However, this requires 'gpg.exe' to be available on the path mentioned in the PowerShell script on the machine which will invoke the execution. Is there a way the script can look for pre-requisites (like gpg.exe, folder structure etc) only on the remote server, not the machine which invoked the bat file?
Not sure if OS makes any difference, the remote server has Windows Server 2019 and calling machine has Win 10. The remote server has the required folder structure, gpg.exe, bat file to execute the PowerShell script successfully. The calling machine will not have 'gpg.exe' & the folder structure.

Batch - check if given process is running with admin privileges

I'm writing a batch script, where I need to check if a specific process is run with admin privileges and I have trouble finding a proper command to do so. Tasklist command does not give me that information.
Is there any way to get info about privileges of given process (not cmd.exe, but any process) with a command (and possibly without 3rd party software)?
Edit:
I don't need to determine which account has launched the process, nor do I need to check if cmd.exe process is running with admin privileges. I need to check if a given process is running with admin privileges or not, because later i want to call program which needs to have the same privileges as a given process.
Admin is easily confirmed by calling a PowerShell script from a .bat file script. Place these two (2) files in the same directory. Running Confirm-Admin.bat will return True in the output and 1 as the ERRORLEVEL if the process is being run as admin. If not being run as admin, it will return False as the output and zero (0) as the ERRORLEVEL.
=== Confirm-Admin.ps1
function ExitWithCode($exitcode) {
$host.SetShouldExit($exitcode)
exit $exitcode
}
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "True"
ExitWithCode 1
} else {
Write-Output "False"
ExitWithCode 0
}
=== Confirm-Admin.bat
powershell -NoLogo -NoProfile -File "%~dp0%~n0.ps1"
To run Confirm-Admin.ps1 in PowerShell, invoke another Powershell to run it.
C:>powershell -NoLogo -NoProfile -File "Confirm-Admin.ps1"
True
PS 10:59 C:\src\t
C:>$LASTEXITCODE
1
If you only want to stay in the cmd.exe world, see https://stackoverflow.com/a/11995662/447901
Okay, so after some research and experimenting, I've managed to partially solve my problem.
Firstly, I check if batch script is running with admin privileges:
fsutil dirty query %SYSTEMDRIVE% >nul
if %errorLevel% == 0 (
set isBatchElevated=true
) else (
set isBatchElevated=false
)
Then, I look for a specific process by getting list of all tasks running by current user and finding a process by name:
tasklist /fi "username eq %USERDOMAIN%\%USERNAME%" | find /i "processname" > nul
if errorlevel 1 (
:: batch script doesn't have admin privileges, but the process has
)
So, there are four possible scenarios of running script and process with or without admin privileges.
1) Batch script without admin privileges, process with admin privileges
Running tasklist command won't find the given process with elevated rights and will set exit code to 1. Therefore, you can be 100% sure, that the process is running with elevated privileges, but only if batch script is running without admin privileges.
2) Batch script without admin privileges, process without admin privileges
Running tasklist command will find the given process. Basing on the 1) outcome, you can be 100% sure, that the process is running without elevated privileges, but only if batch script is running without admin privileges.
3)/4) Batch script with admin privileges, process with/without admin privileges
Those are problematic scenarios. When the script is running with elevated privileges, then the given process will be found, but there would be no difference between process with and without elevated rights when running tasklist.
After the privileges check I need to run a program with the same rights as the given process. The difference in the privileges will cause an error and the given won't be running without admin privileges only, so running the batch script without admin rights only won't solve the issue.

Windows script opening cmd and running a command

So i'm trying to write a script which checks if the cmd is with administrative privileges. If it is I just ran the command - which is a jar file. If it isn't what I did was create a link to the cmd and in that link I made it always run as administrator.
The problem is that after it runs the command it opens the second cmd as administrator but then the command needs to be written again. Is there any chance to save the command written and as the second cmd opens run it?
net session >nul
if %errorLevel% == 0 (
java -jar %~dp0/myjar.jar%*
) else (
echo Administrative permissions required
cmdadmin.lnk
)
cmdadmin.lnk is as I said a link to cmd which in the advanced properties I set as run as administrator.
Now what I want is to pass a command when opening the link. Is it possible?

VBScript exit code 3010 for SCCM 2012

I am writing a vbscript to install a .exe application. Script works fine except that once the script is completed I need SCCM 2012 to get a exit code of 3010 so that it would schedule a restart of the PC.
The .exe when run with silent switch suppresses the reboot but the application won't work until restarted. Could you help with a vbscript to return 3010 once setup is finished.
If your script runs under cscript.exe, use WScript.Quit:
copy con 27878706.vbs
WScript.Quit 3010
^Z
1 file(s) copied.
cscript 27878706.vbs
echo %ERRORLEVEL%
3010

Windows Service Write output to file

I have the following batch script:
echo %time% >> C:\file.txt
C:\MyProgram\program.exe /arg1 >> C:\file.txt
echo ------- >> C:\file.txt
I have created a service with
sc create ProgramRun type= own start= auto binPath= "cmd /c cd /d c:\MyProgram\ && start script.bat"
After a reboot, in file.txt I have printed the correct time, but without my program ouput. In that program, I have some simple printf
What can I do to write the output to a file without editing the program?
As a Windows Service, your program is being run in the context of the Local System account, which may not have the rights necessary to launch and run your program properly. Try editing the service and setting the Log On credentials to a Windows account that you know can execute your program properly.
Also, while the Windows Service Control Manager (SCM) will happily start your batch file, the outcome reported will always be failure, specifically "Error 1053: The service did not respond to the start or control request in a timely fashion". This is because your batch file can not communicate with the SCM! Have a look at Microsoft's free (and basic) Srvany "service wrapper" to avoid this problem.

Resources