VB icon

Create database user

Email
Submitted on: 1/1/2015 10:01:00 AM
By: Newsgroup Posting (from psc cd)  
Level: Not Given
User Rating: By 39 Users
Compatibility: VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 895
 
      The following function creates a user. You can execute it under any user you like. dror-a@euronet.co.il (Dror Dotan A')
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Create database user
'**************************************
const ADMIN_USERNAME = "Admin"
const ADMIN_PASSWORD = "adminpass (or whatever)"
const SHOWICON_STOP = 16
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Create database user
' Description:
The following function creates a user. You can execute it under any user you like.
dror-a@euronet.co.il (Dror Dotan A')
' By: Newsgroup Posting (from psc cd)
'**************************************

Function CreateNewUser% (ByVal username$, ByVal password$, ByVal PID$)
'- create a new user.
'- username$ - name
'- password$ - user password
'- PID$ - PID of user
'-----------------------------------
Dim NewUser As User
Dim admin_ws As WorkSpace
'=====================================
'- check PID
If (Len(PID$) < 4 Or Len(PID$) > 20) Then
MsgBox "Invalid PID", SHOWICON_STOP
CreateNewUser% = True
Exit Function
End If
'- verify that user does not yet exist
If (UserExist%(username$)) Then
CreateNewUser% = True
Exit Function
End If
'- open new workspace and database as admin
dbEngine.Workspaces.Refresh
Set admin_ws = dbEngine.CreateWorkspace("TempWorkSpace",
 ADMIN_USER, ADMIN_PASSWORD)
If (Err) Then
'- failed opening workspace
MsgBox "invalid administrator password", SHOWICON_STOP
MsgBox "Error: " & Error$, SHOWICON_STOP, SystemName
CreateNewUser% = True
Exit Function
End If
On Error Resume Next
'- create the new user
Set NewUser = admin_ws.CreateUser(username$, PID$, password$)
If (Err) Then
MsgBox "Can't create new user.", SHOWICON_STOP
MsgBox Error$, SHOWICON_STOP
GoTo CreateNewUser_end
End If
'- add user to user list
admin_ws.Users.Append NewUser
'- add user to "Users" group
Set NewUser = admin_ws.CreateUser(username$)
admin_ws.Groups("Users").Users.Append NewUser
admin_ws.Users(username$).Groups.Refresh
admin_ws.Close
CreateNewUser% = False
CreateNewUser_end:
On Error GoTo 0
End Function


Other 14 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.