IVSSDatabase.AddUser MethodÂ
Adds a new user to the current database IVSSUsers collection.
Namespace: Microsoft.VisualStudio.SourceSafe.Interop
Assembly: Microsoft.VisualStudio.SourceSafe.Interop (in microsoft.visualstudio.sourcesafe.interop.dll)
Syntax
'Declaration
Function AddUser ( _
<InAttribute> User As String, _
<InAttribute> Password As String, _
<InAttribute> ReadOnly As Boolean _
) As VSSUser
'Usage
Dim instance As IVSSDatabase
Dim User As String
Dim Password As String
Dim ReadOnly As Boolean
Dim returnValue As VSSUser
returnValue = instance.AddUser(User, Password, ReadOnly)
VSSUser AddUser (
[InAttribute] string User,
[InAttribute] string Password,
[InAttribute] bool ReadOnly
)
VSSUser^ AddUser (
[InAttribute] String^ User,
[InAttribute] String^ Password,
[InAttribute] bool ReadOnly
)
VSSUser AddUser (
/** @attribute InAttribute() */ String User,
/** @attribute InAttribute() */ String Password,
/** @attribute InAttribute() */ boolean ReadOnly
)
function AddUser (
User : String,
Password : String,
ReadOnly : boolean
) : VSSUser
Parameters
- User
Unique name of a new user added to the database.
- Password
A password of the new user.
- ReadOnly
true assigns new user read-only rights to the database, false assigns the rights set by DefaultProjectRights property.
Return Value
A reference of a IVSSUser type to an object representing a single IVSSUser.
Remarks
The SourceSafe Administrator can add new users to the current SourceSafe database. The AddUser method does that by adding a new user to the collection of IVSSUsers. If you attempt to add a user that already exists or give a user an invalid password, a run-time error is generated. An empty string sets the password to nothing. The AddUser method may be called only by an Admin. If another user attempts to call the AddUser method, a run-time error is generated.
When the ReadOnly parameter is set to true, the DefaultProjectRights settings of the database are overridden by read-only rights. For example, if DefaultProjectRights is set to VSSRIGHTS_ALL, and a new user is added to the database with the ReadOnly parameter set to true, the new user will have VSSRIGHTS_READ rights to the database, not VSSRIGHTS_ALL. If the ReadOnly parameter is set to false, the new user is given whatever rights are assigned by DefaultProjectRights.
Example
The following example demonstrates how to use the AddUser property to add a new user to the SourceSafe database.
[C#]
using System;
using Microsoft.VisualStudio.SourceSafe.Interop;
public class IVSSTest
{
private static void DisplayUsers(IVSSDatabase vssDatabase)
{
Console.Write("Database Users:");
foreach(IVSSUser vssUser in vssDatabase.Users)
Console.Write(" {0}", vssUser.Name);
Console.WriteLine();
}
private static string GetUsername()
{
Console.Write("Enter Username: ");
return Console.ReadLine();
}
private static string GetPassword()
{
Console.Write("Enter Password: ");
return Console.ReadLine();
}
public static void Main()
{
// Create a VSSDatabase object.
IVSSDatabase vssDatabase = new VSSDatabase();
// Only SourceSafe Admin can add a new user.
Console.WriteLine("Admin login");
vssDatabase.Open(@"C:\VSSTestDB\srcsafe.ini",
GetUsername(), GetPassword());
DisplayUsers(vssDatabase);
// Add new user to the database.
Console.WriteLine("Add New User");
IVSSUser vssUser =
vssDatabase.AddUser(GetUsername(),
GetPassword(), false);
DisplayUsers(vssDatabase);
// Remove a user from the database
vssUser.Delete();
DisplayUsers(vssDatabase);
}
}
Output:
Admin login
Enter Username:
Enter Password:
Database Users: Admin Guest1 Guest2
Add New User
Enter Username: NewUser
Enter Password:
Database Users: Admin Guest1 Guest2 NewUser
Database Users: Admin Guest1 Guest2 (NewUser is removed)
See Also
Reference
IVSSDatabase Interface
IVSSDatabase Members
Microsoft.VisualStudio.SourceSafe.Interop Namespace