AE6382 Scripting in Windows AE 6382. Documentation l The most difficult aspect of scripting in...
Click here to load reader
AE6382 Scripting in Windows AE 6382. Documentation l The most difficult aspect of scripting in Windows is finding the documentation. l Microsoft produces
Text of AE6382 Scripting in Windows AE 6382. Documentation l The most difficult aspect of scripting in...
M/S Scripting DocumentationAE6382 Documentation The most difficult aspect of scripting in Windows is finding the documentation. Microsoft produces enormous quantities of documentation for its part – it is a matter of locating the correct document and interpreting it. The documentation for non-Microsoft software can be difficult. AE6382 MS Documentation Local copies of some of the MS scripting documents are located at AE6382 Windows Scripting Host The Windows Scripting Host provides an environment for running scripts in Windows. Provides a host for ActiveX scripting engines (VBScript, Jscript, and other 3rd party implementations) The fundamental object is WScript and is pre-instantiated Properties Windows Scripting Host The WshShell object makes it possible to run a program locally. Can control the programs input and output The WshScriptExec object is returned from the Exec method and contains status information Properties CurrentDirectory Methods AE6382 Runtime Scripting The Runtime Scripting component provides capabilities for VBScript and Jscript that are not otherwise available. They cannot be use when scripting a web page in IE. The objects included in the Runtime Scripting are Dictionary (associative arrays) File System Object MS Office Objects The objects available for the Office programs (Excel in this case) are located on the Office CD in the form of .chm (MS Help files). The file for Excel 10 is VBAXL10.CHM This file contains all the objects and their methods and properties. The objects documented here can be used either by VBA within Excel or accessed externally via automation of the Excel program. For more information see Automation of Excel Example An application that uses data stored in an Excel worksheet to generate a configuration file for use by a Linux dhcp server. The Excel file contains IP address, MAC address, location, owner, and information about whether address is to be managed by dhcp. A script file uses automation to access the fields in the Excel file then generates a Linux formatted text file. AE6382 dhcp_sample.xls AE6382 # my $excel_file = 'e:\programming\ruby\dhcp_sample.xls'; AE6382 It can be downloaded from It is not using the Windows Scripting Host it is standalone. The Win32::OLE modules that are loaded via the use statements provide the automation support. See the ActivePerl documentation for more details. AE6382 my $Excel = Win32::OLE->GetActiveObject('Excel.Application') # Turn off any alert boxes (such as the SaveAs Response) $Excel->{DisplayAlerts} = 0; $Excel->{Visible} = 1; # Open the file # Create a reference to the worksheet my $Sheet = $Book->Worksheets('ASDL'); print "Loading data from $excel_file\n"; my $row_count = $Sheet->Rows->{Count}; print "row_count: $row_count\n"; foreach my $row (3..$row_count) { #print "ROW: $row\n"; my $name = $Sheet->Range("a${row}")->{Value}; print "name: $name\n"; last if $name eq ''; my $i = 0; foreach my $col (qw(a b c d e f g h i j)) { #print "COL: $col\n"; } $entry[1] =~ tr/A-F/a-f/; $entry[1] =~ tr/-/:/; my $mac = $entry[1]; my $flag = ($mac =~ m/[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}/); if ($flag != 1) { "\t",@entry,"\n"; next MAC; print "Duplicate MAC address: $entry[1]\n", "\t",@{$entry1},"\n", "\t",@entry,"\n"; next MAC; if (exists $ip_list{$entry[4]}) { my $entry1 = $ip_list{$entry[4]}; print "Duplicate IP address: $entry[4]\n", "\t",@{$entry1},"\n", "\t",@entry,"\n"; open(OUT,">dhcpd-hosts.conf") || die "Unable to create dhcpd-hosts.conf: $!"; binmode OUT; foreach my $key (sort keys %mac_list) { my $entry = $mac_list{$key}; # Skip non-dhcp controlled machines next if $entry->[5] ne 'Y' and $entry->[5] ne 'y'; my $host_name = $entry->[0]; next if $ip_address eq '*'; print OUT "\thardware ethernet $mac_address;\n"; print OUT "\tfixed-address $ip_address;\n"; print OUT "}\n";