Announcement

Collapse
No announcement yet.

how do I write a script to change computer description & computer name on windows xp

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how do I write a script to change computer description & computer name on windows xp

    Hi,
    I run a computer cafe, and use ghost to image new games and updates across all the systems (running win xp prof.). The problem is, afterwards, I need to manually go around and adjust the computer description and the computer name through control panel -> system -> comp name, to prevent network issues.

    All the systems are assigned their ip address according to their mac, so I thought there might be a way to do a script to change the info according to the internal ip. (If - Then - Else Statements?)

    Preference would be a batch file, as there are some other files for the games that need to be modified, however, I don't know if batch files can do things this complex.

    Thanks for looking!
    Dan

  • #2
    Re: how do I write a script to change computer description & computer name on windows

    And what has this to do with Networking?
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Re: how do I write a script to change computer description & computer name on windows

      Originally posted by Dumber View Post
      And what has this to do with Networking?
      not a lot, Marcel! unless the OP has "Networking" confused with "Google", where you can do a nifty thing that I just discovered called a "search", like http://www.google.co.uk/search?hl=en...ter+name&meta= which gives loads of answers. Well well well. No need to reinvent the wheel.
      Best wishes,
      PaulH.
      MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008

      Comment


      • #4
        Re: how do I write a script to change computer description & computer name on windows

        It has to do with networking, as I want the script to change the computer name as it shows on the network, and as it is doing so by the ip address of the individual computer.
        If ip=10.0.0.1 then name=comp-1 & description=comp-1
        etc.

        I have tried google, and found a couple that will change the network name, with input fields required, however, having to go around telling the script what to put in, I may as well just do it through the system settings myself anyway.

        I have also found batch files that will give the output of the ip address, and put it into a nifty little .txt file, not one that will read it, and do something based upon what it reads.

        Sorry for any misunderstanding.

        For some reason when I first came to this site, the networking forums were all I could see, so I bookmarked the general one to go back to after registration. I have discovered a dedicated scripting one now, as it seems to be more relevant, should I repost there, or can this be moved?
        Last edited by sblade; 7th June 2008, 16:08. Reason: added last paragraph

        Comment


        • #5
          Re: how do I write a script to change computer description & computer name on windows

          No your asking for a script and we have a scripting forum.
          I've requested the admins/forum mods to move this to the scripting forum.
          Marcel
          Technical Consultant
          Netherlands
          http://www.phetios.com
          http://blog.nessus.nl

          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
          "No matter how secure, there is always the human factor."

          "Enjoy life today, tomorrow may never come."
          "If you're going through hell, keep going. ~Winston Churchill"

          Comment


          • #6
            Re: how do I write a script to change computer description & computer name on windows

            Thank you very much.

            Comment


            • #7
              Re: how do I write a script to change computer description & computer name on windows

              Moved to scripting forum.
              Regards,
              Jeremy

              Network Consultant/Engineer
              Baltimore - Washington area and beyond
              www.gma-cpa.com

              Comment


              • #8
                Re: how do I write a script to change computer description & computer name on windows

                I found this by doing a Google:

                Code:
                List IP Addresses for a Computer 
                
                Returns the IP address for each IP-enabled network adapter installed in a computer. 
                
                strComputer = "."
                Set objWMIService = GetObject("winmgmts:" _
                    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                
                Set IPConfigSet = objWMIService.ExecQuery _
                    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
                 
                For Each IPConfig in IPConfigSet
                    If Not IsNull(IPConfig.IPAddress) Then 
                        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
                            WScript.Echo IPConfig.IPAddress(i)
                        Next
                    End If
                Next
                In conjunction with the other google search I posted earlier, you can join the scripts together to achieve what you want. I hope this points you in the right direction. We're here to help, and hopefully you'll learn a bit if you're not spoonfed a script, if you can bolt together stuff for yourself, you'll find it all the more rewarding and useful. In this instance, a bit of Googling was all that was required, my friend. Hope your cafe does well.
                Best wishes,
                PaulH.
                MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008

                Comment


                • #9
                  Re: how do I write a script to change computer description & computer name on windows

                  Originally posted by sblade View Post
                  Preference would be a batch file, as there are some other files for the games that need to be modified
                  Hi Dan,
                  I assume the computers are not clients in a domain?

                  You could make a list (text file) containing all the IP-addresses, with per Ip address the new name and new description for this computer. Make it a 'tab_separated_values' list.

                  example file [IP2Description.txt]:
                  Code:
                  ActiveIPaddres	newComputername	newDescription
                  --------------	---------------	------------------------------------------------------
                  192.168.10.4	Compnumber4	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                  192.168.10.5	Compnumber5	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                  192.168.10.6	Compnumber6	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                  192.168.10.7	Compnumber7	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                   ...
                  ect. ~
                  This file can be stored in a central share on the network. (tthe extra variables that are used in this sample file, to create a description, are optional, see also OPTIONAL in de batch below. Instead you can also enter a description string in this text file).


                  The batch must be executed by a user that is member of the local group administrators.
                  Code:
                  @echo off
                  
                  SET "RefFile=unc\folder\IP2Description.txt" ('tab_separated_values' file)
                  IF NOT Exist "%RefFile%" (echo.not found %RefFile% &GoTo:EOF)
                  
                  :: Current Computer Name: %Computername%
                  
                  :: Determine Active IP Address
                  ::--------------------------------------------------------
                   For /f "tokens=2 delims=[]" %%! in (
                    'ping.exe -n 1 %computername%') Do (
                    SET "strIP=%%!"
                   )
                  
                  :: LOOKUP IP in RefFile, (note, Delims is <tab> )
                  ::--------------------------------------------------------
                   for /f "tokens=2* Delims=	" %%a in (
                    'Find.exe "%strIP%" "%RefFile%" 2^>nul') do (
                    SET "newcomputername=%%a"
                    SET "newDescription=%%b"
                   )
                  
                  
                  ::---[OPTIONAL]-----------------------------------------------------------------------------------
                  :: Use WMIC to retrieve WORKGROUP/DOMAINNAME
                   FOR /F "skip=2 tokens=2-4 delims=," %%A IN (
                    'WMIC.exe Path Win32_ComputerSystem Get Domain^,PartOfDomain^,Workgroup /Format:csv') DO (
                    If /i [%%B]==[True] (
                      (SET _NetwName=%%A&SET _NetwType=DOMAIN)
                    ) else (
                      (SET _NetwName=%%C&SET _NetwType=WORKGROUP)
                    )
                   )
                  
                  :: EXPAND variables that were used in newDiscription
                  For /f "delims=" %%! in ('echo.%newDescription%') do SET "newDescription=%%!
                  
                  :: OPTIONAL2, ADD/Update variables to currentUser's environment
                   rem (SETX "_NetwName" "%_NetwName%")
                   rem (SETX "_NetwType" "%_NetwType%")
                  ::---[/]------------------------------------------------------------------------------------------
                  
                  
                  IF DEFINED newcomputername (
                   IF NOT [%Computername%]==[%newcomputername%] (
                    :: *Change Computer Description
                    reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /f /v "srvcomment" /d "%newDescription%"
                    :: *Change Computer Name
                    reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /f /v "ComputerName" /d "%newcomputername%"
                    reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /f /v "ComputerName" /d "%newcomputername%"
                    reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "Hostname" /d "%newcomputername%"
                    reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "NV Hostname" /d "%newcomputername%"
                    :: *Reboot
                    Shutdown.exe -r -t 0
                   )
                  ) ELSE ((echo.&echo.%strIP%	%computername%	undefined computer!)>>"%RefFile%")
                  
                  :End
                  If the list and the batch are in the same directory (or in a "subfolder\" of the script's directory) then you can use this for a path:
                  SET "RefFile=%~dp0IP2Description.txt" (Where %~dp0 will expand the actual "path\" of the batchfile)
                  IF NOT Exist "%RefFile%" (echo.not found %RefFile% &GoTo:EOF)




                  Other tools to change the Computername:
                  - Netdom.exe
                  - WMIC.exe


                  I have not tested this batch yet!

                  \Rems


                  EDIT
                  here is and other thread about changing the computer's description: http://forums.petri.com/showthread.php?t=24425
                  There you can find a vbscript that change AND update the description on the local computer (w/out reboot) .
                  -=AND=-
                  There is a vbscript that change the computer discription in Active Directory.

                  .
                  Last edited by Rems; 13th June 2008, 23:57.

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: how do I write a script to change computer description &amp; computer name on windows

                    http://www.msfn.org/board/Renaming-c...r-t119224.html

                    This guy seems to have an idea as well, not sure if it is relevant to this situation though.
                    cheers
                    Andy

                    Please read this before you post:


                    Quis custodiet ipsos custodes?

                    Comment


                    • #11
                      Re: how do I write a script to change computer description &amp; computer name on windows

                      you can use a programme called reshack, google it if you want, but you have to use regedit to make it effective though
                      MY COMPUTER SPECS:
                      Laptop:
                      1.6GHz Intel Celeron, Overclocked to 2GHz
                      1GB RAM
                      40GB HDD
                      128MB Intel Graphics
                      3x USBs
                      Desktop:
                      3GHz AMD Phenom x3 (overclocked)
                      4GB RAM
                      2X 500GB HDDs
                      a 512MB ATi Radeon of some description (cant remember lol)
                      X - Fi Soundblaster pro sound card
                      5X Cold Cathode Case Lights
                      12X USBs

                      Comment


                      • #12
                        Re: how do I write a script to change computer description &amp; computer name on windows

                        Originally posted by Rems View Post
                        Hi Dan,
                        I assume the computers are not clients in a domain?

                        You could make a list (text file) containing all the IP-addresses, with per Ip address the new name and new description for this computer. Make it a 'tab_separated_values' list.

                        example file [IP2Description.txt]:
                        Code:
                        ActiveIPaddres	newComputername	newDescription
                        --------------	---------------	------------------------------------------------------
                        192.168.10.4	Compnumber4	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                        192.168.10.5	Compnumber5	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                        192.168.10.6	Compnumber6	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                        192.168.10.7	Compnumber7	%newComputerName% [%strIP%] in %_NetwType% %_NetwName%
                         ...
                        ect. ~
                        This file can be stored in a central share on the network. (tthe extra variables that are used in this sample file, to create a description, are optional, see also OPTIONAL in de batch below. Instead you can also enter a description string in this text file).


                        The batch must be executed by a user that is member of the local group administrators.
                        Code:
                        @echo off
                        
                        SET "RefFile=unc\folder\IP2Description.txt" ('tab_separated_values' file)
                        IF NOT Exist "%RefFile%" (echo.not found %RefFile% &GoTo:EOF)
                        
                        :: Current Computer Name: %Computername%
                        
                        :: Determine Active IP Address
                        ::--------------------------------------------------------
                         For /f "tokens=2 delims=[]" %%! in (
                          'ping.exe -n 1 %computername%') Do (
                          SET "strIP=%%!"
                         )
                        
                        :: LOOKUP IP in RefFile, (note, Delims is <tab> )
                        ::--------------------------------------------------------
                         for /f "tokens=2* Delims=	" %%a in (
                          'Find.exe "%strIP%" "%RefFile%" 2^>nul') do (
                          SET "newcomputername=%%a"
                          SET "newDescription=%%b"
                         )
                        
                        
                        ::---[OPTIONAL]-----------------------------------------------------------------------------------
                        :: Use WMIC to retrieve WORKGROUP/DOMAINNAME
                         FOR /F "skip=2 tokens=2-4 delims=," %%A IN (
                          'WMIC.exe Path Win32_ComputerSystem Get Domain^,PartOfDomain^,Workgroup /Format:csv') DO (
                          If /i [%%B]==[True] (
                            (SET _NetwName=%%A&SET _NetwType=DOMAIN)
                          ) else (
                            (SET _NetwName=%%C&SET _NetwType=WORKGROUP)
                          )
                         )
                        
                        :: EXPAND variables that were used in newDiscription
                        For /f "delims=" %%! in ('echo.%newDescription%') do SET "newDescription=%%!
                        
                        :: OPTIONAL2, ADD/Update variables to currentUser's environment
                         rem (SETX "_NetwName" "%_NetwName%")
                         rem (SETX "_NetwType" "%_NetwType%")
                        ::---[/]------------------------------------------------------------------------------------------
                        
                        
                        IF DEFINED newcomputername (
                         IF NOT [%Computername%]==[%newcomputername%] (
                          :: *Change Computer Description
                          reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /f /v "srvcomment" /d "%newDescription%"
                          :: *Change Computer Name
                          reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /f /v "ComputerName" /d "%newcomputername%"
                          reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /f /v "ComputerName" /d "%newcomputername%"
                          reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "Hostname" /d "%newcomputername%"
                          reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "NV Hostname" /d "%newcomputername%"
                          :: *Reboot
                          Shutdown.exe -r -t 0
                         )
                        ) ELSE ((echo.&echo.%strIP%	%computername%	undefined computer!)>>"%RefFile%")
                        
                        :End
                        If the list and the batch are in the same directory (or in a "subfolder\" of the script's directory) then you can use this for a path:
                        SET "RefFile=%~dp0IP2Description.txt" (Where %~dp0 will expand the actual "path\" of the batchfile)
                        IF NOT Exist "%RefFile%" (echo.not found %RefFile% &GoTo:EOF)




                        Other tools to change the Computername:
                        - Netdom.exe
                        - WMIC.exe


                        I have not tested this batch yet!

                        \Rems
                        .
                        Thanks I was looking for something similiar to this. Is there any way to use the mac instead of the IP address? I did a search on google to try and find a mac script but did not find anthing (I dont know squat about scripting but am willing to learn)

                        Thanks

                        Comment


                        • #13
                          Re: how do I write a script to change computer description &amp; computer name on windows

                          Originally posted by IBMGeeK View Post
                          Thanks I was looking for something similiar to this. Is there any way to use the mac instead of the IP address? I did a search on google to try and find a mac script but did not find anthing (I dont know squat about scripting but am willing to learn)

                          Thanks

                          Replace
                          Code:
                          :: Determine Active IP Address
                          ::--------------------------------------------------------
                           For /f "tokens=2 delims=[]" %%! in (
                            'ping.exe -n 1 %computername%') Do (
                            SET "strIP=%%!"
                           )
                          :: LOOKUP IP in RefFile, (note, Delims is <tab> )
                          ::--------------------------------------------------------
                           for /f "tokens=2* Delims=	" %%a in (
                            'Find.exe "%strIP%" "%RefFile%" 2^>nul') do (
                            SET "newcomputername=%%a"
                            SET "newDescription=%%b"
                           )
                          to
                          Code:
                          :: Determine Active MAC Address
                          ::--------------------------------------------------------
                           For /f "tokens=1" %%! in (
                            'GetMac.exe ^| Find/i "\Device\TcpIp_{"') Do (
                            SET "strMAC=%%!"
                           )
                          :: LOOKUP MAC in RefFile, (note, Delims is <tab> )
                          ::--------------------------------------------------------
                           for /f "tokens=2* Delims=	" %%a in (
                            'Find.exe /i "%strMAC%" "%RefFile%" 2^>nul') do (
                            SET "newcomputername=%%a"
                            SET "newDescription=%%b"
                           )
                          Then replace %strIP% on also on one other place in the batch to %strMAC%

                          next,
                          Adjust the first column in the file IP2Description.txt
                          if you also like to rename the name of that file, don't forget to change the name also in the batch. . .:
                          SET "RefFile=unc\folder\IP2Description.txt" ('tab_separated_values' file)




                          \Rems
                          Last edited by Rems; 11th July 2008, 22:31.

                          This posting is provided "AS IS" with no warranties, and confers no rights.

                          __________________

                          ** Remember to give credit where credit's due **
                          and leave Reputation Points for meaningful posts

                          Comment


                          • #14
                            Re: how do I write a script to change computer description &amp; computer name on windows

                            Thanks so much. Im going to try it and let you know if it works.

                            Comment


                            • #15
                              Re: how do I write a script to change computer description &amp; computer name on windows

                              notice that I have changed the above script a bit, to exclude the possibility of disabled NICs (wl) besites the one active NIC.

                              But still there is one problem in case the machine has more than one Mac address present (multiple active NICs) !!! The script as it is now will still check only the last MAC address that was returned if that one is present in the file.

                              To solve this - the batch should be adjusted just a bit more. It should look up EVERY Mac address that was found - to check whether it is listed in the text file or not.

                              If I can find the time this weekend - I will try to improve the batch.


                              \Rems


                              -= EDIT =-

                              Here is wat I have changed:

                              Replace
                              Code:
                              :: Determine Active MAC Address
                              ::--------------------------------------------------------
                               For /f "tokens=1" %%! in (
                                'GetMac.exe ^| Find/i "\Device\TcpIp_{"') Do (
                                SET "strMAC=%%!"
                               )
                              :: LOOKUP MAC in RefFile, (note, Delims is <tab> )
                              ::--------------------------------------------------------
                               for /f "tokens=2* Delims=	" %%a in (
                                'Find.exe /i "%strMAC%" "%RefFile%" 2^>nul') do (
                                SET "newcomputername=%%a"
                                SET "newDescription=%%b"
                               )
                              for
                              Code:
                              :: Determine Active MAC Address(es), 
                              ::                             and Lookup EACH in RefFile
                              ::--------------------------------------------------------
                               For /f "tokens=1" %%! in (
                                'GetMac.exe ^| Find/i "\Device\TcpIp_{"'
                                ) Do (
                                  For /f "tokens=2* Delims=	" %%a in (
                                   'Find.exe /i "%%!" "%RefFile%" 2^>nul'
                                   ) do (
                                     SET "newcomputername=%%a"
                                     SET "newDescription=%%b"
                                  )
                               )
                              Now every MAC address found on the machine will be checked if it exists in the text file.
                              Last edited by Rems; 11th July 2008, 22:55.

                              This posting is provided "AS IS" with no warranties, and confers no rights.

                              __________________

                              ** Remember to give credit where credit's due **
                              and leave Reputation Points for meaningful posts

                              Comment

                              Working...
                              X