Solved Write to registry by checking a file

September 28, 2012 at 04:54:40
Specs: Windows 7, P4Dual Core 3Ghz/4GB RAM
Hello,

I'm having a csv file (for instance)

192.168.3.132,LC03-132,User A,11-04-2011
192.168.3.133,LC03-133,User B,02-05-2011
192.168.4.109,LC04-109,User C,26-10-2011
192.168.5.143,LC05-143,User D,02-05-2010

This file contains IP-address, PC name, User and start date of the warranty. The goal is to create a batch file (being launched from my pc) thakes the first line, tries to ping that machine, if it responds, write the date into the registry and then goes to pinging the following and so on.
If there isn't any response to the ping, it should continue to the following line. Is there a way to doe this by a batch file?

Jvuz


See More: Write to registry by checking a file

Report •


✔ Best Answer
September 29, 2012 at 08:37:31
You kidding me? first you talk crap out of your backside, not explaining thoroughly and you've got a 90% working script in front of you and you say nothing?
This will do the job.
@echo off & setlocal enabledelayedexpansion
set Counter=1
for /f %%x in (%userprofile%\desktop\info.txt) do (
set "Line_!Counter!=%%x"
set /a Counter+=1
)
set /a NumLines=Counter - 1
set limit=0
set /A counter -=1
:LOOP
set /A limit +=1
set ipaddress=!Line_%limit%:~0,13!
ping -n 1 %ipaddress% > nul 2>&1
if not errorlevel 1 (
echo Windows Registry Editor Version 5.00
echo [HKEY_CURRENT_USER\Info]
echo "Machine Number %limit%"="!Line_%limit%:~0,-10!"
)> %tmp%\info.reg
regedit.exe /s %tmp%\info.reg
if "%limit%"=="%counter%" del %tmp%\info.reg & exit
Goto :LOOP

Use the following commands to your preference.
\\Servername\public\PsExec.exe \\127.0.0.1 -u Admin -p Password regedit /s \\Servername\public\Test.reg


#1
September 28, 2012 at 05:52:47
This could be done using the REG command, or perhaps with WMIC's StdRegProv class

When your only tool is a hammer, every problem looks like a nail.


Report •

#2
September 28, 2012 at 06:56:51
"The registry" is an awfully big place. Why don't you just write the results to a file?

How To Ask Questions The Smart Way


Report •

#3
September 28, 2012 at 22:35:46
I'm gonna write to the pc's registry. The goal is to ping to the first line (192.168.3.132), if it answers, I'm gonna use psexec to write the date for that machine to its registry.
The problem I'm having is how to check by line. Doing the writing to the regditry itsef I know how to do (I think)

Report •

Related Solutions

#4
September 28, 2012 at 23:43:44
Here just finished and tested, it works
@echo off & setlocal enabledelayedexpansion
set Counter=1
for /f %%x in (%userprofile%\desktop\info.txt) do (
set "Line_!Counter!=%%x"
set /a Counter+=1
)
set /a NumLines=Counter - 1
set limit=0
set /A counter -=1
:LOOP
set /A limit +=1
set ipaddress=!Line_%limit%:~0,13!
ping -n 1 %ipaddress% > nul 2>&1
if not errorlevel 1 (
echo Windows Registry Editor Version 5.00
echo [HKEY_CURRENT_USER\Info]
echo "Machine Number %limit%"="!Line_%limit%!"
)> %tmp%\info.reg
regedit.exe /s %tmp%\info.reg
if "%limit%"=="%counter%" del %tmp%\info.reg & exit
Goto :LOOP

Just noticed you want to write to the remote registry, so use this instead and modify to your preference:
\\Servername\public\PsExec.exe \\127.0.0.1 -u Admin -p Password regedit /s \\Servername\public\Test.reg
I've never used psexec so i can't help any further.


Report •

#5
September 29, 2012 at 03:56:01
You seem awfully convinced the registry will solve all your problems, but you don't tell us your problem, or how you think this'll solve it.

How To Ask Questions The Smart Way


Report •

#6
September 29, 2012 at 06:49:47
Sorry,

this is the situation: our company allows regular users to have admin rights (not my choice, just to be clear ;) ) and now they created SLA's with these rules:
Golden support: every computer not older then 3 years AND nobody else then local admin and domain admin are in the list of the local admins.
Silver support: every computer not older the n 3 years AND not only local admins and domain admins are in the local admin list. Silver support is also for pc's with the age between 3 and 7 years
Limited: every computer older then 7 years.

Now I already wrote a script that sets the local admins list into the registry. I also have a key in the registry that has no (one or more regular users have admin rights) or yes (only the (local and domain) admins are in the local admin list). This is done by the logon script.

Now is the goal of this script to fill in on every pc its warranty start date. Another script will be to check which support it will get and write that into the registry. We also use GLPI in cooperation with OCSNG, where I can set to check registry keys. That way I'll have this info for every pc.

I knwo it's a bit complicated, but if someone knows and works with GLPI and knows another way to accomplish this, you're all welcome to help me.

Jvuz


Report •

#7
September 29, 2012 at 08:37:31
✔ Best Answer
You kidding me? first you talk crap out of your backside, not explaining thoroughly and you've got a 90% working script in front of you and you say nothing?
This will do the job.
@echo off & setlocal enabledelayedexpansion
set Counter=1
for /f %%x in (%userprofile%\desktop\info.txt) do (
set "Line_!Counter!=%%x"
set /a Counter+=1
)
set /a NumLines=Counter - 1
set limit=0
set /A counter -=1
:LOOP
set /A limit +=1
set ipaddress=!Line_%limit%:~0,13!
ping -n 1 %ipaddress% > nul 2>&1
if not errorlevel 1 (
echo Windows Registry Editor Version 5.00
echo [HKEY_CURRENT_USER\Info]
echo "Machine Number %limit%"="!Line_%limit%:~0,-10!"
)> %tmp%\info.reg
regedit.exe /s %tmp%\info.reg
if "%limit%"=="%counter%" del %tmp%\info.reg & exit
Goto :LOOP

Use the following commands to your preference.
\\Servername\public\PsExec.exe \\127.0.0.1 -u Admin -p Password regedit /s \\Servername\public\Test.reg

Report •

#8
September 29, 2012 at 14:16:08
Assuming you can tell the age of the PC by when its OS was installed, you could just check WMI's Win32_OperatingSystem.InstallDate and avoid this whole exercise, or at least change it into a quick startup script.

How To Ask Questions The Smart Way


Report •


Ask Question