VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create database user

by Newsgroup Posting (15 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (39 Votes)


The following function creates a user. You can execute it under any user you like.
[email protected] (Dror Dotan A')

API Declarations
const ADMIN_USERNAME = "Admin"
const ADMIN_PASSWORD = "adminpass (or whatever)"
const SHOWICON_STOP = 16

Rate Create database user

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

Download this snippet    Add to My Saved Code

Create database user Comments

No comments have been posted about Create database user. Why not be the first to post a comment about Create database user.

Post your comment

Subject:
Message:
0/1000 characters