NEWJOB.EXE

Overview

This is a console mode application that illustrates how to view, create, and delete jobs. There are four types of jobs in SMS: Run Command On Workstation jobs, Share Package On Server jobs, Remove Package From Server jobs, and System jobs. Of these, all except System jobs can be created and deleted from the SMS API. All job types can be viewed.

This sample shows how the SmsDescribeFolder function is used to retrieve a template description of the folder and the scalars that it contains.

Running the Program

NEWJOB.EXE runs as a console application. The program prompts you to enter the information needed to connect to SQL Server, then it creates and populates a job container. At this point the program enters a loop and prompts you to view a job, delete a job, create a job, or quit the program. Enter:

C to create a new job

N to view the next job folder

D to delete the current job folder

X to exit the program

Functions

SmsDataSourceConnect
SmsDataSourceDisconnect
SmsOpenContainer
SmsCloseContainer
SmsPopulate
SmsGetFolderType
SmsGetFolderCount
SmsGetNextFolder
SmsGetFolderID
SmsCreateFolder
SmsDescribeFolder
SmsLinkFolder
SmsUnlinkFolder
SmsCommitFolder
SmsGetScalarCount
SmsGetNextScalar
SmsSetScalar
SmsRewind

Program Flow

After logging on to a datasource, a job container is created and populated. (No filters are used in this program, so you will be able to view all jobs in the system.) The program then enters a loop asking whether the user wants to view the next job folder, delete the currently viewed folder, or create a new folder. Both deletion and creation are two-stage processes. Only when the SmsCommitFolder function is called will the folder be either deleted from or inserted into the datasource.

For folder creation, the user is asked which of the three types of folders that support creation the user wants to create. The creation process then continues by soliciting scalar information from the user. For each scalar that can be set, the user is given the name of the scalar and its type. When all scalars have been set, the folder is displayed and the user is asked to confirm the creation. Successful folder creation depends on the validity of the scalar settings.