Discussion Locked

Run a program as a different user

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a VB program that does some things like adding & managing users, editing file/directory permissions, etc. My problem is that in order for the user to run the command to create a user, they need to have Admin rights (or at least create user rights) on the server they run it on. I don't want that. I've seen ASP components before that allow you to specify a username/password that the program runs as, so, say, a normal user could run the program but the command would execute as though they were logged on as Administrator.

Does anyone know how to do this in Visual Basic?

--Aaron

5 replies

by bojidar alexandrov

GEEK I want to create a Visual Basic-based component that will accept a user's login credentials, check their validity, then check whether that user is a member of a given domain group. I don't want to track user security in a database, but instead rely on the existing security model of Windows NT. All authorized users of my application will be members of a particular group in the domain. How can I do this with the Win32? API?
GEEK When you say "accept a user's login credentials," do you mean that you want your application to display a dialog box in which the user enters their user name and password, which your application in turn passes on to the system? If so, this is a dangerous thing, since you would essentially be impersonating the security of the system. This is not something that can be provided without consequences.
The user should have already been required to authenticate themselves to the system if they're working directly from a networked workstation that is part of the specified domain. If the user is accessing your system via the Web, then again, this can be accomplished within the confines of the OS by simply assigning the appropriate privileges to the files that the user might be trying to access. The system will then issue a challenge/response, which will force a login request.
Your application's simple attempt to open a file to which only the appropriate users would have read access would be a quick way to test for authentication.
If you're attempting a Web-based login, essentially the same process could be used. Access privileges would be set not against a file, but against the Web pages that users are trying to access. This would tie the security directly to the Web access via the Windows NT-based user database.

by salexru2000

Check CreateProcess win32 function and related security topics in MSDN.

Smaple Prototype:
Declare Function CreateProcess Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributesAs Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Any, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

This discussion is closed to new replies.