Jump to content

Computer Set Up


Recommended Posts

Hey all,

 

I'm new to AutoIt, and I'm trying to get my feet wet, but I'm pretty overwhelmed. I'm trying to create a script that does a few things for a new computer set up for us, but I'm not even sure where to get started. I sort of laid out my idea for how I want things to go like this, but I could really use some direction. 

 

; Script Start - Add your code below here

; Change Admin Name to "COMPANY"

; Change Admin Password to "xxxxxx"

; Set Password Hint as "Please see documentation"

; Rename PC "Company-Laptop-'xxx'" where 'xxx' is the next available number on tracking spreadsheet

; Disable Notifications "Show me tips about Windows"

; Open this web link "software download"

; Save at prompt

; Run "software set up"

; Pin "program a" to Taskbar

; Delete "program b" Shortcut

; Set "program b" as Default PDF Reader

; Set "program a" as Default Web Browser

; Remove "program c" from Taskbar

 

I appreciate any help. I could outsource, but I'm hoping to learn for myself. 

Thanks!

Link to comment
Share on other sites

I can see why you're overwhelmed, that's a lot of tasks! I'm fairly experienced with AutoIT and it would take me a while to develop a script that can do all those tasks, specially sometime robust enough to work on many machines. And there may be more suitable tools, such as creating a master image and restoring with Sysprep that might be more applicable.

Start by breaking each task down. Create a test script to tackle only one problem. Don't worry about the user interface, don't worry about the other tasks. Just use hard coded values in the script. When in development I like using "ConsoleWrite" to spit out some debug information while I go. When

When looking at some of these system level changes, see if there's any programmatic API, registry, WMI, commandline tool that can do it. Trying to rely on pure GUI automation (mousemove, click, keystrokes, even controlclick) can be fragile. Your script is doing a lot of admin level stuff so it will need #RequireAdmin at the top.

Admin username / password: Look at Commandline interface via Net: (net User, Net localgroup).

These could be invoked via a Runwait() command. No need to use @COMSPEC because net.exe is separate from the command interpreter cmd.exe.

Password hint may be more difficult

Computer Name: Looks possible via wmic. Looks like you need to know existing name, doable via @ComputerName in AutoIt

Sample wmic code, looking like it's written for batch, is:

wmic computersystem where name="%COMPUTERNAME%" 
     call rename name="NEW-NAME"

Getting name from excel may be a little more involved, especially if Excel isn't installed on the PC. Look at IniRead, and FileRead/FileREadLine/FileReadToArray for potential options to read from a text file.

To download something via http, check InetGet()

Run programs using "Run" if you'll then need to interact with it, or "RunWait" if you want to wait for execution to finish.

Pinning in Windows 7 at least it's just copying or deleting a shortcut into a certain file. Either per user, or one for global. Check our FileCopy() and FileDelete()

 

Once you can get the individual features working, then look at starting to assemble them in one script.

Link to comment
Share on other sites

Thanks for the tip, TurionAltec! I appreciate your expertise. 

Is there anything else I should know? I've read through the help file, and it's still fairly daunting. Any particular tutorials of note, or useful tips/ticks, or other resources I should check out?

Link to comment
Share on other sites

I think I've gotten a good start, so far. This is my current progress. I haven't run the body of the script yet, but it gives me an idea of the command that I need to include.

 

#RequireAdmin
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

; Change Admin Name to "COMPANYNAME"
ControlSend ("wmic useraccount where name='Owner' rename COMPANYNAME")

; Change Admin Password to "PASSWORD"
ControlSend ("net user COMPANY NAME PASSWORD")
; Set Password Hint as "Please see documentation"
RegWrite ("HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\COMPANYNAME [, "UserPasswordHint", "REG_SZ", "Please see documentation"] )

; Rename PC "COMPANYNAME-Laptop-'xxx'" where 'xxx' is the next available number on tracking spreadsheet (may require GUI for input)

; Disable Notifications "Show me tips about Windows" (Still not sure how to do this one, may need regedit, or GUI prompt)

; Open this web link "web address"
InetGet ("web address", "programABpackage.exe" [, options = 0 [, background = 0]] )

; Run "programABpackage.exe"
RunWait ( "programABpackage.exe" )

; Pin "programA" to Taskbar (need to find default directory)

; Delete "programB" Shortcut (need to find default directory)

; Set "programB" as Default PDF Reader
ControlSend ("assoc .pdf=programB")

; Set "programA as Default Web Browser
ControlSend ("assoc .html=programA")

; Remove Edge from Taskbar (may require mouse automation)

 

Link to comment
Share on other sites

@KVice

All your ControlSend() should be replaced with Run() or RunAs() function; that's because ControlSend() sends an hotkey or raw keys to a GUI control, rather than Run()/RunAs(), which run a command, returning the PID of the application you did run.

For the point about renaming the PC, you could use a CSV file in which you store the needed information, and then manipulate them through _FileReadToArray()/_FileWriteFromArray(); look at those functions in the Help file.

For the point about disabling Windows notifications, take a look at this link :)

By the way, welcome to the AutoIt forums :welcome:

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • 1 month later...

Rename the computer with this:

;==================================================================================================
; Sets computer name without restart (but restart is required for name to be in effect)
; Author: JScript - Snippet Version No. = 1.0
; Snippet was Created Using AutoIt Version = 3.3.8.1, Creation Date = 28/05/12.
;==================================================================================================
Func _SetComputerName($sCmpName)

    Local $sLogonKey = "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon"
    Local $sCtrlKey = "HKLMSYSTEMCurrentControlSet"
    Local $aRet

    ; RagsRevenge -> http://www.autoitscript.com/forum/index.php?showtopic=54091&view=findpost&p=821901
    If StringRegExp($sCmpName, '|/|:|*|?|"|<|>|.|,|~|!|@|#|$|%|^|&|(|)|;|{|}|_|=|+|[|]|x60' & "|'", 0) = 1 Then Return 0

    ; 5 = ComputerNamePhysicalDnsHostname
    $aRet = DllCall("Kernel32.dll", "BOOL", "SetComputerNameEx", "int", 5, "str", $sCmpName)
    If $aRet[0] = 0 Then Return SetError(1, 0, 0)
    RegWrite($sCtrlKey & "ControlComputernameActiveComputername", "ComputerName", "REG_SZ", $sCmpName)
    RegWrite($sCtrlKey & "ControlComputernameComputername", "ComputerName", "REG_SZ", $sCmpName)
    RegWrite($sCtrlKey & "ServicesTcpipParameters", "Hostname", "REG_SZ", $sCmpName)
    RegWrite($sCtrlKey & "ServicesTcpipParameters", "NV Hostname", "REG_SZ", $sCmpName)
    RegWrite($sLogonKey, "AltDefaultDomainName", "REG_SZ", $sCmpName)
    RegWrite($sLogonKey, "DefaultDomainName", "REG_SZ", $sCmpName)
    RegWrite("HKEY_USERS.DefaultSoftwareMicrosoftWindows MediaWMSDKGeneral", "Computername", "REG_SZ", $sCmpName)

    ; Set Global Environment Variable
    RegWrite($sCtrlKey & "ControlSession ManagerEnvironment", "Computername", "REG_SZ", $sCmpName)
    ; http://msdn.microsoft.com/en-us/library/ms686206%28VS.85%29.aspx
    $aRet = DllCall("Kernel32.dll", "BOOL", "SetEnvironmentVariable", "str", "Computername", "str", $sCmpName)
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)
    ; http://msdn.microsoft.com/en-us/library/ms644952%28VS.85%29.aspx
    $iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", "hwnd", 0xffff, "dword", 0x001A, "ptr", 0, _
            "wstr", "Environment", "dword", 0x0002, "dword", 5000, "dword_ptr*", 0)
    If $iRet2[0] = 0 Then Return SetError(2, 0, 0)

    Return 1
EndFunc   ;==>_SetComputerName

 

Always carry a towel.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...