Jump to content

Recommended Posts

Posted (edited)

Hello, I'll try to explain to you my matter. I'm in BTS Informatique de Gestion (computing in simpler), and one project is to create a windows which can be installed without any user. My matter is : who increment the name of the PC with only the IP adress. Ex: If the PC have the IP : 192.168.0.5 I wanna the name PC-TEST 5, if the PC have the IP : 192.168.0.14, I wanna the name PC-TEST 14, ... . It's possible? With a script, with WPI, with nlite?

Edited by eleve

Posted (edited)
Hello, I'll try to explain to you my matter. I'm in BTS Informatique de Gestion (computing in simpler), and one project is to create a windows which can be installed without any user. My matter is : who increment the name of the PC with only the IP adress. Ex: If the PC have the IP : 192.168.0.5 I wanna the name PC-TEST 5, if the PC have the IP : 192.168.0.14, I wanna the name PC-TEST 14, ... . It's possible? With a script, with WPI, with nlite?

Using your 2 example plus I added a Local Address to confirmed it working.

How this script works is as follows

1:\ It starts with a Array that holds all your ip address

2:\ It Loops threw the Array to ping the computers

3:\ If the ping returns false nothing happens it continues threw the Array

4:\ If the ping returns true it the uses a Case Select to see what ip responded

and sets the varible called NameComputer.

I have not added any scripting to change the name of the computer. You will have

to add the ip`s to the Array Called Computer.

This script will only work ON XP and UP

Save As Ping.vbs

 Option Explicit
Dim ArrComputer, Computer, NameComputer, Pings, Status, strComputer, Wmi
strComputer = "."
'-> Array To Hold IP Addresses
Computer = Array( _
"192.168.0.5",_
"192.168.0.14",_
"127.0.0.1")
'-> Connect To WMI
Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'-> Loop To Go Threw Computer Array
For Each ArrComputer In Computer
'-> WMI Class We Used Using Array Computer
Set Pings = Wmi.ExecQuery("Select * From Win32_PingStatus where Address = '" & ArrComputer & "'")
'-> Ping Computer In The Array
For Each Status in Pings
If IsNull(Status.StatusCode) or Status.StatusCode<>0 Then
WScript.Echo "Computer did not respond."
Exit For
Else
'-> Where We Select Which IP Returned True
Select Case ArrComputer
Case "192.168.0.5"
NameComputer = "PC-TEST 5"
Case "192.168.0.14"
NameComputer = "PC-TEST 14"
Case "127.0.0.1"
NameComputer = "My Computer Test"
End Select
'-> Add A A Script Here To Change The Computer Name To NameComputer
Wscript.Echo "Computer responded." & vbtab & NameComputer
End If
Next
Next

Edited by gunsmokingman
Posted

If all you want is the last octet of the IP address, which will limit you to 256 machines you could do this very simply, as gunsmokingman showed though it could be even easier. If you are going to be doing this in a larger organization and you have DHCP and all the machines are registered so that the machine name is associated with the MAC address of the machine you could poll DNS and rename the machine according to the registered info.

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...