Thread: Running initdb while logged in as Administrator user (Windows)

Running initdb while logged in as Administrator user (Windows)

From
"Daniel Futerman"
Date:
I'm trying to develop an automated PostgreSQL installer for Windows that uses a silent install of PostgreSQL and batch scripts to initialise the database cluster (i.e. run initdb) and start/stop the db server. The install shouldn't install as a service, so initdb needs to be run manually.

The problem I'm having is that initdb cannot be run as an Administrator user, so I wrote a script that creates a new limited Windows user and I now want to run initdb using this user, but while still logged in as the Administrator user.
I've looked at using the RUNAS comand, but the user password has to be inserted manually when using this. I've also tried to pipe in the password using echo *** | RUNAS... where *** is the password, but this doesn't seem to work.

I know there are some apps out there that function as alternatives to RUNAS but some of them require licences, and I'm looking for a distributable solution.

How does the PostgreSQL installer work around this when a new limited user can be specified when installing as a service?

Thanks,
Daniel.

Re: Running initdb while logged in as Administrator user (Windows)

From
Simon Riggs
Date:
On Thu, 2008-09-18 at 19:29 +0200, Daniel Futerman wrote:

> silent install of PostgreSQL

Please shout about it, don't hide it. And look at stackbuilder.

--
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


Re: Running initdb while logged in as Administrator user (Windows)

From
Magnus Hagander
Date:
Daniel Futerman wrote:
> I'm trying to develop an automated PostgreSQL installer for Windows that
> uses a silent install of PostgreSQL and batch scripts to initialise the
> database cluster (i.e. run initdb) and start/stop the db server. The
> install shouldn't install as a service, so initdb needs to be run manually.
>
> The problem I'm having is that initdb cannot be run as an Administrator
> user, so I wrote a script that creates a new limited Windows user and I
> now want to run initdb using this user, but while still logged in as the
> Administrator user.

Actually, in 8.3 (at least, I can't remember if it was in 8.2 as well),
you *can* run it as admin in a lot of cases. It will drop privileges
though, so it can't use the admin permissions.

That said, using a separate account is still best practice.

> I've looked at using the RUNAS comand, but the user password has to be
> inserted manually when using this. I've also tried to pipe in the
> password using echo *** | RUNAS... where *** is the password, but this
> doesn't seem to work.
>
> I know there are some apps out there that function as alternatives to
> RUNAS but some of them require licences, and I'm looking for a
> distributable solution.

Look at psexec from Microsoft (former sysinternals).
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

You'll have to verify what the license says, but given that it's free
and comes from the guys that make Windows, it seems reasonable that it
should be doable.


> How does the PostgreSQL installer work around this when a new limited
> user can be specified when installing as a service?

The installer uses direct Win32 API functions to launch the process as a
different user.

//Magnus

Re: Running initdb while logged in as Administrator user (Windows)

From
"Daniel Futerman"
Date:
Thanks for the suggestion.

Maybe i should rephrase my question :
How does the Postgres (8.3) Installer manage to run initdb (when the installation is not installed as a service).
When installing Postgres from the command line (the 'silent' install), initdb can only be run if installing as a service, but I don't require the service, so have to run initdb after the installation, but cannot do this with Admistrative privileges.

Does the installer temporarily revoke these privileges in order to run initdb, and if so, how is this done?



On Thu, Sep 18, 2008 at 8:18 PM, Simon Riggs <simon@2ndquadrant.com> wrote:

On Thu, 2008-09-18 at 19:29 +0200, Daniel Futerman wrote:

> silent install of PostgreSQL

Please shout about it, don't hide it. And look at stackbuilder.

--
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


Re: Running initdb while logged in as Administrator user (Windows)

From
"Daniel Futerman"
Date:
> Look at psexec from Microsoft (former sysinternals).
> http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

> You'll have to verify what the license says, but given that it's free
> and comes from the guys that make Windows, it seems reasonable that it
> should be doable.

This looks like it does exactly what I need :)
Thanks for the tip :)
Will look into the licence.

Daniel.

Re: Running initdb while logged in as Administrator user (Windows)

From
"Merlin Moncure"
Date:
On Thu, Sep 18, 2008 at 3:47 PM, Daniel Futerman
<daniel.futerman@gmail.com> wrote:
>> Look at psexec from Microsoft (former sysinternals).
>> http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
>
>> You'll have to verify what the license says, but given that it's free
>> and comes from the guys that make Windows, it seems reasonable that it
>> should be doable.
>
> This looks like it does exactly what I need :)
> Thanks for the tip :)
> Will look into the licence.

back in my windows days, i pulled the same trick with 'sanur'

http://www.commandline.co.uk/sanur/

merlin