Jump to content

Recommended Posts

Posted

Hi all,

First of all, not sure whether to post this here or example scripts as although it works it does have a problem

This is my first script I have made with AutoIT, its very basic but does some deployment tasks to make my life easier.

Script:

  Reveal hidden contents

2 Questions:

1, Why doesn't this part work? If the Computer has a floppy disk, the script still tries to read it even though I have specified no A:\ When it tries to read A:\ the files do not copy from the usb stick & then the script continues to add users to admins.

; Locate USB Drive & assigned drive letter, then copy files.
$var = DriveGetDrive( "removable" )
If NOT @error Then
For $i = 1 to $var[0]
   If $var[$i] = "a:" Then ContinueLoop
$usbdrive = $var[$i]

2, Can you suggest any improvements to the code, as I've said this is my first one and I've never tried scripting before.

Posted (edited)

; Deployment Script
#RequireAdmin ; script requires admin rights
#NoTrayIcon ; do not display autoit tray icon
#include <Constants.au3>

; Gather information
$hUser = InputBox("Input", "Enter the persons name who will use this computer in the format USERNAME, FORENAME: ")
If $hUser = @error Or $hUser = 0 Or StringLen($hUser) < 1 Then
    MsgBox(0, "Error", "No data entered or cancel was pressed", 5) ; changed timeout to 5 seconds
    Exit
Else
    ; Read and format MAC address
    $hRun = Run(@ComSpec & " /c getmac /fo csv /nh", '', @SW_HIDE, $STDOUT_CHILD) ; get mac address
    While ProcessExists($hRun)
        Sleep(100) ; wait for window to close
    WEnd
    $sMAC = StringLeft(StringReplace(StringReplace(StringStripWS(StdoutRead($hRun), 8), "-", ""), """", ""), 12) ; format MAC address
    ; Check if Corp. IS&T has been contacted
    $hYesNo = MsgBox(4, "Check!", "Have you registered the MAC# with Corporate IS&T for ACS (Authentication)")
    If $hYesNo = 7 Then
        Exit
    Else
        RunWait(@ComSpec & " /c netsh interface tcp set global autotuning=disabled") ; disable autotuning on network card
        ; Locate USB Drive & assigned driver letter, then copy files
        $aVar = DriveGetDrive("removable")
        If Not @error Then
            For $i = 1 to UBound($aVar) - 1
                If $aVar[$i] = "a:" Then ContinueLoop
                $sUsb = $aVar[$i]
                Sleep(3000)
                FileCopy($sUsb & "7_DeploymentShortcuts*.*", "C:UsersPublicDesktop", 1)
            Next
        Else
            MsgBox(4112, "Error", "USB Drive not found")
            Exit
        EndIf
        FileDelete ("C:UsersPublicDesktopInfoWorks 4.url") ; delete infoworks file from public desktop
        If Not FileExists("C:Temp") Then DirCreate("C:Temp") ; create directory if it doesnt exist
        FileCopy($sUsb & "7_DeploymentCitrix FixAPPSRV.INI", "C:UsersDefaultAppDataRoamingICAClient", 1) ; copy citrix file to default users - stops WCSError on boot
        ; code for adding user as an administrator. not sure what you are doing here and why, so letting you figure out a better way to work that code.
        ; the above code should help you understand how to make your code more efficient
    EndIf
EndIf

I have not tested it, but it passes syntax checks.

I'm not sure why you are getting the machines MAC addres since your code doesn't seem to do anything with it. But you can use my code I've found that works quite well to get a machines MAC address. I store it in the variable $sMAC

Edited by kor
Posted

Regarding the MAC address, its just to have it on screen if the person deploying hasn't already contacted the department to add it to network.

Posted

  On 5/25/2012 at 3:28 AM, 'EllisDee said:

Regarding the MAC address, its just to have it on screen if the person deploying hasn't already contacted the department to add it to network.

Then change

$sMAC = StringLeft(StringReplace(StringReplace(StringStripWS(StdoutRead($hRun), 8), "-", ""), """", ""), 12) ; format MAC address
    ; Check if Corp. IS&T has been contacted
    $hYesNo = MsgBox(4, "Check!", "Have you registered the MAC# with Corporate IS&T for ACS (Authentication)")

To

$sMAC = StringLeft(StringReplace(StringStripWS(StdoutRead($hRun), 8), """", ""), 17) ; format MAC address
    ; Check if Corp. IS&T has been contacted
    $hYesNo = MsgBox(4, "Check!", "Have you registered the MAC " & $sMAC & " with Corporate IS&T for ACS (Authentication)")

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
×
×
  • Create New...