PeterAtkin Posted March 12, 2010 Share Posted March 12, 2010 (edited) OK so what am am trying to do it read an .ini file into an array [Printers] "Black and White in Administration" = "\\dc-pri-cfu\hp4250n" "Colour in Administration" = \\dc-pri-cfu\hp4700n To add further complication the read_file_into_array($network_printers,"vars.ini","Printers") I wish a variable to point and update another variable itself!, not sure if that makes sense, so i have two questions. 1) is it possible for me to have a variable update another variable as per my example below. Func read_file_into_array($ini_var, $ini_file, $ini_section) If FileExists($ini_file) Then $var = IniReadSection($ini_file, $ini_section) If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $ini_var[$i][1] = $var[$i][1] $ini_var[$i][0] = $var[$i][0] MsgBox(4096, "Number of Printers :" & $ini_var[0], "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf Else $error_code = 1 _put_event(1, "The INI file " & $ini_file & " may not exist or the section " & $ini_section & " within may not exist", @error) EndIf EndFunc ;==>read_host_file_into_array 2) and how can I copy 'not merge' the 2nd element of a 2D arraying into a 1D Array something like $var_printers = _StringBetween($network_printers[0][$x], "\\", "\") Full code to date below just in case expandcollapse popup#include <Array.au3> #include <EventLog.au3> #include <string.au3> Global $network_printers[99][2] read_file_into_array($network_printers,"vars.ini","Printers") Func _add_network_printers() For $x = 0 To UBound($network_printers[0][0]) - 1 Step 1 $var_printers = _StringBetween($network_printers[0][$x], "\\", "\") If Ping($var_printers[0], 25) Then ;_PrinterAdd($network_printers[0][$x], 0) Sleep(500) Else _put_event(1, "printer Device Error :" & $var_printers[0] & " Printer not present or pingable!", @error) $error_code = 1 EndIf Next EndFunc ;==>_add_network_printers Func read_file_into_array($ini_var, $ini_file, $ini_section) If FileExists($ini_file) Then $var = IniReadSection($ini_file, $ini_section) If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $ini_var[$i][1] = $var[$i][1] $ini_var[$i][0] = $var[$i][0] MsgBox(4096, "Number of Printers :" & $ini_var[0], "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf Else $error_code = 1 _put_event(1, "The INI file " & $ini_file & " may not exist or the section " & $ini_section & " within may not exist", @error) EndIf EndFunc ;==>read_host_file_into_array Func _put_event($value, $text, $error_id_code) ;SUCCESS = 0 ;ERROR =1 ;WARNING =2 ;INFORMATION =4 ;AUDIT_SUCCESS =8 ;AUDIT_FAILURE =16 Local $hEventLog, $aData[4] = [3, 1, 2, 3] $hEventLog = _EventLog__Open("", "Logon Script") _EventLog__Report($hEventLog, $value, 0, $error_id_code, @UserName, @CRLF & @CRLF & $text & @CRLF & @CRLF & "Contact Computer Facilities for more information, contact details can be found at [url="http://www.computer-facilities.com"]www.computer-facilities.com[/url] or e-mail [email="support@computer-facilities.com"]support@computer-facilities.com[/email]", $aData) _EventLog__Close($hEventLog) EndFunc ;==>_put_event Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Step by step. You already got an 2D array from IniReadSection. Why saving it to another 2D array? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) Step by step. You already got an 2D array from IniReadSection. Why saving it to another 2D array? This is just s general perpose .ini file, the printer section as you can see is a 2d array but I only need the 2nd element of the 2D array for the printer connection side of things, I wish to presurve the ability to read 2d array but sometimes I only need one element not two.. Below is my full vars.ini file to give you an idea, hope I am making sense. [Printers] "Black and White in Administration" = "[url="file://\dc-pri-cfuhp4250n"]\\dc-pri-cfu\hp4250n[/url]" "Colour in Administration" = "[url="file://\dc-pri-cfuhp4700n"]\\dc-pri-cfu\hp4700n[/url]" [Servers] "[url="file://\public"]\\public[/url]" = "[url="file://\10.0.0.4"]\\10.0.0.4[/url]" "[url="file://\CF-NAS1"]\\CF-NAS1[/url]" = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]" "[url="file://\CF-NAS1"]\\CF-NAS1[/url]" = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]" "[url="file://\CF-NAS1"]\\CF-NAS1[/url]" = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]" "[url="file://\CF-NAS1"]\\CF-NAS1[/url]" = "[url="file://\10.0.0.3"]\\10.0.0.3[/url]" [User groups] "cfu users" "Domain Admins" "quoteworks" "core" "Engineers" [cfu users] "h:" = "$homebase & "\user$\" & @UserName"" "p:" = "$public & "\public"" [Domain Admins] "s:" = "$source & "\source"" [quoteworks] "w:" = "$accounts & "\quotewerks"" [core] "x:" = "$accounts & "\core$"" "q:" = "$accounts & "\quickbooks$"" "t:" = "$accounts & "\clients$"" "u:" = "$accounts & "\suppliers$"" [Engineers] "s:" = "$source & "\source"" I am currently overhauling my logon script and want to make it more usable to admin people as apposed to programmers, I have attached the full script below that may give you a better idea of where I am comming from. expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=H:\My Documents\Website Work\computer-facilities.com\favicon.ico #AutoIt3Wrapper_Outfile=C:\Users\peter.CFU\Desktop\logon.exe #AutoIt3Wrapper_Res_Comment=Computer Facilities automated logon script for Windows Domain based networks running 32bit XP/Vista and Windows 7 OS. #AutoIt3Wrapper_Res_Description=independent automated logon script #AutoIt3Wrapper_Res_Fileversion=5.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Computer Facilities (Uganda) Ltd. ://////=__=.= ://////=__= #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/striponly #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** ;#RequireAdmin #include <Constants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> #include <NetShare.au3> #include <Misc.au3> #include <AD.au3> #include <File.au3> #include <string.au3> #include <EventLog.au3> ;Function keys to pause or terminate the script HotKeySet("{PAUSE}", "_TogglePause") HotKeySet("{END}", "_Terminate") Global $Paused Global Const $_SingleTonKey = "07c9623c-2ffb-4e6e-8fd9-f824ede2e9ac" ; e.g. GUID _single_instance() ; comment this line out if in multi user enviroment. Global $network_printers[2] ; make sure you updated the printer array to match the number of printers you have, last printer becomes the default $network_printers[0] = "\\dc-pri-cfu\hp4700n" $network_printers[1] = "\\dc-pri-cfu\hp4250n" Global $cmd = UBound($CmdLine) - 1 Global $network_drives[24] Global $local_IP = GetLanIP() Global $error_code = 0 $ostemp = _OSGet() If $ostemp = "vista_win7" Then ;this is only needed if your accessing external none windows based NAS devices if you using Vista or Windows 7 as a client ;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/Foru...ead/4606ad12-1f23-4231-8597-8e515422d57d[/url] $operation="Vista and Windows 7" $public = "\\10.0.0.4" $accounts = "\\10.0.0.3" $source = "\\10.0.0.3" $chaos = "\\10.0.0.3" $homebase = "\\10.0.0.3" $operation = "Vista Mode" ElseIf $ostemp = "winnt" Then $public = "\\public" $accounts = "\\CF-NAS1" $source = "\\CF-NAS1" $chaos = "\\CF-NAS1" $homebase = "\\CF-NAS1" $operation = "XP Mode" ElseIf $ostemp = "server" Then Exit ElseIf $ostemp = "preinstall" Then _put_event(1, "Logon Script not ment for a preinstall environment", @error) Exit Else MsgBox(16, "OS Incompatability", "this domain fully supports Windows XP/2000 Vista and Windows 7 workstations" & _ @CRLF & "with 2003/8 server support both 32 and 64bit" & _ @CRLF & @CRLF & "Current logged OS version is: " & @OSVersion) Exit EndIf If $CmdLine[0] = 0 Then Else _ReadCmdLineParams() EndIf $greeting = FuzzyTime() _put_event(4, "logon script started", @error) ProgressOn($greeting & " " & @UserName, "login onto " & @LogonServer & " (" & $operation & ")", "Automated Domain Access Progress", 50, 50, 16) ; >>> main part of the code that would require editing on a per domain basis <<< _say($greeting & " " & @UserName & ", and welcome to the Computer Facilities Network, please wait while you are being logged onto the system", 50) TrayTip("Logon script running", $operation & " Local IP: " & $local_IP, 7, 1) ProgressSet(6, "Finding network drives in use...") _AD_Open() If @error Then _put_event(1, "Active Directory error :" & @error & " AD connection could not be opened", @error) Exit Else _put_event(4, "Active Directory connection opened succesfully to " & @LogonDNSDomain, @error) EndIf If _AD_isMemberOf("cfu users", @UserName) Then ; cannot use 'domain users' seems to be some techci reason why that will not work, and make sure your usergroups do not have groups within as they seem not to be read. ProgressSet(10, "Removing old network shares please wait...") _delmappeddrive("*") ProgressSet(15, "Adding default shares") ProgressSet(20, "Home share" & $homebase & "\user$\" & @UserName) _mapdrive("h:", $homebase & "\user$\" & @UserName) ProgressSet(23, "Public share " & $public) _mapdrive("p:", $public & "\public") ProgressSet(26, "Setting up network printers") _add_network_printers() Else MsgBox(16, "Invalid User", "Sorry you apper not to have sufficent rights to use this domain") _put_event(4, "Invalid User tried to log on", @error) $error_code = 1 Exit EndIf If _AD_isMemberOf("Domain Admins", @UserName) Then _mapdrive("s:", $source & "\source") ProgressSet(40, "Setup admin shares") EndIf If _AD_isMemberOf("quoteworks", @UserName) Then _mapdrive("w:", $accounts & "\quotewerks") ProgressSet(50, "Setup quoteworks share") EndIf If _AD_isMemberOf("core", @UserName) Then _mapdrive("x:", $accounts & "\core$") _mapdrive("q:", $accounts & "\quickbooks$") _mapdrive("t:", $accounts & "\clients$") _mapdrive("u:", $accounts & "\suppliers$") ProgressSet(80, "Setup core shares") EndIf If _AD_isMemberOf("Engineers", @UserName) Then _mapdrive("s:", $source & "\source") ProgressSet(85, "Setup engineer share") EndIf ; >>>> no need to edit beyond this point.. _AD_Close() If @error Then _put_event(1, "Active Directory error :" & @LogonDNSDomain & " AD connection could not be closed", @error) Exit Else _put_event(4, "Active Directory connection Closed succesfully", @error) EndIf ProgressSet(90, "System Cleanup", "Started") temp_clean() EmptyRecycleBin() ProgressSet(95, "System Cleanup", "Complete") Sleep(500) ProgressSet(96, "IE Cleanup", "Started") IE_Clean() ProgressSet(99, "IE Cleanup", "Complete") _users() ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() _welcome() _put_event(4, "logon script finished", @error) ; >>> Sub part of the code that would require editing on a per User basis <<< Func _users() TrayTip("Individual preferences", "setup for " & @UserName, 7, 1) Switch @UserName Case "peter" ;_mapdrive("n:", $chaos & "\localcoms$") Case "tasha" ;_mapdrive("n:", $chaos & "\localcoms$") ;_mapdrive("m:", "\\10.0.0.53\Tasha Mabonga-Atkin's Tim") Case "accounts" ;_mapdrive("n:", $chaos & "\localcoms$") Case "engineers" ;_mapdrive("n:", $chaos & "\localcoms$") Case "administrator" MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10) EndSwitch EndFunc ;==>_users ; >>>> no need to edit beyond this point.. ;=============================================================================== ; ; Function Name: _PrinterAdd() ; Description: Connects to a Network Printer. ; Parameter(s): $sPrinterName - Computer Network name and printer share name (\\Computer\SharedPrinter). ; $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 $error_code = 1 _put_event(1, "Could not install printer :" & $sPrinterName & " on local computer " & @ComputerName & "Does shared printer exist on host machine?", @error) 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 _ReadCmdLineParams() For $ic = 1 To $cmd Select Case $CmdLine[$ic] = "-update" ; put code here Case $CmdLine[$ic] = "-newcomputer" ; put code here Case $CmdLine[$ic] = "-repair_domain_profile" ; put code here Case $CmdLine[$ic] = "-pc_diags" ; put code here Case $CmdLine[$ic] = "-backup_user_profile" ; put code here Case Else Exit EndSelect Next EndFunc ;==>_ReadCmdLineParams Func _single_instance() ;Stop script from running more than once, use [url="http://guidgen.com"]http://guidgen.com[/url] to make the $_SingleTonKey ;see [url="http://www.autoitscript.com/forum/index.php?showtopic=108203&st=0&p=762946&hl=_Singleton&fromsearch=1&#entry762946"]http://www.autoitscript.com/forum/index....&hl=_Singleton&fromsearch=1&#entry762946[/url] for more information ;may need to remove this if your in a terminal enviroment If WinExists($_SingleTonKey) Then ;MsgBox(16, "Another instance running", "this script is not ment to be running several instanaces at the same time") $error_code = 1 _put_event(1, "Another instance running :" & $_SingleTonKey & " this script is not ment to be running several instanaces at the same time on the same PC", @error) Exit (2) EndIf EndFunc ;==>_single_instance Func _add_network_printers() For $x = 0 To UBound($network_printers) - 1 Step 1 $var_printers = _StringBetween($network_printers[$x], "\\", "\") ProgressSet(27 + ($x * 2), "Adding " & $network_printers[$x]) If Ping($var_printers[0], 25) Then _PrinterAdd($network_printers[$x], 0) Sleep(500) Else _put_event(1, "printer Device Error :" & $var_printers[0] & " Printer not present or pingable!", @error) $error_code = 1 EndIf Next EndFunc ;==>_add_network_printers Func _mapdrive($DriveLtr, $DrivePath) $var_DrivePath = _StringBetween($DrivePath, "\\", "\") If Ping($var_DrivePath[0], 25) Then ; so now the function will not try to connect to a device that is not present, make sure your firewall allows ICBM echo requests. DriveMapAdd($DriveLtr, $DrivePath, 1) ; thanks to 99ojo for his help, see [url="http://www.autoitscript.com/forum/index.php?showtopic=110567&st=0&gopid=776497&#entry776497"]http://www.autoitscript.com/forum/index....ic=110567&st=0&gopid=776497&#entry776497[/url] Sleep(250) Switch @error Case 1 _put_event(1, "O.M.G Error, An unknown error occured on " & $DrivePath & " trying to be mapped as local drive " & $DriveLtr & " maybe end device is not avilable for mapping", @error) $error_code = 1 Case 2 _put_event(1, "Access Error, Access to the remote share " & $DrivePath & " was denied", @error) $error_code = 1 Case 3 _put_event(1, "Map Drive Error, The device/drive " & $DriveLtr & " is already assigned and will be deleted", @error) $error_code = 1 Case 4 _put_event(1, "Device Error, Invalid device " & $DriveLtr & " name", @error) $error_code = 1 Case 5 _put_event(1, "Connect to Remote Share Error, Invalid remote share :" & $DrivePath, @error) $error_code = 1 Case 6 _put_event(1, "Password Error for user :" & @UserName & " Invalid password for " & $DriveLtr & $DrivePath, @error) $error_code = 1 Case Else ;MsgBox(64, "Completed!", "Mapped " & $DriveLtr & " to share " & $DrivePath) EndSwitch Else _put_event(1, "Share (" & $DriveLtr & $DrivePath & ") could not be added. The host " & $var_DrivePath[0] & " device is not present or pingable!, make sure host firwall allows ping requests", @error) $error_code = 1 EndIf EndFunc ;==>_mapdrive Func _delmappeddrive($drived) If $drived = "*" Then $var = DriveGetDrive("Network") If Not @error Then For $i = 1 To $var[0] Step 1 $network_drives[$i] = $var[$i] Next For $i = 1 To $var[0] DriveMapDel($network_drives[$i]) If @error Then $error_code = 1 _put_event(1, "Delete All Drive Error " & $network_drives[$i] & " code :" & @error & " and is already assigned And could Not be deleted", @error) Else ;MsgBox(64, "Completed!", "Deleted " & $network_drives[$i]) EndIf Next Else $error_code = 1 _put_event(1, "Delete all drives error, no drives to delete.", @error) EndIf Else DriveMapDel($drived) If @error Then $error_code = 1 _put_event(1, "Map Drive Error " & $drived & " is already assigned and cannot be deleted", @error) Else ;MsgBox(64, "Completed!", "Deleted " & $network_drives[$i]) EndIf EndIf EndFunc ;==>_delmappeddrive Func GetLanIP() ;http://www.autoitscript.com/forum/index.php?showtopic=109887&st=0&gopid=772563&#entry772563 ;Thanks to Phodexis for this. ;http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DefaultIPGateway(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return @IPAddress1 If @IPAddress2 = $objItem.IPAddress(0) Then Return @IPAddress2 If @IPAddress3 = $objItem.IPAddress(0) Then Return @IPAddress3 If @IPAddress4 = $objItem.IPAddress(0) Then Return @IPAddress4 EndIf Next Else _put_event(1, "What no IP?", @error) $error_code = 1 Return @IPAddress1 ; if you dont have Gateway EndIf EndFunc ;==>GetLanIP Func GetLanGW() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DefaultIPGateway(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0) EndIf Next Else $error_code = 1 _put_event(1, "What no Gateway IP?", @error) Return @IPAddress1 ; if you dont have Gateway EndIf EndFunc ;==>GetLanGW Func GetLanDNS() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DNSServerSearchOrder(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0) EndIf Next Else Return @IPAddress1 ; if you dont have DNS EndIf EndFunc ;==>GetLanDNS Func GetLanDHCP() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DHCPServer(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0) EndIf Next Else Return "N/A" ; if you dont have a DHCP Server EndIf EndFunc ;==>GetLanDHCP Func GetLanSubnet() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.IPSubnet(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0) EndIf Next Else Return @IPAddress1 ; if you dont have IPSubnet EndIf EndFunc ;==>GetLanSubnet Func GetLANMACAddress() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.MACAddress(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) EndIf Next Else Return "N/A" ; if you dont have IPSubnet EndIf EndFunc ;==>GetLANMACAddress Func temp_clean() EmptyFolder(@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files\Content.IE5") EmptyFolder(@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files") EmptyFolder(@HomeDrive & @HomePath & "\Cookies") EmptyFolder(@HomeDrive & @HomePath & "\Local Settings\History") EmptyFolder(@HomeDrive & "\Temp\Temporary Internet Files") EmptyFolder(@WindowsDir & "\Temp") EmptyFolder(@HomeDrive & "\Temp") EmptyFolder(@HomeDrive & @HomePath & "\Recent") EmptyFolder(@HomeDrive & @HomePath & "\Application Data\Microsoft\Office\Recent") EmptyFolder(@HomeDrive & @HomePath & "\Local Settings\Temp") EndFunc ;==>temp_clean Func EmptyRecycleBin() Local $var = DriveGetDrive("FIXED") ;MsgBox(4096, "", "Found " & $var[0] & " Fixed drives") For $i = 1 To $var[0] FileRecycleEmpty($var[$i]) Switch @error Case 0 ; sucess not needed just there for completness Case 1 $error_code = 1 _put_event(1, "Could not empty recycle bin at " & $var[$i], @error) EndSwitch Next EndFunc ;==>EmptyRecycleBin Func IE_Clean() $var = _IEGet() Switch $var Case 7 To 8 ShellExecuteWait("RunDll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 255", @SW_HIDE) Case Else $error_code = 1 _put_event(1, "IE Clean could not be done, IE Version :" & $var & "not supported requires IE7 or 8", @error) EndSwitch EndFunc ;==>IE_Clean Func EmptyFolder($FolderToDelete) $Debug = 0 ;0 or 1 $AllFiles = _FileListToArray($FolderToDelete, "*", 0) If $Debug Then ConsoleWrite("-->" & $FolderToDelete & @CRLF) If IsArray($AllFiles) Then If $Debug Then _ArrayDisplay($AllFiles, $FolderToDelete) EndIf For $i = 1 To $AllFiles[0] $crt = FileGetTime($FolderToDelete & "\" & $AllFiles[$i], 1) If $crt[2] = @MDAY And $crt[0] = @YEAR And $crt[1] = @MON Then If $Debug Then ConsoleWrite($FolderToDelete & "\" & $AllFiles[$i] & " --> Today's File, Skipping!" & @CRLF) EndIf ContinueLoop EndIf $delete = FileDelete($FolderToDelete & "\" & $AllFiles[$i]) If $Debug Then ConsoleWrite($FolderToDelete & "\" & $AllFiles[$i] & " =>" & $delete & @CRLF) EndIf DirRemove($FolderToDelete & "\" & $AllFiles[$i], 1) Next EndIf EndFunc ;==>EmptyFolder Func _deleteautorun($drive) EndFunc ;==>_deleteautorun Func _welcome() Local $local_domain = @LogonDNSDomain Local $domain_server = @LogonServer Local $gateway = GetLanGW() Local $dns_server = GetLanDNS() Local $dhcp_server = GetLanDHCP() Local $subnet_mask = GetLanSubnet() Local $mac_address = GetLANMACAddress() Local $welcome = GUICreate("IP: " & $local_IP & " DNS: " & $dns_server & " GW: " & $gateway & " DHCP: " & $dhcp_server, 500, 200) GUISetIcon("D:\applications\AutoIt3\Icons\help.ico") GUICtrlCreateLabel("Welcome " & @UserName & " to the " & $local_domain & " Network" & _ @CRLF & @CRLF & "you seem to be running " & @OSVersion & " " & @OSServicePack & " OS in " & @OSArch & " mode" & @CRLF & @CRLF & "Your home directory is: " & $homebase & "\user$\" & @UserName & _ @CRLF & @CRLF & "If you have any problems or questions with your account please contact Computer Facilities support on " & @CRLF & "0414-533784 or e-mail: [email="support@computer-facilities.com"]support@computer-facilities.com[/email]" & _ @CRLF & @CRLF & "Logon script in " & $operation & " from " & @ComputerName & @CRLF & "MAC : " & $mac_address & " using Server " & $domain_server, 10, 10) Switch $error_code Case 0 GUICtrlCreateLabel("No Errors Present", 10, 180) Case 1 GUICtrlCreateLabel("*** See Application Event Log ***", 10, 180) $diags = "IP: " & $local_IP & " DNS: " & $dns_server & " GW: " & $gateway & " DHCP: " & $dhcp_server & _ @CRLF & @CRLF & @OSVersion & " " & @OSServicePack & " OS in " & @OSArch & " mode" & @CRLF & @CRLF & "home directory is: " & $homebase & "\user$\" & @UserName & _ @CRLF & @CRLF & "Logon script in " & $operation & " from " & @ComputerName & @CRLF & "MAC : " & $mac_address & " using Server " & $domain_server _put_event(4, $diags, @error) EndSwitch $Link = GUICtrlCreateLabel("About", 460, 180) GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetFont(-1, Default, Default, 4) GUICtrlSetCursor(-1, 2) GUISetState(@SW_SHOW, $welcome) While WinActive($welcome) $aMsg = GUIGetMsg() Switch $aMsg Case $GUI_EVENT_CLOSE GUIDelete($welcome) Case $Link _About() EndSwitch WEnd ; About window EndFunc ;==>_welcome Func _About() $About = GUICreate("About Secure Autologin", 500, 200) GUISetIcon("D:\applications\AutoIt3\Icons\windows.ico") GUICtrlCreateLabel("Secure login created by Computer Facilities - A Network Admin's best friend." & _ @CRLF & @CRLF & "Features" & _ @CRLF & "- integrates with AD domain security" & _ @CRLF & "- secure verification by MAC, IP and Username" & _ @CRLF & "- optional secure dongle logon" & _ @CRLF & "- user level customization" & _ @CRLF & "- push software installs and updates domain wide" & _ @CRLF & "- integrates with ZyXEL security appliances" & _ @CRLF & "- auto setup full user environment" & _ @CRLF & @CRLF & "Computer Facilities specialists in network installation and network security solutions", 10, 10) $Link = GUICtrlCreateLabel("[url="http://www.computer-facilities.com"]www.computer-facilities.com[/url]", 350, 180, 280) GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetFont(-1, Default, Default, 4) GUICtrlSetCursor(-1, 2) GUISetState(@SW_SHOW, $About) While WinActive($About) $aMsg = GUIGetMsg() Switch $aMsg Case $GUI_EVENT_CLOSE GUIDelete($About) Case $Link ShellExecute("[url="http://www.computer-facilities.com"]http://www.computer-facilities.com[/url]") EndSwitch WEnd ; About window EndFunc ;==>_About Func _put_event($value, $text, $error_id_code) ;SUCCESS = 0 ;ERROR =1 ;WARNING =2 ;INFORMATION =4 ;AUDIT_SUCCESS =8 ;AUDIT_FAILURE =16 Local $hEventLog, $aData[4] = [3, 1, 2, 3] $hEventLog = _EventLog__Open("", "Logon Script") _EventLog__Report($hEventLog, $value, 0, $error_id_code, @UserName, @CRLF & @CRLF & $text & @CRLF & @CRLF & "Contact Computer Facilities for more information, contact details can be found at [url="http://www.computer-facilities.com"]www.computer-facilities.com[/url] or e-mail [email="support@computer-facilities.com"]support@computer-facilities.com[/email]", $aData) _EventLog__Close($hEventLog) EndFunc ;==>_put_event Func _IEGet() Local $sVersion = FileGetVersion(@ProgramFilesDir & "\Internet Explorer\iexplore.exe") Switch StringLeft($sVersion, 1) Case "8" Return "8" Case "7" Return "7" Case "6" Return "6" Case "5" Return "5" Case "4" Return "4" Case Else Return "1" EndSwitch EndFunc ;==>_IEGet Func _OSGet() Switch @OSVersion Case "WIN_7" Return "vista_win7" Case "WIN_XP" Return "winnt" Case "Win_2000" Return "winnt" Case "WIN_VISTA" Return "vista_win7" Case "WIN_2008" Return "server" Case "WIN_2008R2" Return "server" Case "WIN_2003" Return "server" Case Else $error_code = 1 ;MsgBox(32, "OS Version Machine Diags", "User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", 10) _put_event(1, "Unsupported OS Version, User " & @UserName & " on computer " & @ComputerName & " running OS " & @OSVersion & " " & @OSArch & " Architecture", @error) Return "not supported" 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 Func FuzzyTime() Switch @HOUR Case 5 To 7 Return "Your the Early Bird" Case 8 To 11 Return "Good Morning" Case 12 To 17 Return "Good Afternoon" Case 18 To 20 Return "Good Evening" Case 21 To 23 Return "It is getting late" Case Else Return "Get a life" EndSwitch EndFunc ;==>FuzzyTime ;some fun Func _say($v2t, $volume) Local $objVoice = False, $temp $objVoice = ObjCreate("SAPI.SpVoice") $objVoice.Volume = $volume $objVoice.Rate = 0 $objVoice.Speak($v2t, 0) EndFunc ;==>_say 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 Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Sorry, I still do not get your problem. Please try to strip it down to an easy example. You got a 2d array and want it to become a 1d array or 2 1d arrays? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) Sorry, I still do not get your problem. Please try to strip it down to an easy example. You got a 2d array and want it to become a 1d array or 2 1d arrays? i am wanting the 2nd element of a d2 array put into 1d array. something like: $var[1][1]"blah blah blah" "//server/printer" the 2nd element to be put into $var1[1].. so $var1[1] would look like "//server/printer" does that help.. Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 #include <Array.au3> Global $2dArray[4][2] = [['1', 'a'], ['2', 'b'], ['3', 'c'],['4', 'e']] _ArrayDisplay($2dArray) Global $1DArrayFirst[UBound($2dArray)], $1DArraySecond[UBound($2dArray)] For $i = 0 To UBound($2dArray) -1 $1DArrayFirst[$i] = $2dArray[$i][0] $1DArraySecond[$i] = $2dArray[$i][1] Next _ArrayDisplay($1DArrayFirst, '$1DArrayFirst') _ArrayDisplay($1DArraySecond, '$1DArraySecond') Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) Excellent example I see where I had my issues now.. #include <Array.au3> #include <EventLog.au3> #include <string.au3> Global $network_printers[99][2] Global $number_of_network_printers _add_network_printers() Func _add_network_printers() For $j = 1 To read_file_into_array("vars.ini","Printers") MsgBox(4096, "Number of Printers :" & $number_of_network_printers, "Key: " & $network_printers[$j][0] & @CRLF & "Value: " & $network_printers[$j][1]) $printer = $network_printers[$j][1] _PrinterAdd($printer, 0) Next EndFunc ;==>_add_network_printers Func read_file_into_array($ini_file, $ini_section) If FileExists($ini_file) Then $var = IniReadSection($ini_file, $ini_section) If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $network_printers[$i][1] = $var[$i][1] $network_printers[$i][0] = $var[$i][0] MsgBox(4096, "Number of Printers :" & $var[0][0], "Key: " & $network_printers[$i][0] & @CRLF & "Value: " & $network_printers[$i][1]) Next $number_of_network_printers = $var[0][0] Return $number_of_network_printers EndIf Else $error_code = 1 _put_event(1, "The INI file " & $ini_file & " may not exist or the section " & $ini_section & " within may not exist", @error) EndIf EndFunc ;==>read_host_file_into_array Thanks I shall close this topic and star a new one for the variable issues once I thought out how to phrase it properly. Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Fine, you got it! New thread? No, I guess that is not needed. Just try to explain in simple words what is your problem and I'll have a look whether I can help you. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) Currently I have something likeIf $ostemp = "vista_win7" Then $operation="Vista and Windows 7" $public = "\\10.0.0.4" $accounts = "\\10.0.0.3" $source = "\\10.0.0.3" $chaos = "\\10.0.0.3" $homebase = "\\10.0.0.3" $operation = "Vista Mode" ElseIf $ostemp = "winnt" Then $public = "\\public" $accounts = "\\CF-NAS1" $source = "\\CF-NAS1" $chaos = "\\CF-NAS1" $homebase = "\\CF-NAS1" $operation = "XP Mode" Else Exit EndIfI would like to add this to the vars.ini file so the file may look like this.[Shares] “$public” = “\\CF-NAS1 “ “$accounts” = ” \\CF-NAS1” “$source” = “\\CF-NAS1” “$chaos” = “\\CF-NAS1” “$homebase” =” \\CF-NAS1” [Servers] "\\CF-NAS1" = "10.0.0.3"I know how to read the above into an array but what I do not know is how can I extract the first element of the array in the section Shares and have it defined and act as a variable within the script, as per the autoit example .I hope I have been a little clearer in my explanation this time. Sorry forgot my manners, thanks for you help as you can tell I'm a bit new to this.. Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 You can easily access the keys and values of the ini using somthing like this. $re = IniReadSection('ini.ini', 'Shares') For $i = 1 To UBound($re) - 1 ConsoleWrite('Use this for the Key : ' & $re[$i][0] & @CRLF) ConsoleWrite('Use this for the Value : ' & $re[$i][1] & @CRLF) Next Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) Seems I have not explained correctly, what I want to do is read the section shares in and have them declared as variables within the script.. so they can be used and manipulated as true declared variables: for example $public = "\\CF-NAS1“ would be in the .ini "$public” = “\\CF-NAS1“ or simlair.. Edited March 12, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Although is not necessary, cause you can work this the array variable from IniReadSection, you can assign every variable if you want to. $re = IniReadSection('ini.ini', 'Shares') Global $public, $accounts, $source, $chaos, $homebase For $i = 1 To UBound($re) - 1 ;~ ConsoleWrite('Use this for the Key : ' & $re[$i][0] & @CRLF) ;~ ConsoleWrite('Use this for the Value : ' & $re[$i][1] & @CRLF) Assign($re[$i][0], $re[$i][1], 2) Next ConsoleWrite($public & @CRLF) My ini.ini looks like this [Shares] public=\\CF-NAS1234 accounts=\\CF-NAS1 source=\\CF-NAS1 chaos=\\CF-NAS1 homebase=\\CF-NAS1 Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 12, 2010 Author Share Posted March 12, 2010 OK thanks that seems to have done the trick! [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 OK thanks that seems to have done the trick!Glad, that I could help you! Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now