| • | Creates a stored procedure, called IdentifyComputer, which creates a unique computer name, and then updates the AdminDB database with the new computer name, the MAC address, the make of the workstation, and the model of the workstation. Note In the new machine scenario, you may want to include additional logic in the IdentifyComputer stored procedure to automatically populate the OSDINSTALLPACKAGE and OSDINSTALLPROGRAM columns (for example, based on the make and model passed). The current version of the script does not have this feature implemented. Note Some parts of the following code snippet have been displayed in multiple lines only for better readability. These should be entered in a single line. use [BDDAdminDB]
GO
if exists (select * from dbo.sysobjects where
id = object_id(N'[dbo].[IdentifyComputer]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[IdentifyComputer]
GO
if exists (select * from dbo.sysobjects where
id = object_id(N'[dbo].[MachineNameSequence]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MachineNameSequence]
GO
CREATE TABLE [dbo].[MachineNameSequence] (
[Prefix] [varchar] (50)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Sequence] [int] NOT NULL
) ON [PRIMARY]
GO
INSERT INTO [dbo].[MachineNameSequence]
(Prefix, Sequence) VALUES ('PC', 0)
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[IdentifyComputer]
@MacAddress CHAR(17),
@Make VARCHAR(50),
@Model VARCHAR(50)
AS
DECLARE @Cnt INT,
@Prefix VARCHAR(50),
@Sequence INT,
@NewName VARCHAR(50)
SET NOCOUNT ON
/* See if there is an existing record for this machine */
SELECT @Cnt=COUNT(*) FROM BDDAdminCore
WHERE MacAddress = @MacAddress
/* No record? Add one. */
IF @Cnt = 0
BEGIN
/* Create a new machine name */
BEGIN TRAN
SELECT @Prefix=Prefix, @Sequence=Sequence
FROM MachineNameSequence
SET @Sequence = @Sequence + 1
UPDATE MachineNameSequence SET
Sequence = @Sequence
SET @NewName = @Prefix +
Right('00000'+LTrim(Str(@Sequence)),5)
/* Insert the new record */
INSERT INTO BDDAdminCore (MacAddress,
Make, Model, ComputerName, OSDNewMachineName,
OSDInstallSilent, OSInstall)
VALUES (@MacAddress, @Make, @Model,
@NewName, @NewName, '1', 'Y')
COMMIT TRAN
END
/* Return the record as the result set */
SELECT * FROM BDDAdminCore
WHERE MacAddress = @MacAddress
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOListing 45. BDDAdminDB-IdentifyComputer.sql script to create table and IdentifyComputer stored procedure .
.
.
[IdentifyComputer]
SQLDefault=DB_IdentifyComputer
[DB_IdentifyComputer]
SQLServer=SERVER1
Database=BDDAdminDB
StoredProcedure=IdentifyComputer
Parameters=MacAddress, Make, Model Listing 46. Excerpt from the Customsettings.ini file that calls the IdentifyComputer stored procedure |