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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with code 1

Status
Not open for further replies.

jono261970

Programmer
Jun 28, 2002
182
GB
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 by pressing F8 and run a simple registry import from floppy.

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
 
I'm not a win programmer so there are probably better ways to do this but this works on my win98 machine. I don't know
if you need the reg patch file to look exactly like what you've posted or not, in any case you should be able to play with the idea. Some lines were too long for the forum
formatting, keep this in mind.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define fpath &quot;c:\\update.reg&quot;
#define hdr &quot;[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName]&quot;

char prewrite[15] = &quot;ComputerName=&quot;;


int main(void) {
FILE *fd;
char bbuf[50];
char *ppt;
         printf(&quot;Host name for write to reg-patch file(?): &quot;);
		 fgets(bbuf,50,stdin);
		   if (!strlen(bbuf)) {
				 printf(&quot;Cannot write an empty hostname to regfile\n&quot;);
				 return 1;
		   } else {
			     if ( (fd = fopen(fpath,&quot;a&quot;)) != NULL) {
					   ppt = malloc(strlen(bbuf) + 15 * sizeof(char));
					   ppt = strcat(prewrite,bbuf);
					   fprintf(fd,&quot;%s\n%s\n&quot;,hdr,ppt);
					   fclose(fd);
					   printf(&quot;Done with %s\n&quot;, fpath);
					   return 0;
				  }

				  printf(&quot;Error: opening %10s\n&quot;,fpath);
				  return 1;
		   }
}
 
Hello,

Thanks for your reply. Sorry for appearing dense but how do I compile or put the above code into a file?

I need this code to work in DOS and not in windows. I have to modify the workstation name before it boots into windows.

Would it be possible to send me the file?

Many thanks for taking the time to reply.

Jono

jono1970@aol.com
 
execute batch file by &quot;mainF computerName&quot;
note: remove &quot;rem&quot; to run scanreg & del

mainF.bat contains:
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] > update.reg
echo &quot;ComputerName&quot;=&quot;%1&quot; >> update.reg
rem scanreg update.reg
rem del update.reg
talk is nothing, get it done is everything...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top