Jump to content

Recommended Posts

Posted

Hi, I am having issue with this script. Basically I want to be able to type something into an input box. Click install and have it open my System Properties, go to the computer name and send the variable defined by the input box. So if I typed in.. "Jenkin's Computer" in the input box, it would send that to the "send($inv)". But I am just having syntax issues now. Any clue?

#include <GUIConstants.au3>
   
    GUICreate("ZenRenameiT", 255, 85, 255, 255)
    GUICtrlCreateLabel("Type in the computer TE number and click rename.", 5, 5)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $inv = GUICtrlCreateInput("", 75, 25, 100, 20)
    $btn = GUICtrlCreateButton("Rename", 95, 55, 60, 20)
    GUICtrlSetData($btn, $inv)
    GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn
            If GUICtrlRead($btn) = $inv Then
                _Rename()
                    EndIf
            ExitLoop
    EndSelect
WEnd


Func _Rename()

    Run(@ComSpec & " /c sysdm.cpl", "", @SW_HIDE)
    WinWaitActive("System Properties")
    Send("{RIGHT}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{ENTER}")
    Send($inv)
EndFunc

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Posted (edited)

This works :)

#include <GUIConstants.au3>

GUICreate("ZenRenameiT", 255, 85, 255, 255)
GUICtrlCreateLabel("Type in the computer TE number and click rename.", 5, 5)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$inv = GUICtrlCreateInput("", 75, 25, 100, 20)
$btn = GUICtrlCreateButton("Rename", 95, 55, 60, 20)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn
                _Rename()
            ExitLoop
    EndSelect
WEnd


Func _Rename()

    Run(@ComSpec & " /c sysdm.cpl", "", @SW_HIDE)
    WinWaitActive("System Properties")
    Send("{RIGHT}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{ENTER}")
    $x = GUICtrlRead($inv)
    Send($x)
EndFunc   ;==>_Rename

Edit: I removed some useless things... Now the button is called how it should.

Edited by Kiti
Posted (edited)

  Richardo said:

ahhh I see! Thank you so much! :)

You're welcome ! :P The thing to remember from here is that you always have to use GuiCtrlRead($ControlID) when you want to do something with some data obtained from the user. :P

Edited by Kiti
Posted

You could replace this:

CODE
Run(@ComSpec & " /c sysdm.cpl", "", @SW_HIDE)

WinWaitActive("System Properties")

Send("{RIGHT}")

Send("{TAB}")....

with this:

CODE
Run(@ComSpec & " /c sysdm.cpl,1", "", @SW_HIDE)

WinWaitActive("System Properties")

Send("{TAB}")....

Posted (edited)

There are more reliable ways to do this:

$strDomain = "domainname"
$strPassword = "password"
$strUser = "username"

$strNewComputerName = "newName"

$objNetwork = ObjCreate("WScript.Network")
$strComputer = $objNetwork.ComputerName

$objComputer = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\" & $strComputer & "\root\cimv2:Win32_ComputerSystem.Name=" & $strComputer & "")
$ErrCode = $objComputer.Rename($strNewComputerName, $strPassword, $strUser)
If $ErrCode = 0 Then
     MsgBox (0,"","Computer renamed correctly.")
Else
     MsgBox (0,"","Eror changing computer name. Error code: " & $ErrCode)
EndIf

Even easier:

http://www.autoitscript.com/forum/index.ph...script++network

Edited by weaponx
Posted

Remember that changing the computer name requires a restart before it takes effect.

George

  Reveal hidden contents
Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
  • Recently Browsing   0 members

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