Solved

C# installer to install software as different user

Posted on 2003-10-31
10
352 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:acameron
  • 5
  • 3
  • 2
10 Comments
 
LVL 4

Expert Comment

by:Tonylmiller
ID: 9662966
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
 
LVL 9

Accepted Solution

by:
_ys_ earned 125 total points
ID: 9669851
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
 

Author Comment

by:acameron
ID: 9670287
I am getting a whole bunch of undeclared identifiers, what headers do I need to include to test this?
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9670453
You should already have those functions protyped. A single #include "windows.h" is sufficient.
0
 

Author Comment

by:acameron
ID: 9670490
Nevermind, I found it.  Let me test this out and I will be back.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:Tonylmiller
ID: 9670597
Oh yes, I thought you wanted the ability to do this on any machine where you would not know the admin password.
0
 

Author Comment

by:acameron
ID: 9671043
Ok, does not appear to be entering the if to assign user and then execute...
0
 

Author Comment

by:acameron
ID: 9671869
Found the problem I overlooked the Win2k issue.  I am running Win2k pro. any ideas?
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9677457
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
 

Author Comment

by:acameron
ID: 9679594
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
detecting  the added row index in a datagridview 3 60
Icons and Colors for Terms 3 24
Need help on C# Linq query on object 6 53
how to read json value 2 31
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now