Link to home
Start Free TrialLog in
Avatar of acsmith
acsmith

asked on

launch app as different user

hi, is it possible to launch an application from vb, and have it run in the context of another user?
Avatar of kuppachi
kuppachi

what do u mean by in the context of another user?
Avatar of glass_cookie
Hi!

Not sure what you want exactly, but here's the code to run an application:

Shell "C:\MyFolder\MyApp.exe", vbNormalFocus

where "C:\MyFolder\MyApp.exe" is the path of the desired program.

That's it!

glass cookie : )
Hi acsmith,

The context of another user, maybe you can put your info into a database, retrieve the 'context' from database according to the logon user.

regards
You could try calling LogonUser first...

Public Declare Function Lib "kernel32" Alias "LogonUserA" (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


Let me know if you need help with the VB code to call it.
First..Make an shortcut to anything...then check the run as a other user...then rename it to another extension in dos then open the file in a hex editor and then replace the path of the program with

---<ProPath>--- then in vb load the file nad replace the ---<ProPath>---  with your program and then copy it with the  shortcut extension and then run the shortcut...

or..if it is only for one program then just run the shortcutr file
Avatar of acsmith

ASKER

blaZer, where is the "run as other user" box when creating a shortcut? (I'm running NT4)
umm...2000 here and it is right  click on shortcut, choose preferences, then under destination and right to run in seperate memory thread
Yes, that is a new feature in Windows 2000. Before that, it was available, only for NT as far as I know, in the NT resource kit. There is an exe called something like runas.exe which you use to run apps under different contexts.

Zaphod.
umm...im playing a littel with my hexeditor...lemme c what i can do
do u know the username and password or do the user have to enter it?
Avatar of acsmith

ASKER

ok, using anthony_glenwright's suggesting of calling LogonUser, I can now get the token handle of the user I want to run the new app as. Now I need to call CreateProcessAsUser, passing in this token....but I can't get it working. The call just returns false, and doing a getlasterror returns 0.
any ideas??
I don't know if this will help since you don't seem to be getting errors, but it might give you some other pointers.
check http://support.microsoft.com/support/kb/articles/Q223/3/34.asp
ASKER CERTIFIED SOLUTION
Avatar of anthony_glenwright
anthony_glenwright
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of acsmith

ASKER

cheers!
called LogonUser, ImpersonateLoggedOnUser, shell "prog.exe", then revertToSelf.
works a treat.
WOO HOO... i made it to 3000 points on the last day of the month :-)

I get to keep my KB pro user interface :-)

BTW:  Does anyone know if the search function works for the regular interface?