Sign in to follow this  
Followers 0
PeterAtkin

Domain Logon Script

3 posts in this topic

#1 ·  Posted (edited)

I just managed to get our batch file logon script converted to Autoit

#include <Constants.au3>
#include <Array.au3>
#include <NetShare.au3>

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{END}", "Terminate")
Global $ostemp

Global $network_printers[2]
;last printer becomes the default
$network_printers[0] = "[url="file://\dc-2008hp4700n"]\\dc-2008\hp4700n[/url]"
$network_printers[1] = "[url="file://\dc-2008hp4250n"]\\dc-2008\hp4250n[/url]"

Switch OSGet()
Case 'vista_win'
  ;this is only needed if your accessing external none windows based NAS devices using Vista or Windows 7
  ;read this for more help with Vista and windows 7: [url="http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d"]http://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/4606ad12-1f23-4231-8597-8e515422d57d[/url] $operation="Vista and Windows 7"
  $accounts = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $source = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $chaos = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $homebase = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]"
  $operation = "Vista or Windows 7 Mode"
Case 'winnt'
  $accounts = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $source = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $chaos = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $homebase = "[url="file://\CF-NAS1"]\\CF-NAS1[/url]"
  $operation = "XP Mode"
Case 'server'
  mapdrive("s:", $source & "\source")
  Exit
Case Else
  MsgBox(16, "OS Incompatability", "this domain fully supports Windows NT/XP/2000, 2003, 2008, Vista and Windows 7 workstations, with partial support for Windows 64bit OS and none for the rest sorry!" & @CRLF & @CRLF & "OS version " & @OSVersion)
EndSwitch

If _CMD(@LogonServer & '\netlogon\ifmember Domain Users') Then
RunAs("Administrator", "cfu", "xxxxxxxx", 4, "net time " & @LogonServer & " /SET /Y", @SW_HIDE)
ShellExecuteWait("net", "use * /delete /yes", "", "", @SW_HIDE)
mapdrive("h:", $homebase & "\user$\" & @UserName)
mapdrive("n:", $chaos & "\localcoms$")
add_network_printers()
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember Domain Admins') Then
mapdrive("s:", $source & "\source")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember quoteworks') Then
mapdrive("w:", $accounts & "\quotewerks")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember core') Then
mapdrive("x:", $accounts & "\core$")
mapdrive("q:", $accounts & "\quickbooks$")
mapdrive("t:", $accounts & "\clients$")
mapdrive("u:", $accounts & "\suppliers$")
EndIf

If _CMD(@LogonServer & '\netlogon\ifmember Engineers') Then
mapdrive("s:", $source & "\source")
EndIf
_users()
_welcome()

Func _users()
Switch @UserName
  Case 'Peter'
   ;MsgBox(16, "Hello", "peter")
  Case 'Tasha'
   ;MsgBox(16, "Hello", "Tasha")
  Case 'Administrator'
   MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
EndSwitch
EndFunc   ;==>_users

Func _welcome()
$local_domain = EnvGet("userdomain")
$domain_server = EnvGet("logonserver")
MsgBox(64, "Welcome to the " & $local_domain & " network", "Welcome " & @UserName & " to the " & $local_domain & " Network" & @CRLF & @CRLF & "If you have any problems or questions with your account please contact support. Peter on xxxx-xxxxxx" & @CRLF & @CRLF & "Enjoy" & @CRLF & @CRLF & "Logon script in " & $operation & " login on " & @ComputerName & " via Server " & $domain_server)
EndFunc   ;==>_welcome


Func add_network_printers()
$sh = UBound($network_printers) - 1
For $x = 0 To $sh Step 1
  _PrinterAdd($network_printers[$x], 1)
Next
EndFunc   ;==>add_network_printers

Func mapdrive($DriveLtr, $DrivePath)
DriveMapAdd($DriveLtr, $DrivePath, 1)
Switch @error
  Case '1'
   MsgBox(16, "Error", "An unknown error occured on " & $DrivePath & " trying to be mapped as local drive " & $DriveLtr)
  Case '2'
   MsgBox(16, "Error", "Access to the remote share " & $DrivePath & " was denied")
  Case '3'
   MsgBox(16, "Error", "The device/drive " & $DriveLtr & " is already assigned")
  Case '4'
   MsgBox(16, "Error", "Invalid device " & $DriveLtr & " name")
  Case '5'
   MsgBox(16, "Error", "Invalid remote share :" & $DrivePath)
  Case '6'
   MsgBox(16, "Error", "Invalid password")
  Case Else
   ;MsgBox(64, "Completed!", "Mapped " & $DriveLtr & " to share " & $DrivePath)
EndSwitch
EndFunc   ;==>mapdrive

Func _CMD($command, $workingdir = '')
Return RunWait('"' & @ComSpec & '" /c ' & $command, $workingdir, @SW_HIDE)
EndFunc   ;==>_CMD

Func OSGet()
Switch @OSVersion
  Case "WIN_7"
   $ostemp = "vista_win7"
  Case "WIN_XP"
   $ostemp = "winnt"
  Case "Win_2000"
   $ostemp = "winnt"
  Case "WIN_VISTA"
   $ostemp = "vista_win7"
  Case "WIN_2008"
   $ostemp = "server"
  Case "WIN_2008R2"
   $ostemp = "server"
  Case "WIN_2003"
   $ostemp = "server"
  Case Else
   MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
   Exit
EndSwitch
ArchGet()
EndFunc   ;==>OSGet

Func ArchGet()
Switch @OSArch
  Case "X86"
  Case Else
   MsgBox(32, "32/64bit Architecture", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10)
   Exit
EndSwitch
EndFunc   ;==>ArchGet


;===============================================================================
;
; Function Name:    _PrinterAdd()
; Description:      Connects to a Network Printer.
; Parameter(s):     $sPrinterName - Computer Network name and printer share name ([url="file://\ComputerSharedPrinter"]\\Computer\SharedPrinter[/url]).
;                   $fDefault - Set to 1 if Printer should be set to default (optional).
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure, If Printer already exist @error = 1.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterAdd($sPrinterName, $fDefault = 0)
If _PrinterExist($sPrinterName) Then
  SetError(1)
  Return 0
Else
  RunWait("rundll32 printui.dll,PrintUIEntry /in /n" & $sPrinterName & " /q")
  If _PrinterExist($sPrinterName) = 0 Then
   Return 0
  EndIf
  If $fDefault = 1 Then
   _PrinterDefault($sPrinterName)
  EndIf
  Return 1
EndIf
EndFunc   ;==>_PrinterAdd

;===============================================================================
;
; Function Name:    _PrinterDefault()
; Description:      Set a printer to default.
; Parameter(s):     $sPrinterName - The name of the printer.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterDefault($sPrinterName)
If _PrinterExist($sPrinterName) Then
  RunWait("rundll32 printui.dll,PrintUIEntry /y /n" & $sPrinterName)
  Return 1
Else
  Return 0
EndIf
EndFunc   ;==>_PrinterDefault

;===============================================================================
;
; Function Name:    _PrinterDelete()
; Description:      Delete a connection to a network printer.
; Parameter(s):     $sPrinterName - Computer Network name and printer share name.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterDelete($sPrinterName)
If _PrinterExist($sPrinterName) Then
  RunWait("rundll32 printui.dll,PrintUIEntry /dn /n" & $sPrinterName)
  If _PrinterExist($sPrinterName) Then
   Return 0
  Else
   Return 1
  EndIf
Else
  Return 0
EndIf
EndFunc   ;==>_PrinterDelete

;===============================================================================
;
; Function Name:    _PrinterExist()
; Description:      Check if a Printer Exist.
; Parameter(s):     $sPrinterName - The name of the printer.
; Requirement(s):
; Return Value(s):  1 - Success, 0 - Failure.
; Author(s):        Sven Ullstad - Wooltown
; Note(s):          None.
;
;===============================================================================
Func _PrinterExist($sPrinterName)
Local $hService, $sPrinter, $sPrinterList
$hService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" & @ComputerName & "\root\cimv2")
If Not @error = 0 Then
  Return 0
EndIf
$sPrinterList = $hService.ExecQuery("Select * From Win32_Printer")
For $sPrinter In $sPrinterList
  If StringUpper($sPrinterName) = StringUpper($sPrinter.name) Then
   Return 1
  EndIf
Next
EndFunc   ;==>_PrinterExist

Func TogglePause()
$Paused = Not $Paused
While $Paused
  Sleep(100)
  ToolTip('Script is "Paused"', (1), (8), (1), (8))
WEnd
ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
Exit
EndFunc   ;==>Terminate
But am facing one issue I still seem to have to us microsofts excelent little utility 'ifmember.exe' is there a way to use any of the ad.au3 functions or simlair to replace the script using an external programe to function. Hope I have made sence here. Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0