Edit: This is a rewrite since long ago, Free to use and modify.

REASON OF POSTING:
This community has given me so much since I started sniffing this place for usefull information - time to give something back.
Code and instructions as follows;

BUILD NOTES:
This build was working correctly with a 2003 AD, kix 4.5x and XP clients.

Create a GPO with user-logon-script pointing toward wkix32.exe
in same catalouge create following files:

kixtart.kix
 Code:
;Main file.

if NOT @LOGONMODE
Break On
EndIf

$silent=SetOption('Explicit','ON')
$silent=SetOption('CaseSensitivity','OFF')
$silent=SetOption('NoMacrosInStrings','OFF')
 
Dim $func_dir,$file_dir,$FileName
;Define values
$func_dir = @scriptdir
$file_dir = @scriptdir

 
;call functions 
 
$FileName = Dir($func_dir+"\fn*.kix")
While $FileName <> "" and @ERROR = 0
 call $func_dir+"\$FileName"
  $FileName = Dir() ; retrieve next file
Loop
;Call each *.udf file until an error occurs or there are no more files to call.

;next two lines enabled at testphase. 
;MessageBox ("Logon-Script started","Enable and change this text to enable messagebox with info regarding script running",64,)
;fnWriteLog("Script started at: " + @TIME+" "+ @DATE+" "+@LServer+" "+@USERID)

fnRemdrive("1.0") 

fnNetmap($func_dir+"\network.ref")


;fnWriteLog("Script ended at: " + @TIME+" "+ @DATE+" "+@LServer+" "+@USERID)

exit 


network.ref
 Code:
; Rev 1.0.0 
; Created: 
;  $Revision:  $ $Date: 200y/mm/dd  $
;
; Layout file for logon script
; 
 
[NetworkResources]
SetTime   = SetTime.NetworkResources
Group   = Group.NetworkResources
 
Domain   = Domain.NetworkResources
;Domain.GroupX = Controlgroups to sort by.

/*
[Controlgroup1]
Home.1      = h:,@homeShr,some group
SetTime.1   = ,@lserver,some group
NetShr.2	= i:,\\netshr\path,some group


fnnetmap.kix
 Code:
; Function for DriveMapping using a standard ini-shaped file (ie - network.ref).

function fnnetmap($path)
Dim $i,$domaingrp,$valuename,$value,$donotmap,$group
 
$i = 0
for each $domaingrp in split(left(readprofilestring($path,"",""), -1),chr(10))
  if $i = 0 and ingroup($domaingrp)
    $i = $i + 1 
    for each $valueName in split(left(readprofilestring($path,$domaingrp,""),-1),chr(10))
      $value = split(readprofilestring($path,$domaingrp,$valueName),",")
      $doNotMap = 0
      for each $group in split($value[2],"|")
        if left($group,1) = "!" and ingroup(substr($group,2))
          $doNotMap = 1
        endif
      next
      for each $group in split($value[2],"|")
        if ingroup($group) - $doNotMap
          select
           case left($valueName,7) = "NetShr."
            use $value[0] $value[1]
            if @error fnwritelog("Error occured in fnnetmap.kix."+ $value[0] +"|"+ $value[1]+"| "+ @error+" , "+ @serror) endif
           ;case left($valueName,8) = "SetTime."
            ;SETTIME "$value[1]"
            ;if @error fnwritelog("Error occured in fnnetmap.kix."+ $value[0] +"|"+ $value[1]+"| "+ @error+" , "+ @serror) endif
           case left($valueName,5) = "Home."
            use $value[0] @HomeShr 
            if @error fnwritelog("Error occured in fnnetmap.kix."+ $value[0] +"|"+ $value[1]+"| "+ @error+" , "+ @serror) endif
          endselect
        endif
      next
    next
  endif
next
endfunction


fnwritelog.kix
 Code:
;fnWriteLog.

Function fnWriteLog($text)
   Dim $rc, $loglile, $filehandle
   $filehandle = "7"
   $logfile = ExpandEnvironmentVars(%temp%) + "\logon.log"
   $rc = WriteLine ($filehandle, @Date + " " + @Time " - " + $text + @CRLF)
   If $rc < 0
      $rc = Close ($filehandle)
      $rc = Open ($filehandle, $logfile, 5)
      Select
         Case $rc = -1
            $rc = MessageBox ("Invalid file name (" + $logfile + ") specified for log file.","Logon Script Error",48)
         Case $rc = 0
            fnWriteLog ($text)
         Case $rc => 0
            $rc = MessageBox ("Error(" + $rc + ") while attempting to open log file (" + $logfile + ").","Logon Script Error",48)
      EndSelect
   EndIf
EndFunction


fnRemDrive.kix
 Code:
;fnRemDrive.

Function fnremdrive($checkvalue)
dim $checkval,$check,$wrcheck
$checkval="HKEY_CURRENT_USER\Software\ACME"
  $check=readvalue($checkval,"script")
  if @error = 0
   if NOT $check = $checkvalue
    USE * /DELETE /PERSISTENT
    $wrcheck=writevalue($checkval,"script",$checkvalue,"REG_SZ")
   endif
  endif
endfunction


Last function was in use due to some error in removing mappings/errors with mapping thanks to faulty handeling of mappings with kix 4.50 and/or a bad damn network.

NOTE: Most of this code exists thanks to this community - this is the reason I give it 'back'. Many hours of consulting-time was spent on this - but only to put it into production - NOT development - and the hours that was - code was provided to me by the inhabitants of kixtart.org.

Help or code optimation is always welcome. Better commenting as well. Go with the flow.

! Explanation :

running wkix32.exe / kix32.exe only will make the script look in @scriptdir for @userid.kix - next in line is kixtart.kix - this exists - and if you ever need a specific login for a user - simply create a main file with the username.

The main - kixtart.kix will enumerate (perhaps in a faulty manner) all fn*.kix files in @scriptdir - thus adding your own function will not require that much energy - and logging can always be added or edited due to the use of the function provided (fnwritelog.kix). The structure of the "ini" file containing the mappings should be self-explained. If errors found - please report it. This is a base to be handled. Several functions has been removed due to customer-specific-builds, built during work-hours and thus not mine to use anymore.

NOTE REGARDING fnRemDrive:
This function uses a reg key to be used as a version-handler - each time you update things you use a new version, if the new version is not equal to the version in the reg-key - remdrive will be used - this was used due to
to much troubleshooting faulty drives when servers was changed - new mappings added / removed.


NOTE REGARDING PATH TO SCRIPT! :
When I wrote and created this in 2006, I used the full scriptpath of\\domain\sysvol\fqdn.topdomain\{id}\[user(think it was)\scripts\ .
A bit messy - but safer than placing it in \\domain\netlogon\ due to 1. harder to find - security can be added within the applied logic - you apply this only to a specific WMI-filter/group-access via the GPO.

ISSUES:
Fast logon opt. may scr*w things up as usual. Nonworking script - disable it.

This is as always - WORK IN PROGRESS.
Questions/etc - provide it in the thread.

EDIT: just realized that the function for removing drives needs to check over - this due to a pre-relase/tested verions was posted. will be fixed.
EDIT: Added Mart's rewritten log-function :).
EDIT: Added break on/off in kixtart.kix
EDIT: Fixed subject spelling..
EDIT: Small revision \:\)


Edited by Björn (2015-05-12 04:34 PM)