mikex Posted July 25, 2005 Report Share Posted July 25, 2005 (edited) I want to make a small script to delete cookies, temp, temp internet, recent, and history. I want to carry this on a thumb drive, use it to clean client machines. The user directories will be different. Can I do that?How?Made a few batch files before but nothing to brag about.MikeI want to be able to use it on different machines.Machine 1 - 2 users.C:\Documents and Settings\user1\Local Settings\HistoryC:\Documents and Settings\user1\CookiesC:\Documents and Settings\user2\Local Settings\HistoryC:\Documents and Settings\user2\Cookiesdifferent machine:C:\Documents and Settings\useA\Local Settings\HistoryC:\Documents and Settings\userA\CookiesUsers will be different, because it will be different macnines.M Edited July 25, 2005 by mikex Quote Link to post Share on other sites
shanenin Posted July 25, 2005 Report Share Posted July 25, 2005 I have only written maybe a 6 line batch script myself, but have fun trying to code :-)The user directories will be different.I am not quite following, could you give me an example Quote Link to post Share on other sites
jcl Posted July 25, 2005 Report Share Posted July 25, 2005 (edited) Sigh. I don't have access to my Windows box at the moment, unfortunately.The USERPROFILE environment variable is set to the directory of the current user profile (equivalent to %HOMEDRIVE%%HOMEPATH% if Google is correct). The location of the files should be the same for every profile, so the batch file could be structured a series ofdel %USERPROFILE%\somedirectory\filesor deltree or whatever.It's probably more complicated if you need to support both WinNT and Win9x. Edited July 25, 2005 by jcl Quote Link to post Share on other sites
mikex Posted July 25, 2005 Author Report Share Posted July 25, 2005 Thanks jcl.Could have a .bat for 9X and another for XP.I try it.M Quote Link to post Share on other sites
jcl Posted July 25, 2005 Report Share Posted July 25, 2005 Could have a .bat for 9X and another for XP.<{POST_SNAPBACK}>You can detect the operating system with, um... *googlegoogle* OS. %OS% is set to 'Windows_NT' on NT/2k/XP and not defined on 9x. The batch file can detect the system and adjust the target paths appropriately. Quote Link to post Share on other sites
shanenin Posted July 25, 2005 Report Share Posted July 25, 2005 (edited) is there a way to do command substitution with batch? for instance the output ofdir C:\documents and settings I was wanting to use that output with a for statment.for examplefor %%i in `dir C:\documents and settings` do this Edited July 25, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted July 25, 2005 Report Share Posted July 25, 2005 (edited) Yes. The syntax is something likefor /F %%i in ('dir C:\documents and settings') do ...orfor /F "usebackq" %%i in (`dir C:\documents and settings`) do ...Edit: Got my W2k machine back on the LAN. The above works but the for (or cmd.exe, or something) does automatic field splitting, so you have use set the 'delims' option if you want to whole line, like sofor /F "delims=" %%i in ('dir C:\') do echo %%ior for /F "usebackq delims=" %%i in (`dir C:\`) do echo %%i Edited July 25, 2005 by jcl Quote Link to post Share on other sites
mikex Posted July 25, 2005 Author Report Share Posted July 25, 2005 jcl i can't find "somedirectory"LOLANYWAYcan't do it, missing something.M Quote Link to post Share on other sites
shanenin Posted July 25, 2005 Report Share Posted July 25, 2005 you would for example do %HOMEDRIVE%%HOMEPATH%\Local Settings\History Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 (edited) This works. I'm not sure why it works, but it does.: Hygienesetlocal              : the value of 'targets' is a space-seperated list of paths to be mangledset targets="%USERPROFILE%\Cookies" "%USERPROFILE%\Local Settings\History" : iterate over the paths in targets, doing whatever needs to be donefor %%i in (%targets%) do mangle %%i: HygieneendlocalIf I replace 'mangle' with 'dir' I getC:\Documents and Settings\jcl\My Documents\src\batch>f.bat     Volume in drive C has no label.                    Volume Serial Number is DCAE-1139                      Directory of C:\Documents and Settings\Default User\Cookies   02/28/2005  01:13a        16,384 index.dat                   1 File(s)     16,384 bytes                         0 Dir(s)   471,162,880 bytes free              Volume in drive C has no label.                       Volume Serial Number is DCAE-1139                    Directory of C:\Documents and Settings\Default User\Local Settings\HistoryFile Not Foundwhich is almost correct, so I assume it's working. I have no idea why %USERPROFILE% is set to 'Default User'. Edited July 26, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 (edited) my thought was to use a for statment to go thru and delete the needed data for all users. Since all of the users are listed under c:\documents and settings\ I could do something like this. I was just testing this in the shell. first I am changing to the directory documents and settinds then trying thisfor %i in (*) do echo %i%it is running with out echoing anything or giving me an error. I thought one time it worked for me, but I forgot the syntax I used. I read in a doc you use %%i for scripts, but in the shell you use %i . Does my for statment look wrong?edit added//this seems to workfor /d %i in (*) do echo %i Edited July 26, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 (edited) The problem with deleting the files for all accounts is that the batch file would need to run under Administrator or another account with ridiculous privs. If that's reasonable then yeah, it can be done easily by iterating over the contents of Documents and Settings. You do have be careful to hit only the accounts that really should be cleansed. And you'll miss accounts if they don't have a profile in the usual place. Edited July 26, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 (edited) if he is making a batch script to clean customers computers, which he is going to carry on a usb drive. I would think he would be running as admin. There is still the problem of use profiles in odd spots. Edited July 26, 2005 by shanenin Quote Link to post Share on other sites
CurlingSteve Posted July 26, 2005 Report Share Posted July 26, 2005 I think you're over-complicating this.the %1 variable is all you need.If the file CLEAN.BAT has these lines:DEL C:\Documents and Settings\%1\Local Settings\History *.*DEL C:\Documents and Settings\%1\Cookies *.*Then running CLEAN USER1expands toDEL C:\Documents and Settings\USER1\Local Settings\History *.*DEL C:\Documents and Settings\USER1\Cookies *.*You will have to confirm the delete commands.(That can be automated as well). Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 He'd have to manually collect the list of accounts, invoke the batch file for each one, and hope that the profiles are all in the standard locations. At the very least I'd want the batch file to iterate over a list of usernames provided as arguments and lookup the profiles for each.This would really be much easier in VB or something. Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 (edited) .This would really be much easier in VB or something.<{POST_SNAPBACK}>batch(what ever it is called) just sucks. I don't really have anything facts to back that up with, but it fealt good to say :-) Edited July 26, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 batch(what ever it is called) just sucks.<{POST_SNAPBACK}>Yes, yes it does. Thank God Microsoft is finally killing it. Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 is the new shell officially going to be in vista? Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 is the new shell officially going to be in vista?<{POST_SNAPBACK}>Last I heard. It's actually being released before Vista, as part of Exchange Server on Win2003. There's no reason why it couldn't ship for XP as well. Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 I googled, but did not find any info on it Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 There's small section devoted it on the Channel 9 Wiki. It's really quite impressive. Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 thanks you for the link :-) Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 wow, it does sound pretty neat. Quote Link to post Share on other sites
shanenin Posted July 26, 2005 Report Share Posted July 26, 2005 from my understanding of monad, eventually a person will be able to manage there whole windows system from a command line. I am still having trouble grasping what it does. Is monad similar to bash, in the sence it is a powerful scripting language, but with oop built in. Quote Link to post Share on other sites
jcl Posted July 26, 2005 Report Share Posted July 26, 2005 Is monad similar to bash, in the sence it is a powerful scripting language, but with oop built in.<{POST_SNAPBACK}>Precisely. It's very much like a typical Unix shell, but implemented on, and hooked into, the .NET framework. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.