Novell Home

Automatic Workstation Registration

Novell Cool Solutions: Trench
By Xavier Zinn

Digg This - Slashdot This

Posted: 2 Aug 2002
 

As we all know ZENworks has the ability to automatically register a workstation. With registration comes the benefit of manipulating objects in NDS, be it in adding applications to an object, remote control, or querying. The long and short of it is, workstation registration is a good thing. But how do you know a workstation is registered?

We are well aware that we can't rely on the user to give us accurate information. Although certain users are quite capable in giving us the information we want and need, the vast majority can't or won't for a multitude of reasons. Workstation registration can ease our frustration by getting the information we need, when we need it. But what happens when the workstation is not registered?

This is a common problem in my particular environment and I am sure it happens in other environments as well. In a perfect environment all workstations are registered correctly and are all working properly. What if this is not the case. Do you have a process in place to identify workstations that are not registered correctly? Once identified are the workstation registered manually? This can be time consuming if it is more than a handful of workstations. What if workstations across the WAN aren't being registered. Can you get to those workstations and register them? What happens when a workstation is registered and then it is moved to the other side of the WAN. Is there a process in place that will un-register and re-register the workstation to the new location? (This assumes that you have multiple ZEN servers importing workstations in multiple contexts.)

These questions and more led me on this crusade to find a way to register/re-register workstations in the proper context. I also wanted to let the user know that the workstation is registered and if a problem is encountered during the registration process instructions would be displayed to call the helpdesk. I wanted to accomplish this all through the login script and using no third-party applications or custom in-house apps.

In my particular environment there are 10 contexts and each context has its own servers. In each context there is a server with ZEN 3. Each context has the ability to automatically register workstations. Workstation registration works fine but as we all know there are times when we get the dreaded error-1 (get winsockhostname). This is the most common error I have come across with workstation registration. In this situation a workstation is not registered. How do you know? The only way is to look at the Wsreg32.log and see if there is an error ?1 or navigate through the application explorer to see the workstation context. This can be annoying. What if you have an outside vendor supplying and installing workstations? In this case you would really have no handle on the situation because you have no way of knowing if they checked to see if the workstations were registered and if they weren't, would they fix it? Or more importantly, do they know how to fix it?

I needed a way in which to ensure that:

  1. Workstations are registered correctly.
  2. Users know the workstations are registered correctly.
  3. If the workstation moved they would be re-registered.
  4. If the user moved to a different location this would be recognized.
  5. If the workstation wasn't registered correctly, the user would know to call the helpdesk.
  6. It is not necessary to rely on a process to register/re-register the workstations.
  7. All of this needed to be done automatically without user intervention
  8. No need to worry about a workstation being registered properly in the proper context.
  9. Minimal administrative overhead relatively speaking.
  10. Users outside their context (in a different building or city, etc. don't register workstations.

Here are the complete scripts for WIN 95 and NT/2000 with commentaries when necessary. They work for me hopefully if you will find them useful. Please test before implementing.

As with anything for WIN95 it is easy. This script is the one I wanted to use for both 95 and NT/2000 but a funny thing called permissions on the registry caused this not to happen. I found in my testing that access to the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Workstation Manager on NT/2000 is not available unless you are the administrator or administrator equivalent. What does this mean? Regread does not work on NT/2000. You will see what I mean shortly. I played with some registry permission tools like reini and regperm but, as stated in one of Novell's TIDs, these tools only work during the current session on the workstation. Once the workstation is rebooted the permissions revert to their original state.

As stated earlier, these scripts use only commands that are available in both the Novell Client 3.3 and later for WIN95, and the OS.

The Win95 Script

Each context has this script added to the current login script.

IF NETWORK_ADDRESS >= ?BEGINNING OF IP ADDRESS RANGE IN HEX? AND 
NETWORK_ADDRESS <= ?END OF IP ADDRESS RANGE IN HEX? THEN 
GOTO XAVIER
ELSE
WRITE ? YOU ARE LOGGING INTO A WORKSTATION 
THAT IS NOT IN ?YOUR CONTEXT HERE? ?
WRITE ? THE REGISTRATION PROCESS WILL NOT CONTINUE. 
IF YOU ARE NOW IN A DIFFERENT?
WRITE ? LOCATION PLEASE INFORM THE HELPDESK 
AT ?YOUR HELPDESK EXTENSION HERE?
GOTO END

The ip address range is in Hex. Example. IP address range from 10.10.10.1 to 10.10.20.254 IF NETWORK_ADDRESS >= ?0A0A0A01? AND NETWORK_ADDRESS <= ?0A0A0AFE? THEN Make sure you use 2 hex numbers per decimal number. 10 is A in hex but I use 0A why? Hex likes it. Try this command to see what I mean. Type the following (write ?my network address is %NETWORK_ADDRESS?) without the brackets.

The context is the context that has been defined in NDS that correlates to the IP range. Example. IP address range from 10.10.10.1 to 10.10.20.254 is for the Toronto context. Hence Toronto will be the context you supply.

So far the script is saying if your IP address falls within the range defined then goto xavier if not tell the person logging on that the workstation is not in your context. If you have moved, inform the helpdesk so they can make the appropriate changes. This allows users from one context, who are somewhere else physically, to keep from registering workstations that are not in their ?home? building. Here's an example: You are in the Toronto context. You can register workstations in the Toronto context. This is based on the IP address range defined in the beginning of the script. You have a meeting in Calgary and use a workstation in Calgary. Since you are in Calgary your login script recognizes that the IP address range is not for your context so it will not try to register the workstation because if it did, you would be registering it in the Toronto context even though it is physically in Calgary. The script completes knowing that it doesn't have to do anything else.

XAVIER:
WRITE ? YOU ARE LOGGING INTO A WORKSTATION THAT RESIDES 
IN ?YOUR CONTEXT HERE? THE?
WRITE ? REGISTRATION PROCESS WILL TAKE PLACE.?
REGREAD ?HKLM,SOFTWARE\NOVELL\WORKSTATION MANAGER\Identification, 
Registered In?
WRITE ?YOUR WORKSTATION IS REGISTERED IN THIS CONTEXT=%99?
IF ?%99?=?CONTEXT THAT THE WORKSTATION IS REGISTERED IN? THEN
WRITE ? THIS WORKSTATION IS ALREADY REGISTERED 
AT ?YOUR CONTEXT HERE?
WRITE ? NO FURTHER ACTION IS REQUIRED. THANK YOU.
GOTO END

Here the workstation is recognized as being in the proper building due to IP address and will register the workstation. Using regread, the Novell client reads the registry key through the variable %99. I can now use this in a logic statement. Regread uses the %99 variable exclusively. I state what context the workstation is registered in and, if it matches, then it knows the workstation has already been registered properly and will not register it again. Here's another example: Your context is Toronto.tree. You register your workstations in workstations.toronto.tree. Regread reads the registry key and gives you the information through the %99 variable. Your workstation is registered in workstations.toronto.tree. It checks what the context is, in this case workstations.toronto.tree, and compares it with what it should be: workstations.toronto.tree. They match and recognize that this workstation has been registered in this context before. It will not do it again. The script completes knowing that it doesn't have to do anything else.

ELSE
WRITE ?YOUR WORKSTATION MEETS THE REQUIREMENTS FOR BEING REGISTERED 
AT ?YOUR CONTEXT 
WRITE ? HERE? BUT IT IS NOT REGISTERED IN THIS CONTEXT. IT WILL 
BE REGISTERED FOR YOU. 
WRITE ?THANK YOU FOR YOUR PATIENCE.?

Obviously this script needs to be placed after all the drive mappings have completed. For clarity I will list a batch file and then its contents with an indent so you know what the batch file is doing.

#M:\WKSTN REG TORONTO.BAT
 	contents for Toronto.bat
	echo ?your IP address in decimal form here?	 
	zenwsimport>c:\windows\hosts
	cls
	exit.

The batch file creates a host file in c:\windows\hosts with the ip address for the zenwsimport service that the workstation is going to be registered to. The file will look like this.

IP address of the zenwsimport service 	zenwsimport

That is a tab between the ip address and zenwsimport. Cls and exit are for the batch file to execute and close without user intervention.

#Z:\UNREG32.EXE
#Z:\WSREG32.EXE
REGREAD ?HKLM,SOFTWARE\NOVELL\WORKSTATION MANAGER\Identification, 
Registered In?
WRITE ? YOUR WORKSTATION IS NOW REGISTERED IN THIS CONTEXT =%99?
IF ?%99?= ?YOUR WORKSTATION CONTEXT HERE?
WRITE ?YOU WORKSTATION HAS BEEN SUCCESSFULLY REGISTERED 
IN THE PROPER CONTEXT.
ELSE
WRITE ? YOUR WORKSTATION WAS NOT REGISTERED SUCCESSFULLY. 
PLEASE CALL THE HELPDESK
WRITE? ?YOUR HELPDESK NUMBER HERE?
END:

The workstation gets unregistered and reregistered. Regread looks at the key and checks to see if it matches what you have defined. If yes, your workstation is registered. If not, call the helpdesk. Here's an example: A workstation comes from China. It is registered in the workstations.china.tree. It is now in Toronto. Your workstations are registered in workstations.toronto.tree. The script runs and it checks the "Registered In" key. It is not workstations.toronto.tree. The workstation needs to be reregistered. The Host file gets created to make sure the workstation gets registered to the correct server. This host file will get overwritten if the workstation gets registered in another context with a different import server. The workstation gets unregistered then reregistered. Regread checks the context. If it equals workstations.toronto.tree, registration was successful. If not, a problem happened that 2nd level needs to look into. The user calls the helpdesk and a ticket is created for 2nd level to investigate/register the workstation.

In this script one knows what the context is before and after the registration script runs if everything is successful.

The NT/2000 Script

The NT/2000 script was very different. I could not use the Regread command from the Novell client 4.8 and higher. Regread is available on the client and does work but one needs admin rights to the registry key I was looking at for workstation registration namely, HKLM,SOFTWARE\NOVELL\WORKSTATIONMANAGER\Identification, Registered In.

Users don't typically have admin rights to the workstation so this was a limitation I needed to work around.

Here's the script.

IF NETWORK_ADDRESS >= ?BEGINNING OF IP ADDRESS RANGE IN HEX? 
AND NETWORK_ADDRESS 
<= ?END OF IP ADDRESS RANGE IN HEX? THEN 
GOTO XAVIER
ELSE
WRITE ? YOU ARE LOGGING INTO A WORKSTATION THAT IS NOT IN 
?YOUR CONTEXT HERE? ?
WRITE ? THE REGISTRATION PROCESS WILL NOT CONTINUE. IF YOU 
ARE NOW IN A DIFFERENT?
WRITE ? LOCATION PLEASE INFORM THE HELPDESK AT 
?YOUR HELPDESK EXTENSION HERE?
GOTO END
XAVIER:
WRITE ?YOUR WORKSTATION MEETS THE REQUIREMENTS FOR 
BEING REGISTERED AT ?YOUR CONTEXT 
WRITE ? HERE? BUT IT IS NOT REGISTERED IN THIS CONTEXT. 
IT WILL BE REGISTERED FOR YOU. 
WRITE ?THANK YOU FOR YOUR PATIENCE.?

This is the same as for Win95. The differences are to follow. The batch files are shown the same way as in the previous script.

#M:\DELWSREG.BAT
	DEL C:\WSREG32.LOG /F
#M:\WKSTNREG.BAT
	ECHO IPADDRESS	ZENWSIMPORT>C:\WINNT\SYSTEM32\DRIVERS\
	ETC\HOSTS
#Z:\UNREG32.EXE
#Z:\WSREG32.EXE
#M:\ERROR.BAT
	C:
	FIND /I ?error? c:\wsreg32.log
	IF ERRORLEVEL 1 GOTO NO
	IF ERRORLEVEL 0 GOTO YES
	:NO
	GOTO END
	:YES
	TYPE WSREG32.LOG>C:\ERROR.LOG
	GOTO END
	:END
	ECHO OFF
	CLS	
	EXIT

Since I can't use Regread to check the registry I needed a way to check if a workstation registered properly. This was the only way I could find to do it. If the find command finds the word error in the log file it will copy the wsreg32.log file to a new file called error.log. I deleted the the wsreg32.log file before running the unreg32/wsreg32.exe because I found that the file sometimes appends instead of creating a new one.

#M:\COPY.BAT
	COPY C:\ERROR.LOG C:\NOVELL
	ECHO OFF
	CLS
	EXIT

I copied this file to a new location so the next line could test if the batch file copied. If it did then the workstation didn?t register. The errorlevel was 0 indicated that it functioned correctly. This is not good. We need it to come back with an errolevel of 1 to indictate it didn?t work.

IF ?%ERRORLEVEL? = ?0? THEN
GOTO ERROR
ELSE
WRITE ?YOUR WORKSTATION IS REGISTERED PROPERLY?
WRITE? THANK YOU?
GOTO END
ERROR:
WRITE ?YOUR WORKSTATION IS NOT REGISTERED PROPERLY. 
PLEASE CALL THE HELPDESK AT 
WRITE ? ?YOUR HELPDESK NUMBER?
#M:\DELFILES.BAT
	C:
	DEL C:\ERROR.LOG /F
	DEL C:\NOVELL\ERROR.LOG /F
	ECHO OFF
	CLS
	EXIT
Once we know that the workstation didn't register 
I wanted to send the workstation
back to its 'original' state, hence the 
deletion of the 2 files I created.
END:

In summary:

As you can see from the 2 different scripts they do the same thing just in different ways. Both do the following.

  1. Workstations were registered correctly.
  2. Users knew the workstations were registered correctly.
  3. If the workstations moved, they were re-registered.
  4. If the user moved to a different location this would be recognized.
  5. If the workstation wasn't registered correctly, the user would know to call the helpdesk.
  6. It is not necessary to rely on a process to register/re-register the workstations.
  7. All of this needed to be done automatically without user intervention
  8. No need to worry about a workstation being registered properly in the proper context.
  9. Minimal administrative overhead relatively speaking.
  10. Users outside their context (in a different building or city, etc. don't register workstations.

Not being able to use Regread on the NT/2000 workstations was really a pain to get around, if anybody has any ideas that are a little more elegant than my solution please share the knowledge.

Currently, the Win95 script is the only script to notice that the workstation is registered in the proper context and will not proceed with re-registering. Unfortunately, this is not the case with the NT/2000 script. It will run every time the workstation is logged in.

All the commands used are either Novell Client or OS commands, and all information is posted through the results screen of the Novell client.

I believe that this will take care of 99 percent of all workstation registration problems. There are, of course, some reasons why a workstation can't register that these scripts will not address, that is what a visit to the workstation is for. But for the most part, I think this can help some of you if you need a solution to some of the problems I listed.

You can reach Xavier with questions at margrave@idirect.com.


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

© 2014 Novell