Novell Home

Re-imaging an NT PC from an icon

Novell Cool Solutions: Feature
By Russell Moore

Digg This - Slashdot This

Posted: 11 Aug 1999
 

Russell Moore sent this creative solution that allows you to re-image a PC (running Windows NT) from an icon in App Launcher. When the image is done, the PC will remember its old name and reassociate itself with its workstation object. Nifty, huh? It's not for the faint of heart, but it's wonderful if you're up to it. Thanks, Russell.

How to re-image a PC running WinNT from an App Launcher icon, get it to remember its name and the login context for the login screen, and get it to re-associate itself with its NDS workstation object.

Prerequisites
Overview
Details
Files, Scripts, etc.

Prerequisites:

  • No advance prep of the workstation is required, but the workstation must have a FAT boot partition.
  • You must have a fully automated unattended install of NT, run from the network.
  • Sorry, but unless you are using ZENworks 2, the person who is going to run this icon must have admin access to the local PC.
  • To fully follow this document you will need to be familiar with the NT unattend process. More information about the unattend process can be found in the Microsoft WINNT Workstation Resource kit.

Overview

First, an overview of what is going to happen, then we'll get into all the details:

  1. Copy down a DOS NetWare client to the PC, and the WIN98 OS (Command line only), along with some batch files to script the whole thing out.
  2. Extract the information about the PC (the Name and NDS object it uses, and login context) and store it on the network.
  3. Reboot to the Win98 command prompt, load the Client, and connect to the network.
  4. Install NT (using the correct PC name), then re-associate it with its NDS object, and restore the Login Context.

Details

Now, how to do all of these things...

Copy DOS NetWare and Win98

Copy down a NetWare client and Win98 OS to the PC. This is an easy one. You use App Launcher to copy the files to the PC. You can see the full list of files in the axt at the end, but basically, it is a copy of client 32, and the Win98 boot files. It also includes batch files to automatically start up the client when the PC is started in Win98 command mode only. It also includes a boot.ini, but more about that in a minute.

Extract PC info

Get the info about the PC and store it. You need to get the name of the PC as well as the NDS object name it is using, and the login context of the PC. You will need to store that info out on the network in a place you can get it from later. I chose to create a directory with the MAC address of the PC as the directory name (since it is unique, meaning that I can run as many of these at a time as I want).

App Launcher creates the directory for us using the variable P_STATION. All of the information is retrieved from the registry. To store the Name, I just copy my unattended.txt file to my directory, and put the name of the workstation right into the now personalized copy of unattend.txt.

The NDS object name and Login Context are placed into an INI file to be retrieved later. The retrieval of the name of the WS and the NDS object name are done with a WinBatch script (the script is attached at the end, name.wil). The app uses an INI file to tell it where to store all the info, and the INI file is made by App Launcher, in the INI section. It also stores on the PC the short name for the directory we created, so we can use it later from DOS.

Reboot in Win98 Command Mode

Reboot the PC in Win98 Command Mode. This is the tricky part, and the part that requires admin access to the local box. Since the boot drive is FAT (see prerequisites), we are going to make our own BOTSECT.DOS file, and use that to boot up the PC. When NT boots, it uses its own boot loader, then processes the boot.ini.

If the User, or Boot.ini, tells the PC to boot into some OS other than NT, the NT loader replaces itself with the specified boot sector from the other OS. This file is the contents of the bootsector for the drive that would be used if that OS were the only OS on the PC.

Now, here's a little gotch. You can't copy this file around from PC to PC and expect it to work, since it contains drive geometry info. So there is a utility called BOOTPART, that will make it for you. You can get a copy of it from the author,G. Vollant, (info@winimage.com) at his web site http://www.winimage.com/bootpart.htm. It was, as of the time of this writing, freeware. So bootpart is going to make this machine specific bootsect.dos for you (it is run from the App Launcher object).

Now all you have to do is modify the boot.ini to boot that OS first, and not to wait. I did it by copying down my own boot.ini. So now, when the machine reboots, it is going to reboot in Win98 command prompt. App Launcher is nice enough to do the reboot for us.

Install NT

Once the PC has booted, do the Unattended Install of the PC.
  1. First load the client, and connect to the network.
  2. Then figure out what the short name of our MAC address is, so you can find your unattend.txt file (App Launcher and name.wil put a batch file on the PC to transfer this info to an environment variable for you).
  3. Then, change your comspec to run Win98's command.com from the network server. (This is important after the drive is formatted if you don't).
  4. Then format the C-drive of the PC.
  5. Once you have done that, copy the REGINFO.INI to the root of the c: drive. You will need this info to be here later.
  6. Then we start the Unattend process using the customized version in our special MAC address directory.
  7. At the end of the Unattended Install process, run (from cmdlines.txt) the program rereg.ini. This will place the Workstation Manager info back into the registry for you. That way, WM knows the name of the NDS object is associated with. Rereg is a WinBatch program (source included at the end). It will also set the login context back to the old value as well.
  8. Now, just reboot the PC (it will do this itself). When the PC starts up, WM will run all of its policies.

Now your NT PC has been formatted & reimaged, remembered its name, re-associated itself with the NDS WS object, and remembered the login context of the PC. -- COOL!!

Files, Scripts, etc.

AXT
After Script
Name.wil
Rereg
Autoexec.bat
Unatt98.bat

AXT

This is the AXT file:

AXT_FILE 2.5

[Application Name]
Value=IMAGE THIS PC

[Application Caption]
Value=IMAGE THIS PC

[Macro]
Name=SOURCE_DIR
Value=\\tam103qa01\sys\image

[Application Description]
File=DESC015A.TXT

[Application Path]
Value=c:\bootpart.exe

[Application Flags]
Flag=Never Prompt Reboot
Flag=Always Distribute Application
Flag=Prompt Before Distribute

[Application Parameters]
Value=win98 bootsect.img image

[Application Platform]
Flag=Windows NT

[Application Shutdown Script]
File=POST0082.TXT

[Application Working Directory]
Value=c:\

[INI Identifier Create]
Flag=Write Always
File=c:\reimage.ini
Section=mac
Identifier=mac
Value=%P_STATION%

[INI Identifier Create]
Flag=Write Always
File=c:\reimage.ini
Section=filelocations
Identifier=unattend
Value=%source_dir%\nic\%p_station%

[Directory Create]
Directory=%SOURCE_DIR%\nic\%P_STATION%

[Directory Create]
Flag=Write Always
Directory=C:\Novell\CLIENT32

[Directory Create]
Flag=Write Always
Directory=C:\Novell\CLIENT32\NLS

[Directory Create]
Flag=Write Always
Directory=C:\Novell\CLIENT32\NLS\ENGLISH

[File Copy]
Flag=Update Create
Source=%SOURCE_DIR%\nt\i386\3c90x.txt
Target=%SOURCE_DIR%\nic\%P_STATION%\3c90x.txt

[File Copy]
Flag=Update Create
Source=%SOURCE_DIR%\nt\i386\madge.txt
Target=%SOURCE_DIR%\nic\%P_STATION%\madge.txt

[File Copy]
Flag=Update Create
Source=%SOURCE_DIR%\nt\i386\octok.txt
Target=%SOURCE_DIR%\nic\%P_STATION%\octok.txt

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\autoexec.bat
Target=c:\autoexec.bat

[File Copy]
Flag=Update Create
Source=%SOURCE_DIR%\IMAGE THIS PC\boot.bat
Target=c:\boot.bat

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\boot.ini
Target=c:\boot.ini

[File Copy] Flag=Update Create
Source=%SOURCE_DIR%\IMAGE THIS PC\bootpart.exe
Target=c:\bootpart.exe

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\24.fil
Target=C:\COMMAND.COM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\config.sys
Target=c:\config.sys

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\25.fil
Target=C:\DRVSPACE.BIN

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\26.fil
Target=C:\HIMEM.SYS

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\27.fil
Target=C:\IO.SYS

[File Copy]
Flag=Update Create
Source=%SOURCE_DIR%\IMAGE THIS PC\logo.sys
Target=c:\logo.sys

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\28.fil
Target=C:\MSDOS.SYS

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\29.fil
Target=C:\NBIHW.CFG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\10.fil
Target=C:\Novell\CLIENT32\3C90X.LAN

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\1.fil
Target=C:\Novell\CLIENT32\CLIENT32.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\8.fil
Target=C:\Novell\CLIENT32\CMDGODI.LAN

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\2.fil
Target=C:\Novell\CLIENT32\CMSM.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\11.fil
Target=C:\Novell\CLIENT32\ETHERTSM.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\3.fil
Target=C:\Novell\CLIENT32\IPX.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\4.fil
Target=C:\Novell\CLIENT32\LSLC32.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\6.fil
Target=C:\Novell\CLIENT32\NBIHW.CFG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\7.fil
Target=C:\Novell\CLIENT32\NET.CFG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\9.fil
Target=C:\Novell\CLIENT32\NIOS.EXE

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\14.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\CLIENT32.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\15.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\CMSM.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\16.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\IPX.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\17.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\LSL.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\18.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\LSLC32.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\19.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\NESL.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\20.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\NIOS.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\21.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\NIOSWIN.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\22.fil
Target=C:\Novell\CLIENT32\NLS\ENGLISH\TOKENTSM.MSG

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\13.fil
Target=C:\Novell\CLIENT32\OCTOK162.LAN

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\5.fil
Target=C:\Novell\CLIENT32\SPX_SKTS.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\12.fil
Target=C:\Novell\CLIENT32\TOKENTSM.NLM

[File Copy]
Flag=Write Always
Source=%SOURCE_DIR%\IMAGE THIS PC\30.fil
Target=C:\PW.TXT

[Text File Add Begin]
Flag=No Reboot Needed
File=c:\setmac.bat
String=set mac=%P_STATION%

After Script (post082.txt)

#\\tam103qa01\sys\image\IMAGE THIS PC\name.exe
#G:\ncshtdwn\Ncshtdwn.exe /5

This is Name.wil

mac=IniReadPvt("MAC","MAC","000000000000","C:\REIMAGE.INI")
unattendpath=IniReadPvt("filelocations","unattend","", "C:\REIMAGE.INI")

cpuname=RegQueryValue( @REGMACHINE,
"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\[ComputerName]")

logincontext=RegQueryValue( @REGMACHINE, "SOFTWARE\Novell\Location Profiles\Services\{1E6CEEA1-FB73-11CF-BD76-00001B27DA23}\Default\Tab1\[Context]")

If logincontext <> ""
IniWritePvt ("REGINFO","loginContext", logincontext,"%unattendpath%\NDSINFO.INI")
endif

ErrorMode(@off)
LastError()
NDSOBJNAME=RegQueryValue( @REGMACHINE, "SOFTWARE\Novell\Workstation Manager\Identification\[Workstation Object]")
err=LastError()
ErrorMode(@cancel)
if err<>0
NDSOBJNAME = ""
endif
IniWritePvt ("REGINFO","NDSOBJ",NDSOBJNAME,"%unattendpath%\NDSINFO.INI")

IniWritePvt ("UserData","ComputerName","""%cpuname%""","%unattendpath%\madge.txt")
IniWritePvt ("UserData","ComputerName","""%cpuname%""","%unattendpath%\octok.txt")
IniWritePvt ("UserData","ComputerName","""%cpuname%""","%unattendpath%\3c90x.txt")

shortmac=FileNameShort("%unattendpath%")
shortmac=Fileroot(shortmac)
handle = fileopen ("c:\setmac.bat","Write")
FileWrite (handle, "set mac=%shortmac%")
fileclose(handle)

This little program is rereg:

NDSOBJNAME=IniReadPvt("REGINFO", "NDSOBJ","","C:\NDSINFO.INI")
logincontext=IniReadPvt("REGINFO", "logincontext","","C:\NDSINFO.INI")

If logincontext <> ""
RegSetValue(@REGMACHINE, "SOFTWARE\Novell\Location
Profiles\Services\{1E6CEEA1-FB73-11CF-BD76-00001B27DA23}
\Default\Tab1\[Context]",logincontext)
endif

If NDSOBJNAME <> ""
RegSetValue(@REGMACHINE, "SOFTWARE\Novell\Workstation Manager\Identification\[Workstation Object]",NDSOBJNAME)
endif

Batch Files

Autoexec.bat

@ECHO OFF
call c:\setmac.bat
set ver=udid1
CLS
SET PATH=C:\
@ECHO OFF
SET NWLANGUAGE=ENGLISH
C:\NOVELL\CLIENT32\NIOS.EXE /W
rem LOAD A:\NOVELL\CLIENT32\NBIC32.NLM
LOAD C:\NOVELL\CLIENT32\LSLC32.NLM
LOAD C:\NOVELL\CLIENT32\CMSM.NLM
LOAD C:\NOVELL\CLIENT32\TOKENTSM.NLM
LOAD C:\NOVELL\CLIENT32\etherTSM.NLM
LOAD C:\NOVELL\CLIENT32\CMDGODI.LAN FRAME=TOKEN-RING MSB
IF ERRORLEVEL 1 GOTO NOTMADGE
set nic=madge
GOTO CLIENT
:NOTMADGE
LOAD C:\NOVELL\CLIENT32\OCTOK162.LAN FRAME=TOKEN-RING MSB
IF ERRORLEVEL 1 GOTO NOTOCTOK
set nic=OCTOK
GOTO CLIENT
:NOTOCTOK
load C:\novell\client32\3c90x.lan frame=ethernet_II
IF ERRORLEVEL 1 GOTO NOT3C90X
set nic=3C90X
GOTO CLIENT
:NOT3C90X
echo Unsupported or unuseable NIC card in this system
echo process terminated
goto end
:CLIENT
LOAD C:\NOVELL\CLIENT32\IPX.NLM
LOAD C:\NOVELL\CLIENT32\SPX_SKTS.NLM
LOAD C:\NOVELL\CLIENT32\CLIENT32.NLM
f:
login tam103qa01\IMAGE /NS < c:\pw.txt
:end
map m: = tam103qa01\sys:
map n: =tam103qa01\sys:
map o:=tam103qa01\zenapps:
map s16: = sys:public
map s16: = tam103qa01\sys:image\menu
map s16: = tam103qa01\sys:image\utils
unatt98

Config.sys
device=himem.sys

Boot.ini

[boot loader]
timeout=1
default=c:\bootsect.img
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Winnt"

Unatt98.bat

echo off
n:\image\utils\smartdrv c+

rem goto exit
IF NOT EXIST N:\IMAGE\NT\I386\%nic%.TXT GOTO ERROR
ECHO FORMATING DRIVE TO ACCEPT THE IMAGE (THIS WILL TAKE AWHILE)
N:\IMAGE\UTILS\FORM98 C: /V:CHASE /U /Q <N:\IMAGE\UTILS\Y.TXT
ECHO DONE FORMATING
echo unlocking drive protection
lock c: < n:\image\utils\y.txt
set comspec=n:\image\utils\comm98.com
copy n:\image\imagethi\rereg.exe c:\
copy n:\image\nic\%mac%\ndsinfo.ini c:\

:unattend
ECHO DOWNLOADING Installing WidnowsNT Image(THIS WILL TAKE AWHILE)
CD\IMAGE\NT\I386
IF NOT EXIST N:\IMAGE\NIC\%MAC%\%nic%.TXT GOTO USEDEFAULT
winnt /b /s:n:\image\nt\i386 /u:n:\image\NIC\%MAC%\%nic%.txt
GOTO EXIT

:USEDEFAULT
winnt /b /s:n:\image\nt\i386 /u:n:\image\nt\i386\%nic%.txt
GOTO EXIT

:ERROR
ECHO This file copy was not successful.
PAUSE

:EXIT
rem reboot.exe


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell