gspino Posted June 9, 2005 Posted June 9, 2005 I hope one of you seasoned programmers can help. I have a rather large program designed to join a computer on a remote wan to the corp domain. One routine needs to change the name of the machine. I want to maintain netbios compatability and limit the input string to 15 charactors with no spaces. I can't seem to work out the logic using the String functions. Thank you in advance! ;============================================== ;GET INPUT - PHASE 1 NEW COMPUTER NAME (limit input to 15 chars no spaces) $aLoop = 1 If Not FileExists("c:\chgname.flg") Then While $aLoop = 1 $text1 = InputBox("WorkStation Preparation Utility 1.0", " " & @CRLF & "PHASE 1: Enter the unique computer name." & @CRLF & "", " ", " M15") If Not $text1 Then MsgBox(0, "Error ", "[cancel function disabled]" & @CRLF & "You must enter the correct information to continue... ", 3) Else $var1 = StringUpper($text1) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", $var1) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $var1) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $var1) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $var1) RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $var1) RunWait(@ComSpec & " /c " & "echo.>>c:\chgname.flg", "", @SW_HIDE) RunWait("c:\windows\install\classictheme\xpclassictheme.exe", "", @SW_HIDE) $aLoop = 0 EndIf WEnd MsgBox(0, "Success", "Phase 1 complete, Local Machine renamed to:" & $var1 & @CRLF & "Your system must be restarted", 5) ;============================================== ;DISPLAY SHUTDOWN MESSAGE ProgressOn("Shutdown in Progress", "Your system will restart in 5 seconds. ", "0 Percent") For $i = 10 To 100 Step 10 Sleep(500) ProgressSet($i, $i & " Percent") Next ProgressSet(100, "Done ", "Restarting... ") Sleep(1000) ProgressOff() ;============================================== Shutdown(6) EndIf Sleep(3000)
vbMark Posted June 9, 2005 Posted June 9, 2005 (edited) Remove the spaces yourself: StringStripWS Strips the white space in a string. StringStripWS ( "string", flag ) --- OR --- Do $ErrorCode = 0 $text1 = InputBox("WorkStation Preparation Utility 1.0", " " & @CRLF & "PHASE 1: Enter the unique computer name." & @CRLF & "", " ", " M15") If StringInStr($text1, " ") Then MsgBox(0, "Error", "No spaces allowed") $ErrorCode = 1 EndIf Until $ErrorCode = 0 Edited June 9, 2005 by vbMark
gspino Posted June 10, 2005 Author Posted June 10, 2005 Thank you very much. I elected to use the StringInStr function. Worked like a charm.\-Glen
MightyGuru Posted June 24, 2005 Posted June 24, 2005 You might also try using the netdom renamecomputer command. I wrote a script with GUI to perform this at work. Works flawlessly. Below is the syntax:netdom renamecomputer machine /newname:new_computername /userd:domainname\administrator_id /passwordd:* /usero:local_admin/passwordo:* /reboot:seconds before automatic rebootYou will need to install Windows XP Support Tools from the Support\Tools folder on the Windows XP Professional CD-ROM to get the netdom unility.From Microsoft:This article describes how to use the Netdom.exe utility (included in Windows XP Support Tools) to rename a computer that is a member of a Windows 2000 domain. This procedure can be performed either locally or remotely on the computer, which is being renamed. Also, the procedure does not require you to reset or manually re-create the computer account in the domain. The Netdom.exe utility has the ability to rename a computer that is a member of a domain. However, to rename the computer, you must be able to specify the user accounts that have local administrative permissions and the object of the computer account in Active Directory. Microsoft - Netdom.exe
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now