The starting point of any operations with the Northern Quota Server COMAPI is the session, represented by the QSComApiSession class. Before you can do anything, you need to:
- Create an instance of the QSComApiSession class
- Connect that instance to a Northern Quota Server server
Using Visual Basic
' Create a new session object
Dim QSS As New QSCOMAPILib.QSComApiSession
' Set Server
QSS.Server = “my QS server name with no backslash”
Using C++
using namespace QSCOMAPILib;
// Create a new session object and acquire a pointer to it.
IQSComApiSessionPtr * pSessionSmartPtr;
IQSComApiSession * pSession;
// first instantiate the smart pointer, which wraps CoCreateInstance etc.
pSessionSmartPtr = new IQSComApiSessionPtr(__uuidof(QSComApiSession));
// now, let's get a pointer to the interface we want to use.
pSession = pSessionSmartPtr->GetInterfacePtr();
// Set Server
pSession->PutServer( _bstr_t( “my QS server name with no backslash” ) );
Using C#
//Create a new session object
QSCOMAPILib.QSComApiSession session = new QSCOMAPILib.QSComApiSession();
//Set Server
session.Server = "my QS server name with no backslash";
Using Powershell
#Create a new session object
$session = New-Object -ComObject QSComApi.QSComApiSession
#Set Server
$session.server = "my QS server name with no backslash";
Getting a Quota
With the Session instance, described above, you can get or set quotas, templates, reports, and permissions on the server you are connected to. You, however, have to do that through the Collection classes. To get a quota:
- Get the IQSQuotaItemCollection from the session
- Get the quota from that collection
Note that Quotas are indexed by 5 values:
- The server name where the quota is.
- The object path on which the quota applies.
- The account on which the quota applies.
- The external quota string, which is reserved for future use and must always be empty.
- A flag specifying if the quota is a template or a real quota.
Using Visual Basic
'…using the session before
' Create an new quota item
Dim tmpQuota As QSCOMAPILib.QSComApiQuotaItem
' Set the new quota item as a copy of the requested quota
' Server_Name is a string with the name of the server we connected to
' Object_Path is a string with the path to the object, like C:\Users
' User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
' ExternalQuota is a string reserved for future use and must be empty
' IsTemplate is a Boolean with whether this quota is a template or not
Set tmpQuota = QSS.Quotas.Get(Server_Name, Object_Path, User_Account, ExternalQuota, IsTemplate)
Using C++
// …get the session before
// Get QuotaItemCollection Pointer
IQSComApiQuotaItemCollection* pQICollection = NULL;
// Get quotas from collection
pQICollection = pSession->GetQuotas();
// Server_Name is a string with the name of the server we connected to
// Object_Path is a string with the path to the object, like C:\Users
// User_Account is a string with the name of the account the quota apply to, or EVERYONE
// ExternalQuota is a string reserved for future use and must be empty
// IsTemplate is a Boolean with whether this quota is a template or not
IQSComApiQuotaItem* pItem = pQICollection->Get(Server_Name,Object_Path,User_Account, ExternalQuota, IsTemplate );
Using C#
…using the session before
// Set the new quota item as a copy of the requested quota
// Server_Name is a string with the name of the server we connected to
// Object_Path is a string with the path to the object, like C:\Users
// User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
// ExternalQuota is a string reserved for future use and must be empty
// IsTemplate is a Boolean with whether this quota is a template or not
QSCOMAPILib.IQSComApiQuotaItem quota = session.Quotas.Get(Server_Name, Object_Path, User_Account, ExternalQuota, IsTemplate);
Using Powershell
…using the session before
# Set the new quota item as a copy of the requested quota
# Server_Name is a string with the name of the server we connected to
# Object_Path is a string with the path to the object, like C:\Users
# User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
# ExternalQuota is a string reserved for future use and must be empty
# IsTemplate is a Boolean with whether this quota is a template or not
$server_name = "Same as session.server"
$Object_Path = "C:\files\test..."
$User_Account = "user or group"
$quota = $session.Quotas.Get($Server_Name,$Object_Path, $User_Account, $ExternalQuota, $False )
Setting a Quota
The setting of a quota is slightly different from the getting of a quota. To set a quota:
- Get the IQSQuotaItemCollection from the session
- Create a quota item
- Set the quota item in the collection
Since items are identified by 5 keys or properties (server name, object path, account, external quota, and template flag), you need to set at least those 5 properties in the quota item, using the following 5 methods:
- IQSComApiQuotaItem::PutServer ( string )
- IQSComApiQuotaItem::PutObject ( string )
- IQSComApiQuotaItem::PutAccount ( string )
- IQSComApiQuotaItem::PutExternalQuota ( string )
- IQSComApiQuotaItem::PutIsTemplate(boolean)
Again, account is EVERYONE, if the quota is not tied to a specific user. External Quota is reserved for future use, and must always be empty.
Using Visual Basic
' …get the session before
' Create a new quota item
Dim tmpQuota As QSCOMAPILib.QSComApiQuotaItem
' Set the items values
tmpQuota.QuotaSize = 128000
tmpQuota.Server = “MyServer”
tmpQuota.Object = ”\\MyServer\Users\john”
tmpQuota.Account = “Everyone”
tmpQuota.ExternalQuota = “”
tmpQuota.IsTemplate = False
' Set the quota in the collection
QSS.Quotas.Set tmpQuota
Using C++
// …get the session before
// Get QuotaItemCollection Pointer
IQSComApiQuotaItemCollection*pQICollection = NULL;
// Get quotas from collectionpQI
Collection = pSession->GetQuotas();
IQSComApiQuotaItemPtr*pItemSmartPtr;
IQSComApiQuotaItem* pItem;
// instantiate a pointer to the interface
spItem = new IQSComApiQuotaItemPtr(__uuidof(QSComApiQuotaItem));
// access the item in the interface
pItem = spItem->GetInterfacePtr();
// set the quota value
pItem->PutServer(_T(“MyServer”));
pItem->PutObject(_T(“\\\\MyServer\\Users\john”));
pItem->PutAccount(_T(“Everyone”));
pItem->PutExternalQuota(_T(“”);
pItem->PutIsTemplate(FALSE);
pItem->PutQuotaSize(128000);
// set the quota in the collection
IQSComApiQuotaItem*pItem = pQICollection->Set(pItem);
Using C#
…using the session before
// Set the new quota item as a copy of the requested quota
// Server_Name is a string with the name of the server we connected to
// Object_Path is a string with the path to the object, like C:\Users
// User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
// ExternalQuota is a string reserved for future use and must be empty
// IsTemplate is a Boolean with whether this quota is a template or not
//Create an new quota item
QSCOMAPILib.QSComApiQuotaItem quota = new QSCOMAPILib.QSComApiQuotaItem();
//Set the items values
quota.Server = Server_Name;
quota.Object = Object_Path;
quota.Account = User_Account;
quota.ExternalQuota = ExternalQuota,
quota.IsTemplate =IsTemplate;
//Set the quota
session.Quotas.Set(quota);
Using Powershell
…using the session before
# Set the new quota item as a copy of the requested quota
# Server_Name is a string with the name of the server we connected to
# Object_Path is a string with the path to the object, like C:\Users
# User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
# ExternalQuota is a string reserved for future use and must be empty
# IsTemplate is a Boolean with whether this quota is a template or not
#Create a new quota item
$quota = New-Object -ComObject QSComApi.QSComApiQuotaItem
#Set the items values
$quota.Server = $Server_Name
$quota.Object = $Object_Path
$quota.Account = $User_Account
$quota.ExternalQuota = $ExternalQuota
$quota.isTemplate = $False
#Set the quota
$session.Quotas.Set($quota)
Enumerating Quotas
To enumerate all the quotas on a server follow these steps:
- Get the IQSQuotaItemCollection from the session
- Go through the collection with the enumerator
Using VisualBasic
' …get the session before
' Dimension a counter
Dim lQuota as Long
' Create a new quota item
Dim tmpQuota As QSCOMAPILib.QSComApiQuotaItem
'Enumerate the quotas
For lQuota = 1 To QSS.Quotas.Count
TmpQuota = QSS.Quotas.Item(lQuota)
' Do something with the quota item
Next
Using C++
In C++ the code is not perhaps as orderly as one would hope, but this is of course due to the type of manipulations required by COM.
// …get the session before
// Get QuotaItemCollection Pointer
IQSComApiQuotaItemCollectionPtrpQICollection = NULL;
// Get quotas from collectionp
QICollection = pSession->GetQuotas();
// get pointer to IUnknown for enumerator object
IunknownPtr pQ = pQICollection->Get_NewEnum();
IEnumVARIANT* pEnum;
// query for the IEnumVARIANT interfacep
Q->QueryInterface( IID_IEnumVARIANT, (void**)&pEnum);
// release IUnknown pointer herepQ->Release();
HRESULT hr;
// okay, let's enumerate all quotas
// start by resetting the enumerator object
hr = pEnum->Reset();do {VARIANT var;
// get next quota object from the collection
hr = pEnum->Next(1, &var, NULL);
if (S_OK == hr) {
IQSComApiQuotaItemPtr*pItemSmartPtr;
QSComApiQuotaItem* pItem;
// okay, let's build ourselves a smart pointer here
pItemSmartPtr = new IQSComApiQuotaItemPtr(var.punkVal);
pItem = pItemSmartPtr->GetInterfacePtr();
// Do something with the quota item
DoSomething( pItem );
pItem->Release();
delete pItemSmartPtr;
}
} while (S_OK == hr);
Using C#
…using the session before
foreach (QSCOMAPILib.QSComApiQuotaItem quota in session.Quotas)
{
//Do something with the quota
}
Using Powershell
…using the session before
ForEach($quota in $session.Quotas)
{
#Do something with the quota
}
Deleting a Quota
The deletion of a quota is quite straightforward. To delete a quota:
- Get the IQSQuotaItemCollection from the session.
- Get or create the quota.
- Delete the quota.
Using Visual Basic
' …get the session before
' Create a new quota item
Dim tmpQuota As QSCOMAPILib.QSComApiQuotaItem
' Since items are identified by 5 keys (server name, object path, account, external quota and template flag), you need to set those 5 properties in the quota item with the following 5 methods:
' Set the items values
tmpQuota.QuotaSize = 128000
tmpQuota.Server = “MyServer”
tmpQuota.Object = ”\\MyServer\Users\john”
tmpQuota.Account = “Everyone”
tmpQuota.ExternalQuota = “”
tmpQuota.IsTemplate = False
' Delete the quota
QSS.Quotas.Delete tmpQuota
Using C++
// …get the session before
// Get QuotaItemCollection Pointer
IQSComApiQuotaItemCollectionPtrpQICollection = NULL;
// Get quotas from collection
pQICollection = pSession->GetQuotas();
if( enumerate == false ) {
// instantiate a pointer to the interface
pItemSmartPtr = new IQSComApiQuotaItemPtr(__uuidof(QSComApiQuotaItem));
// access the item in the interfacepItem = pItemSmartPtr->GetInterfacePtr();
// set the quota values
// Since items are identified by 5 keys (server name, object path, account, external quota and template flag), you need to set at those 5 properties in the quota item with the following 5 setters
pItem->PutServer(_T(“MyServer”));
pItem->PutObject(_T(“\\\\MyServer\\Users\john”));
pItem->PutAccount(_T(“Everyone”));
pItem->PutExternalQuota(_T(“”);
pItem->PutIsTemplate(FALSE);
// delete the quota in the collection
pQICollection->Delete(pItem);
} else {
// get pointer to IUnknown for enumerator objectIunknownPtr pQ = pQICollection->Get_NewEnum();
IEnumVARIANT* pEnum;
// query for the IEnumVARIANT interface
pQ->QueryInterface( IID_IEnumVARIANT, (void**)&pEnum);
// release IUnknown pointer here
pQ->Release();
HRESULT hr;
// okay, let's enumerate all quotas
// start by resetting the enumerator object
hr = pEnum->Reset();
do {
VARIANT var;
// get next quota object from the collection
hr = pEnum->Next(1, &var, NULL);
if (S_OK == hr) {
IQSComApiQuotaItemPtr*pItemSmartPtr;
IQSComApiQuotaItem* pItem;
// okay, let's build ourselves a smart pointer here
pItemSmartPtr = new IQSComApiQuotaItemPtr(var.punkVal);
pItem = pItemSmartPtr->GetInterfacePtr();
// Do something with the quota item
pQICollection->Delete( pItem );
pItem->Release();
delete pItemSmartPtr;
}
} while (S_OK == hr);
Using C#
…using the session before
// Set the new quota item as a copy of the requested quota
// Server_Name is a string with the name of the server we connected to
// Object_Path is a string with the path to the object, like C:\Users
// User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
// ExternalQuota is a string reserved for future use and must be empty
// IsTemplate is a Boolean with whether this quota is a template or not
//Create a new quota item
QSCOMAPILib.QSComApiQuotaItem quota = new QSCOMAPILib.QSComApiQuotaItem();
//Set the items values
quota.Server = Server_Name;
quota.Object = Object_Path;
quota.Account = User_Account;
quota.ExternalQuota = ExternalQuota;
quota.IsTemplate = IsTemplate;
//Delete the quota
session.Quotas.Delete(quota);
Using Powershell
…using the session before
# Set the new quota item as a copy of the requested quota
# Server_Name is a string with the name of the server we connected to
# Object_Path is a string with the path to the object, like C:\Users
# User_Account is a string with the name of the account the quota apply to,‘ or EVERYONE
# ExternalQuota is a string reserved for future use and must be empty
# IsTemplate is a Boolean with whether this quota is a template or not
#Create a new quota item
$quota = New-Object -ComObject QSComApi.QSComApiQuotaItem
#Set the items values
$quota.Server = $Server_Name
$quota.Object = $Object_Path
$quota.Account = $User_Account
$quota.ExternalQuota = $ExternalQuota
$quota.isTemplate = $False
#Delete the quota
$session.Quotas.Delete($quota)
Receiving Further Assistance
It is of course possible to receive direct assistance in the use of the Northern Quota Server COM API from Northern personnel. However support of this advanced usage, in terms of guidance and further code examples, is not covered by the normal terms of a Support and Maintenance agreement; it is reliant on the availability of purchased Professional Services hours. Please contact your Northern Account Manager if you require further assistance in the use of this COM API.