A few things i'll add:

1) I find it's best not to statically reference the name of the server you are running the script from. You can use relative paths instead. Why this is useful is because if the name of the server changes, or you are running the script from another location, it will still work. For example, if its a multi-DC environment and you are storing the scripts in the NETLOGON share (SYSVOL), this will replicate between domain controllers.

So to do this, you would be best to place the batch file and kix script in the same directory and use:

%0\..\wkix32.exe %0\..\7777.kix /i

The "%0\.." bit is basically just saying 'in the same directory as the batch file'.

However that's not really critical, it just causes less headaches in the long run.

As for the script, a few pointers.

2) There is two reasons you aren't getting errors.
> Firstly, you are using wkix32 instead of kix32. wkix is the same as kix32 except it suppreses console output, so you will not see console output. For testing, kix32.exe is in my opinion, the better choice, once happy with it swap to wkix32.exe

> Secondly, kix only outputs error messages by default if there is a syntax error. The way you get error information is by telling the script you want it. For example:

 Code:

use i: /delete /persistent 
? "ERROR CODE = " + @ERROR
? "Verbose error description = " + @SERROR



@ERROR typically returns an integer, corresponding to (i think) typical windows error codes, such as '0' for successful. These are good for checking as conditions in loops, if/else/endif statements etc.

@SERROR typically returns a string, such as 'The operation has been succesful'

Without knowing the exact setup at your site it's difficult to know for sure, but this is possibly close to what you want:

<disclaimer> : I havn't tested this at all, use at own risk, do own testing etc if it breaks your computer, not my fault!! </disclaimer>

 Code:

   ; 7777.KIX
   ; KiXtart script to map network drives

   ;Variables

   ;Get the hostname of the server that served the logon request
   ;IE this should be the local domain controller, if in a domain environment

$strLogonServer = @LSERVER

   ;Get the domain name, rather than declaring it explicitly.
   ;This way script wont break if domain renamed or something

$strDomain = @DOMAIN

   ;Determine the Site Code.
   ;Do this by making the variable $strSiteCode equal to the
   ;first 4 characters of the $strLogonServer variable

$strSiteCode = Left($strLogonServer,4)

   ;Lets build a site-specific string equal to the name of the file server\share

$strSomeFileShare = "\\" + $strSiteCode + "FNP01\SomeShare"

   ;Delete some mappings, display error codes.
   ; This would really be best as a function, but best to keep it simple
   ; while learning

use i: /delete /persistent
? "i: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use g: /delete /persistent
? "g: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use m: /delete /persistent
? "m: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use s: /delete /persistent
? "s: - Error (" + @error + ") SERROR(" + @SERROR + ")"

   ;Presumably you will want to map a drive(s). lets map it to z:\

mapdrive($strSomeFileShare, "z:")


   ;To prevent the script from closing the second 
   ;it has completed, and thereby not giving
   ;us a chance to see the output, we can tell it to 
   ;wait for the user to press a key before continuing/closing
   ;This should be removed before production, but handy for testing

Get $

   ;---------------------
   ;Function to Map a Drive
   ;---------------------
Function mapdrive($drivepath, $driveletter)
	Use $driveletter $drivepath
	If @ERROR = 0
		? "Drive: " $drivepath " was mapped successfully"
	Else
		? "Drive ( " + $drivepath + " ) was NOT mapped!"
		? "Error: " + @SERROR 
	EndIf
EndFunction







Edited by lukeod (2011-02-14 02:31 AM)