Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need some help on batch file

Status
Not open for further replies.

jono261970

Programmer
Jun 28, 2002
182
0
0
GB
Hello,

We have a computer suite of 40 win98 workstations and use drive image to deploy an image to all machines in one sweep. Works fine except I have to change the ID of each machine individually or there's trouble.
I boot into DOS and run a simple registry import.

I exported the following registry file and saved it as update.reg. I then type "regedit update.reg" and it updates the machine's ID before I boot it up.

-----------------------------------------------------------
Inside update.reg file:-

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]
"ComputerName"="W13-1"
----------------------------------------------------------
The only problem is I have to either have 40 unique disks or keep on editing the "computer name" part for each computer.

What I would like is a dos program that would ask me to type in the computer name and then change the computer name for me. Ok, I am finding this hard to explain :O)
This is what I want to do:-

please enter name?
input name$
Then the contents of name$ go into the update.reg file below:-

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]
"ComputerName"=name$

I hope somebody can understand what I need.

Thanks in advance

jono


 
Hi,

If you want the program to work from the DOS promt - VB is not the right language (VC++ or any .net laugaunge would be easier). If it is ok for the program to be a windows prog then its easy from vb.

----------------------------
Private Sub Command1_Click()
'place a command button and a textbox on a form
Dim f As Byte, pcname As String
f = FreeFile
Open "c:\yourfilename.reg" For Output As #f
Print #f, "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]"
Print #f, "ComputerName = " & Text1.Text
Close #f
' here you could use shell to start the deployment of the image
End Sub
---------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
This may help but to avoid using a windows program try the following, cant remember 98 but XP provides lots of good command line options for most commands.

Single bas file in the project.
Sub main is something like the following

Sub Main
Dim S as String
while s <> &quot;&quot;
s = inputbox$(&quot;Enter Computer Name&quot;)
wend
'print code from sunaj example using s instead of text1.text
end sub

In the batch file then add the line (The start is important)
START /WAIT program1.exe

without the wait switch the batch file will just continue running even though the vb program hasn't ended so hopefully 98 supports WAIT.
 
After your image is loaded and before rebooting, you should be able to run &quot;ghstwalk.exe /CN=[computer name]&quot;. If your version of Ghost has those commands available then the following may help...

--------
@echo off
::INPUT.BAT
::Stores user input in environment variable INPUT.
cls
echo.
echo.
echo Enter cubical number:
echo.
fc con nul /lb1 /n | date | find &quot;1:&quot; > en_er.bat
echo set input=> enter.bat
echo :loop>> enter.bat
echo if not &quot;%%input%%&quot;==&quot;&quot; set input=%%input%% %%5>> enter.bat
echo if &quot;%%input%%&quot;==&quot;&quot; set input=%%5>> enter.bat
echo shift>> enter.bat
echo if not &quot;%%5&quot;==&quot;&quot; goto loop>> enter.bat
call en_er.bat
del en?er.bat

----------

That batch file requires FC.EXE and FIND.EXE which are DOS commands and should be in C:\Windows\Command on a Win9x system. Once you verify the input variable is populating with what you enter, then you can run the following command for ghost to update the Computer Name...

ghstwalk.exe /CN=%INPUT% /BV=1:1 /SURE /IGNORE_DOMAIN /IGNORE_ENCRYPTFILES


I suppose you could also do the following after the input variable is set:

echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] > update.reg

echo &quot;ComputerName&quot;=&quot;%input%&quot; >>update.reg

regedit update.reg
 
Thanks for the reply but I am using Drive Image and not Ghost. Drive image does have a sysprep program but it only works for win 2000/NT.

jono
 
The following requires FC.EXE and FIND.EXE which are DOS commands. You can get them from the C:\windows\command directory on a win9x system. This code is for a batch file (.bat) and must be ran on media it has write access to. It will output &quot;update.reg&quot; to the current directory with the computer name you type in at the prompt.

--begin copy below this line--
@echo off
cls
echo.
echo.
echo Enter computer name:
echo.
fc con nul /lb1 /n | date | find &quot;1:&quot; > en_er.bat
echo set input=> enter.bat
echo :loop>> enter.bat
echo if not &quot;%%input%%&quot;==&quot;&quot; set input=%%input%% %%5>> enter.bat
echo if &quot;%%input%%&quot;==&quot;&quot; set input=%%5>> enter.bat
echo shift>> enter.bat
echo if not &quot;%%5&quot;==&quot;&quot; goto loop>> enter.bat
call en_er.bat
del en?er.bat
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] > update.reg
echo &quot;ComputerName&quot;=&quot;%input%&quot; >>update.reg
--end copy above this line
 
Hello Danp129,

Wow your batch file is soooooo kewl. This is just what I need. However in order for it to work I have forgotten to point out that I need the word REGEDIT4 to be displayed above the HKEY_LOCAL_Machine statement.


REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]
&quot;ComputerName&quot;=&quot;test&quot;

I have tried various ways of doing this but keep on getting errors!
I really would appreciate it if you could help me again.

thanks kindly

jono
 
Well, a little variation here. This one has to be called 'nameme.bat'. Uses the same basic idea as the one by Danp129, the necessary information is echoed to a .reg file. This one takes the name directly from the command line as a parameter instead of messing with the CON input. Also automated the import to the registry, delete the .reg file and delete the .bat file.

rem ******** NameMe.bat *************
@echo off
cls
echo.
echo.
if &quot;%1&quot; == &quot;&quot; goto noname
echo REGEDIT4 > newname.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >> newname.reg
echo &quot;ComputerName&quot;=&quot;%1&quot; >> newname.reg
regedit /s newname.reg
del newname.reg
echo **** Computer name changed to %1 ****
pause
call del nameme.bat
:noname
echo ******************************************
echo **** You didn't give me a name !!! ****
echo ******************************************
:end
rem ********* end NameMe.bat ************

In this .bat, the %1 is the first command line parameter passed to the batch file, you would type 'nameme george' to change the computer name to 'george'. If you enter a name on the command line, the .reg file is created, imported, deleted, and then the batch file itself is deleted to keep some moron from trying to play with it later.

If you don't enter a name on the command line, you get a complaint, and the batch file stays so you can try again.

It has been . . . . well it's been quite a while since I played with batch files. You will get a message 'Batch file cannot be found' after a good run. Not a real problem, there is a way to suppress that but I can't for the life of me remember what it is. It has been a long time.

Hope this is of some use.
 
jono, here's the changed code. Mhkwood's code will also work fine, require less dos files to be available (acutually none external to command.com), and will be compatible with all versions of Windows. I'm stuck with using mine though cause it pauses my post-image batch script to let me set a variable before it runs a DOS command to update the computer name. If you decide to use my code, you should hold on to Mkhwoods' code in case you migrate to 2k/XP or higher.

--begin copy below this line--
@echo off
cls
echo.
echo.
echo Enter computer name:
echo.
fc con nul /lb1 /n | date | find &quot;1:&quot; > en_er.bat
echo set input=> enter.bat
echo :loop>> enter.bat
echo if not &quot;%%input%%&quot;==&quot;&quot; set input=%%input%% %%5>> enter.bat
echo if &quot;%%input%%&quot;==&quot;&quot; set input=%%5>> enter.bat
echo shift>> enter.bat
echo if not &quot;%%5&quot;==&quot;&quot; goto loop>> enter.bat
call en_er.bat
del en?er.bat
echo REGEDIT4 > update.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >> update.reg
echo &quot;ComputerName&quot;=&quot;%input%&quot; >>update.reg
--end copy above this line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top