Solved

how to create a batch file that adds the registry values and deletes itself?

Posted on 2007-04-09
6
542 Views
Last Modified: 2010-03-05
Hi, i am system admin for a small distributed network. i want to put the netcat in the windows but as my network is distributed it would take time , what i have thought to put the netcat in systems and remove the shared drives. so can you please tell me how can i add a batch file to system start up folder that it adds the netcat registry value to registry automatically without interaction and deletes it self with out adding registry key every time and bothering the users when the system reboots?is there any alternative solution to this please, if batch file is not a good idea?
0
Comment
Question by:shairankhan
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
herbus earned 125 total points
ID: 18875596
If I understand right, you want the batch file to be deleted after it's been run so that it doesn't keep adding the registry value, yah?

For one, it won't matter if it runs multiple times - it will just overwrite the entry each time, but it will overwrite it with the same settings, so no problem?  Best to run this from a network location, ie: via group policy, rather than having local scripts to deploy...

If for whatever reason you don't want it to run if the registry key is already in there, then I'd suggest an easy way would be to incorporate some sort of logging into the script... even if all it does is make a folder somewhere (like c:\temp\...), then when the script runs it will check for that folder - if it exists the script will quit, if not then it will add the registry values and create the folder...

ie: a simple batch file would do the log check and call on a vbs script if the registry values need to be added - example batch file below:

if exist "%userprofile%\Local Settings\Temp\regadd.log" goto end
cscript \\domaincontroller\netlogon\AddRegistryValues.vbs
md "%userprofile%\Local Settings\Temp\regadd.log"
:end

the vbs file would obviously contain the reg additions you need... ala http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/osrgvb02.mspx?mfr=true

Hope this helps,
Herb
0
 
LVL 9

Expert Comment

by:herbus
ID: 18875614
Keep in mind that the example I posted had %userprofile% variable paths, which would apply to a user login script, not a computer startup script... I'd copied it from one I use at work and forgot to change that bit... if it's a computer startup script you'd replace it with "c:\temp\regadd.log" or whatever...

...and of course you'll want to test it before deploying it network-wide via a policy or such...

Cheers,
Herb
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 18884691
Rather than coding in hard values you can use system variables %temp% instead of c:\documents and settings\%userprofile% ..
0
 
LVL 9

Expert Comment

by:herbus
ID: 19246774
G'day LeeTutor & folks,.. the recommendations for cleanup are normally spot on, but in this case I'm confident that the solution I posted is valid.  If there's no objection I'd put my hand up to claim this as answered...

Cheers,
Herb
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now