C# installer to install software as different user

Hello,

I would like to use C# or C/C++ to write a quick little installer to install a program I have (but did not write) as an administrator.  The program has to be installed as an administrator but I do not want to give out the admin password so I need an installer to install the program as admin even though the installer is getting called by say bob.
acameronAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TonylmillerCommented:
Will Windows let you do that?  I wouldn't think so.  Users are not made administrators for a reason.  I'd be surprised if the software can override the user settings of the operating system.
0
_ys_Commented:
As log as you know the username and password of the admin it's quite straightforward really. (C++ code sample provided.)


HANDLE hAdminUserToken = 0;

if ( LogonUser( "Administrator",
                      ".",                            // local machine (could also be domain name)
                      "{password}",
                      LOGON32_LOGON_BATCH,
                      LOGON32_PROVIDER_DEFAULT,
                      &hAdminUserToken ))
{
    if ( ImpersonateLoggedOnUser (hAdminUserToken) )
    {
        // do whatever you need to do as admin here ...
    }

    RevertToSelf ( );
    hAdminUserToken = 0;
}

Under Win 2000 there are however restrictions on who can actually invoke LogonUser successfully. (These restrictions were lifted again within Win XP). The user must have been granted the 'Act as part of the operating system' user right - which in itself is something you generally don't want to enable if you're trying to lock systems down.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
acameronAuthor Commented:
I am getting a whole bunch of undeclared identifiers, what headers do I need to include to test this?
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

_ys_Commented:
You should already have those functions protyped. A single #include "windows.h" is sufficient.
0
acameronAuthor Commented:
Nevermind, I found it.  Let me test this out and I will be back.
0
TonylmillerCommented:
Oh yes, I thought you wanted the ability to do this on any machine where you would not know the admin password.
0
acameronAuthor Commented:
Ok, does not appear to be entering the if to assign user and then execute...
0
acameronAuthor Commented:
Found the problem I overlooked the Win2k issue.  I am running Win2k pro. any ideas?
0
_ys_Commented:
As previously stated:

The user must have been granted the 'Act as part of the operating system' user right.

Sorry, but no other solution to it.
0
acameronAuthor Commented:
I've got it, I can make a system call to runas.  Any idea how I can make c++ wait for the password prompt, then enter the password?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.