Jump to content

Alt C not working


Recommended Posts

hey Guys

 

I have this running an my script

Run('control.exe sysdm.cpl')

 

it opens the system properties window without issue

However when I follow 

 

Run('control.exe sysdm.cpl')

Send("!c")

Alt + C is now pressed in that window

 

I am obviously missing something simple here - I'd apreciate the help

Link to comment
Share on other sites

This can be done without automating the GUI for the system properties.  Please look at the AD UDF for adding computer to a domain, and below is a function to change the computer name.  

 

 

#RequireAdmin

_RenameComputer("New-Comp")  ;The new computer's name is "New-Comp."

Func _RenameComputer($sCompName, $sUserName = "", $sPassword = "") ;Uses WMI Win32_ComputerSystem

    Local $oMyError = ObjEvent("AutoIt.Error", "_ComError") ;COM Error Handler
    #forceref $oMyError
    Local $objWMIService = ObjGet("winmgmts:\root\cimv2")
    If @error Then
        Return SetError(1, 0, 0)
    EndIf

    For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem")
        Local $oReturn = $objComputer.Rename($sCompName, $sPassword, $sUserName)
        If $oReturn <> 0 Then
            Return SetError(2, 0, 0)
        Else
            Return 1
        EndIf
    Next
EndFunc   ;==>_RenameComputer

Func _ComError($oMyError) ;COM Error function defined in COM Error Handler used in COM functions.
    SplashOff()
    BlockInput(0) ;Enable the Keyboard and Mouse.
    MsgBox(16, "AutoItCOM ERROR!", "COM Error Intercepted!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
EndFunc   ;==>_ComError

 

Adam

 

Edited by AdamUL
Link to comment
Share on other sites

let me ask this - using the function I was provided for remaining the computer and joining it to the domain

 

My question is that - can changing the computer name and domaining it be done without rebooting the system

 

In other words is it change name - reboot then domain or change name and domain then reboot ?

 

If you do the process manually - it can be done in one step - trying to avoid a two step / reboot process

 

Hope that makes snese

Link to comment
Share on other sites

Yes.  You can do both before rebooting, as long as the PC is not already on a domain.  I would recommend doing the machine name first.  This will work MOST of the time.  I have encountered exceptions, but in general, you should be fine.

 

Link to comment
Share on other sites

I am pretty sure the window is active - cause I see it front and center when I run the script

You know it's funny for WEEKS I was trying to figure out how to name and domain a PC via a script and decided on three bat files that run and automate the while process - the first gets the parts started and the rest take it from there

 

However I was so confused after reading yes it can be done - no it can't be done. So I was happy I got it done with three files and several reboots

However now I am excited to learn it can be done in ONE step / script/ reboot!

Link to comment
Share on other sites

You could use WinWaitActive() before sending characters to be sure.

Key sends are a rather less than reliable way to go.  Try using ControlClick() instead.  You can use the "AutoIt Window Info" tool (that installs with AutoIt) to get the info you need for the ControlClick() parameters.

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...