Jump to content

Input string without spaces

Recommended Posts

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)


$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



MsgBox(0, "Success", "Phase 1 complete, Local Machine renamed to:" & $var1 & @CRLF & "Your system must be restarted", 5)



ProgressOn("Shutdown in Progress", "Your system will restart in 5 seconds. ", "0 Percent")

For $i = 10 To 100 Step 10


ProgressSet($i, $i & " Percent")


ProgressSet(100, "Done ", "Restarting... ")







Link to comment
Share on other sites

Remove the spaces yourself:


Strips the white space in a string.

StringStripWS ( "string", flag )

--- OR ---

    $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
Until $ErrorCode = 0
Edited by vbMark
Link to comment
Share on other sites

  • 2 weeks later...

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 reboot

You 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 :)

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

  • Recently Browsing   0 members

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