因新機台數很多,想找快速方式可以將windows環境快速設定完畢的做法
於是我用autoIT帶入下面script
#RequireAdmin
send("#d")
$set1=msgbox(4," ","是否執行加入網域程序?")
if $set1=6 Then
$account = String("testaccount")
$password = String("testpw")
$domain = String("testAD")
run("control sysdm.cpl,,1")
winwaitactive("系統內容")
controlclick("系統內容","變更(&C)","Button2")
winwaitactive("電腦名稱變更")
controlclick("電腦名稱變更","","Edit3")
Send($domain)
send("{ENTER}")
winwaitactive("電腦名稱變更")
send($account)
send("{TAB}")
send($password)
Sleep(1500)
send("{ENTER}")
For $i=1 to 2
sleep(2000)
send("{ENTER}")
Next
controlclick("系統內容","確定","Button3")
send("{ENTER}")
EndIf
但上面的$domain卻沒有帶入到string裡的字串
想詢問還有什麼方式可以帶入字串?
其實用這種模擬鍵盤輸入有時候真的要很注意小細節。
你程式碼不行是因為沒去點到網域這個選項,所以當然他找不到地方輸入。
後面我就沒測試了,就你的問題回答到這邊。
利用VBS加入Domain也是不錯的方法,可以考慮一下~。
#RequireAdmin
send("#d")
$set1=msgbox(4," ","是否執行加入網域程序?")
if $set1=6 Then
$account = String("testaccount")
$password = String("testpw")
$domain = ("testAD")
run("control sysdm.cpl,,1")
winwaitactive("系統內容")
controlclick("系統內容","變更(&C)","Button2")
winwaitactive("電腦名稱/網域變更")
Send("!D")
Send("{TAB}")
Send($domain)
EndIf
'利用VBS加入網域
DomainName = InputBox("請輸入網域名稱")
AccName = InputBox("請輸入帳號")
AccPW = InputBox("請輸入密碼")
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = DomainName
strUser = AccName
strPassword = AccPW
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "\" & strUser, NULL, _
JOIN_DOMAIN + ACCT_CREATE)
MsgBox "Finished Domain change!", vbSystemModal+vbInformation