Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run application as administrator 2

Status
Not open for further replies.

Anesthaesia

Technical User
Aug 30, 2001
126
GB
Does anyone know if this is possible ?

I have an app I need to run on some workstations, which updates the registry and performs other functions - the problem is it needs admin rights to do some of this. I don't want to have to log into each machine as administrator before I run it. Is there any way to run the program as administrator (I have the administrator password) while logged in as a user ?
 
Thanks for the reply, however I'm battling to make head or tail of it.

I understand the way it works, but am not comfortable enough with API calls yet to figure it out.

Any help would be great.
 
from what i understand of it (which is probably < or = to you) you mimic a user that has rights to alter the system, but (and this is were i get lost) you need the rights to change the rights to alter the info?!?!?!? the site pointed at near the top (the MSDN one) says that that particular approach only works on XP but what that particular approach is im not sure (got no clue at all about ASP) i imagine it is possible (cue strongm,cclint,cajuncenturion, etc etc[lol]) its just finding relevant code to get it running!!

my thinkin is shutting down the OS and forcing a logon as the administrator but there was a thread a few days back that went along the lines of it not being possible to force the user name and password etc...

im still looking though!!

in the meantime good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
im stuffed if i can get it workin,

keep getting &quot;cannot find entry point into DLL&quot; which makes me think it isnt supported!!

hopefully one of the pros, will pick up on this.

sorry i couldnt help

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 

Ahhh... I think what you are trying to do is to &quot;Impersonate A User&quot;. Use that for your keyword search at MS or where you normally search.

Good Luck

 
VB5: yeah thats what ive been trying

Declare Function ImpersonateLoggedOnUser Lib &quot;kernel32&quot; Alias &quot;ImpersonateLoggedOnUser&quot; (ByVal hToken As Long) As Long

but to get the hToken ive been using

Declare Function LogonUser Lib &quot;kernel32&quot; Alias &quot;LogonUserA&quot; (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long

but i keep getting &quot;cannot find entry point into DLL&quot;

the MSDN function list at


doesnt seem to contain info on any of these functions!!! well that i can find)

Any Ideas???

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Ok, here is my ms search and its results...

=ALL&nq=NEW&so=RECCNT&p=1&ig=01&i=00&i=01&i=02&i=03&i=04&i=05&i=06&i=07&i=
08&i=09&i=10&i=11&i=12&i=13&i=14&i=15&i=16&i=17&i=18&i=19&i=20&i=21&i=22&i=
23&i=24&i=25&i=26&i=27&i=28&i=29&i=30&i=31&i=32&i=33&i=34&i=35&i=36&i=37&i=
38&i=39&i=40&i=41&siteid=us/dev

which the first answer is I think the one you are looking for...

security/impersonateloggedonuser.asp

Good Luck
 
VB5: do you have any working code:

im still getting the &quot;cannot find entry point into DLL&quot; error

im running on 2k pro (all updates) VB6 SP5 as administrator (but testing as guest)

PS anyone else getting a stupidly large (width) web page when viewing this thread

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
damn thats annoying!!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 

Sorry about the width....

From what I read I am not sure that as guest you have the privledge to do what your are trying to. Look for the Advapi32.lib (dll) and use depends to see if you can find it......................................................



Ok I see your declaration into kernel32.dll. That is not where it is kept or called. It is in the advapi32.dll (just checked on my 2k server) so your declaration should be...
[tt]
Declare Function ImpersonateLoggedOnUser Lib &quot;advapi32.dll&quot; Alias &quot;ImpersonateLoggedOnUser&quot; (ByVal hToken As Long) As Long
'or
Declare Function ImpersonateLoggedOnUser Lib &quot;advapi32&quot; Alias &quot;ImpersonateLoggedOnUser&quot; (ByVal hToken As Long) As Long
[/tt]

either or should work

Good Luck

 
I've just put this together, which may help:
[tt]
Option Explicit

Private Declare Function LogonUser Lib &quot;advapi32&quot; Alias &quot;LogonUserA&quot; (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long
Private Declare Function ImpersonateLoggedOnUser Lib &quot;advapi32&quot; (ByVal hToken As Long) As Long
Private Const LOGON32_LOGON_NETWORK = 3
Private Const LOGON32_PROVIDER_DEFAULT = 0

Private Sub Command1_Click()
MsgBox &quot;Impersonation successful: &quot; & MakeMeImpersonate(&quot;wombat&quot;, &quot;secret&quot;, &quot;acme&quot;)
End Sub

' Attempts to make the current thread (i.e the VB program) impersonate Username, using a given Password
' The relevant Domain can also be named. If omitted, account will be verified against the local account
' database rather than that of a domain
' Function returns non-zero (TRUE) if impersonation is successful, FALSE if not
Private Function MakeMeImpersonate(Username As String, Password As String, Optional Domain As String = &quot;.&quot;) As Boolean
Dim result As Long
Dim hToken As Long

If LogonUser(Username, Domain, Password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, hToken) Then
result = ImpersonateLoggedOnUser(hToken)
End If

MakeMeImpersonate = result
End Function
 
hehe... on that note i would like to point out that API text viewer (standard with VB) is out of date or wrong then on my PC!! [lol] and would explain a lot why i was geting the &quot;cannot find entry point into DLL&quot;

strongm: looks good as always... will give it a whirl a little later!

thanks guys!

Anesthaesia: have you sussed it yet??

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
hmmm.. well ive had no luck getting it to work... (i dont doubt the code just my PC)

ive tried creating accounts, changing rights, allsorts. but the logonuser always fails

Anesthaesia: have you sussed it?

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Depending on your OS, there may be additional requirements for this to work. For example, under W2000 the process calling LogonUser needs the SE_TCB_NAME privilege
 
ah... now i see, i am using 2k pro, i will have a read up properly on LogonUser when i get back in!

thanks for setting me straight!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top