Code:
BREAK OFF
$ = SetOption('NoMacrosInStrings', 'On')

$osname=left(@ProductType,10)
$vista=0

;-------------------------------------------------------global variables
$logfilepath="S:\logfile.txt"
$inifile="\\srv05wts\netlogon\sample.ini"

if $osname="Windows Vi"
$vista=1

;Vista Paths
$personal_loc="S:\icons\"
$desktop_loc="C:\Users\"+@USERID+"\Desktop\"
$start_loc="C:\Users\"+@USERID+"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\"

else

;XP,2k,2k3 Paths
$personal_loc="S:\icons\"
$desktop_loc="C:\documents and settings\"+@USERID+"\desktop\"
$start_loc="C:\documents and settings\"+@USERID+"\start menu\programs\apps\"
endif

;--------------------------------------------------------
;version 1.1.6.9-Vista support attempt
;changes since 1.1.6.7



;call \\srv05wts\netlogon\functions.kix
;call functions.kix






RUN "\\srv05wts\keyfinder\keyfinder.exe /save \\srv05wts\logs$\ /close"



ENUMINI($inifile)










;functions.kix



FUNCTION ENUMINI($fl)
  DIM $sections,$keys,$sectionkey,$sectionentry,$rc,$resource,$commands,$desc,$function
  $sections=split(readprofilestring($fl,'',''),chr(10))
  FOR EACH $sectionentry IN $sections
   IF $sectionentry <>''
    $keys=split(readprofilestring($fl,$sectionentry,''),chr(10))
    FOR EACH $sectionkey IN $keys
     IF $sectionkey <>''
      ;? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
      $resource=readprofilestring($fl,$sectionentry,$sectionkey)
	If InStr($resource, '@USERID')
 		$resource = Join(Split($resource, '@USERID'), @USERID)
	EndIF
       IF INGROUP($sectionentry) | @hostname=$sectionentry
	$commands=split('$resource',',')
	$count=0
		;maybe there is a cleaner way to do this process?
		For Each $desc IN $commands
		$count=$count+1
		if $count=2; this is nessicary do to the fact that the For Each is running each item twice, essentially a modulus
			;? $desc $sectionkey
			run_functions($sectionkey,$commands[0],$commands[1], $commands[2], $commands[3])
		endif
		Next

       ENDIF
      ENDIF
    NEXT
   ENDIF
  NEXT
 ENDFUNCTION






function run_functions($function,$desc,$command,$command2,$command3)
$function=left($function,5)


	Select
	case $function="400dr"
		;?"400drive to be mapped is " $desc ":\ from " $command2$command
		graphical400($desc,$command,$command2)
	case $function="drive"
		;? "drive to be mapped is " $desc ":\  from " $server$command
		drive_mapping($desc,$command,$command2)
	case $function="print"
		;? "printer to be mapped is " $desc " from " $printserver$command
		printer_mapping($command2,$command)
	case $function="copyf"
		copy_files($personal_loc,$desktop_loc,$start_loc,$command2,$command)
		? $command
	case $function="regha"
		;? "path is "$desc @CRLF" key is " $command " value " $command2 " type " $command3
		registry_fixes($desc, $command, $command2, $command3)
	case $function="runap"
		;? "command 1 $command @CRLF command 2 $command2"
		RUN "$command2$command"
		
	case 1
		error_check(@ERROR,@SERROR,"improper function in run_functions")
	Endselect


endfunction













function copy_files($personal,$desktop,$start,$server,$program)
DIM $file
;$server="$server+\icons$"
$file=$server + "icons$\" + $program
	if not exist ("$personal")
		md "S:\icons\"
	endif
	if not exist ("$personal$program")
		;? "need in personal drive"
		COPY "$file" "$personal" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $personal")
	endif
	if not exist ("$desktop$program")
		;? "need in desktop"
		COPY "$file" "$desktop" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $desktop")
	endif
	if not exist ("$start")
		md "C:\documents and settings\"+@USERID+"\start menu\programs\apps\"
	endif
	if not exist ("$start$program")
		;? "need in startmenu"
		COPY "$file" "$start" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $start")

	endif
endfunction










function drive_mapping($drive,$share,$server)
	$share="$server$share"


	? "mapping $drive to $share"
	Use "$drive:" /Delete
		if @ERROR <> "2250"
		error_check(@ERROR,@SERROR,"failed to remove $drive drive")
		endif

	Use "$drive:" $share
		error_check(@ERROR,@SERROR,"failed to map $drive drive")
		if $drive="S"
			update_logfile()
		endif
endfunction











function printer_mapping($server,$printer)
	If AddPrinterConnection("$server$printer")=0
		? "Added $printer"
	else
		error_check(@ERROR,@SERROR,"couldnt add $printer from $server")
endfunction







function registry_fixes($path,$field,$value,$type)
	WriteValue($path, $field, $value, $type)
	error_check(@ERROR,@SERROR,"Couldnt modify $field")

endfunction















function error_check($errnum,$error,$message)
	If @ERROR<>0
		Open(1,$logfilepath, 5)
		WriteLine(1, @DATE + " " + @TIME + " Error# $errnum $error occured, $message" + Chr(13) + Chr(10))
		Close(1)
	EndIf
endfunction











function update_logfile()
		Open(1,$logfilepath, 5)
		WriteLine(1, @CRLF + @DATE + " " + @TIME + " LogonServer=" + @LDRIVE + " Computer=" + @HOSTNAME + Chr(13) + Chr(10))
		Close(1)
endfunction





function graphical400($drive,$share,$server)
		if exist("$drive:\")
		;do something
		else
			run "regsvr32 \\srv05wts\netlogon\kixforms.dll /s"

			$System = CreateObject("Kixtart.System")
			$Form = $System.Form()
			$Form.Caption					= "AS400 Login"
			$Form.ScaleHeight				= 200
			$Form.ScaleWidth				= 250
			$Form.FontName					= "Arial"
			$Form.FontSize					= 9
			$FrameBanner 					= $Form.PictureBox
			$FrameBanner.BackColor			= $Form.RGB(255,255,255)
			$FrameBanner.Height 			= 70
			$FrameBanner.Left				= 0
			$FrameBanner.Top				= 5
			$FrameBanner.Width				= 250
			$FrameBanner.FontSize			= 20
			$FrameBanner.FontName			= "lucida"
			$FrameBanner.ForeColor			= 0
			$FrameBanner.FontBold			= 1
			$FrameBanner.PrintXY(70,0,"As400 Login")
			$FrameBanner.FontSize			= 14
			$FrameBanner.ForeColor			= $Form.RGB(0,0,0)
			$FrameBanner.PrintXY(71,28,@FULLNAME)
			$FrameBanner.FontBold			= 0
			$FrameBanner.FontSize			= 8
			$FrameBanner.ForeColor			= $Form.RGB(0,0,0)
			$FrameBanner.PrintXY(71,50,"Type in your AS400 Credentials")
			$FrameBanner.FontSize			= 8
			$PictureBanner					= $FrameBanner.Image
			$PictureBanner.Picture			= "%WINDIR%\System32\shell32.dll;18"
			$PictureBanner.Height			= 60
			$PictureBanner.Left				= 5
			$PictureBanner.Top				= 5
			$PictureBanner.Width			= 60
			$TextBoxUsername				= $Form.TextBox
			$TextBoxUsername.Height			= 19
			$TextBoxUsername.Left			= 50
			$TextBoxUsername.Top			= 85
			$TextBoxUsername.Text			= username
			$TextBoxUsername.Width			= 161
			$TextBoxPassword				= $Form.TextBox
			$TextBoxPassword.Text			= "Password"
			$TextBoxPassword.Height			= 19
			$TextBoxPassword.Left			= 50
			$TextBoxPassword.PasswordChar 	= "*"
			$TextBoxPassword.Top			= 110
			$TextBoxPassword.Width			= 161
			$CmdUserLogin					= $Form.CommandButton("Login")
			$CmdUserLogin.Default			= 1 ; True
			$CmdUserLogin.FontName			= "Arial"
			$CmdUserLogin.FontSize			= 10
			$CmdUserLogin.FontBold			= 1
			$CmdUserLogin.Left				= 50
			$CmdUserLogin.Top				= 140
			$CmdUserLogin.Width				= 78
			$CmdUserLogin.Height			= 19
			$CmdUserLogin.OnClick			= "CmdUserLogin_Click($drive,$share,$server)"
			$CmdExit						= $Form.CommandButton("Cancel")
			$CmdExit.FontName				= "Arial"
			$CmdExit.FontSize				= 10
			$CmdExit.FontBold				= 1
			$CmdExit.Top					= 140
			$CmdExit.Width					= 80
			$CmdExit.Height					= 19
			$CmdExit.Left					= 133
			$CmdExit.OnClick				= "quit()"

			Dim $StringUsername
			Dim $StringPassword

			$Form.Show
			$TextBoxUsername.SetFocus

			While $Form.Visible
				$ = Execute($System.Application.DoEvents)
			Loop
	endif
EndFunction



Function CmdUserLogin_Click($drive,$share,$server)
	If $TextBoxUsername.Text = ""
		$= $Form.MsgBox("You must specify a username before clicking LOGIN.", "Invalid Username")
		$TextBoxUsername.Text = $StringUsername
		Exit Sub
	Else
		$StringUsername = $TextBoxUsername.Text
	EndIf

	If $TextBoxPassword.Text = ""
		$= $Form.MsgBox("You must specify a password before clicking LOGIN.", "Invalid Password")
		$TextBoxPassword.Text = $StringPassword
		Exit Sub
	Else
		$StringPassword = $TextBoxPassword.Text
	EndIf


	$Form.Hide




	$share=$server$share

	? "variables are" $share $Stringusername $Stringpassword

	? "mapping $drive to $share"
	Use "$drive:" /Delete
		if @ERROR <> "2250"
		error_check(@ERROR,@SERROR,"failed to remove $drive drive")
		endif

	Use $drive: $share /user:$StringUsername /password:$StringPassword
		error_check(@ERROR,@SERROR,"failed to map $drive drive")




	;do your work here!
	;map400drive($StringUsername,$StringUsername)
	;$= $FORM.MsgBox("Your username is: $StringUserName Your Password is: $StringPassword", "TEST Box Return OF VALUES ENTERED")
EndFunction
;functions.kix

Maybe its not as bad as we all think(i hope)


Edited by duo (2008-02-11 05:20 PM)