Link to home
Start Free TrialLog in
Avatar of AndreasOlausson
AndreasOlausson

asked on

Shell runas inside a VB-application

I would like to execute another program with a shellcommand inside a VB-application.

Take Notepad as an example.

If only Admin is allowed to execute Notepad and you want to execute it you have to do it by running runas.

I would like to make a little program, lets call it "RunNotepad"

This would work if I was Admin
Private Sub Form_Load()
   Shell "Notepad"
End Sub
 
But It would crach if I don't have the privelegies.

I could use the advapi32.dll and "ImpersonateLoggedOnUser" and so on, but the user must have the priveleges as "Act as part of operating system" and I don't want that.

I could use this...
Private Sub Form_Load()
   Shell "cmd /c runas /noprofile /user:domain\Admin notepad"
End Sub
...but If I do the Commandwindow pops up and asks me to enter the password for admin.

Is it possible to let the VB application take care of the passwordtyping and don't interact with the user that executes the application?


Thanks a lot!
Andreas Olausson - Sweden
Avatar of Cimperiali
Cimperiali
Flag of Italy image

No, as far as I know.
One thing you could do is build a service that has enough priviledges (that meaning administrator installed it) that can launch app for you as if you were admin. But admin shoudl grant you priviledge to use it....
Avatar of AndreasOlausson
AndreasOlausson

ASKER

Thanks for the comment Cimperiali!

The thing is, the application that must have Adminpriviledges should be executed by the network-logon-script (a .bat-file).
This application will copy a dllfile and register it if it not exists on the users local machine and write some keys to the registry.
I don't what to let the user be allowed to register dll's or edit the registry.

So If I build a Service and put it on a networkshare that all users has access to and grant them rights to execute it should that solve the problem.

I would like to avoid running around and make this machine by machine, it's a couple of them...

If a build the service, should I use srvany.exe? (Q137890 knowledgebase)

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of GERTJAN
GERTJAN

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
Thanks I'll guess that will solve the problem for me!

Regards
Andreas