Bradman Posted January 24, 2007 Share Posted January 24, 2007 I have some systems we use in a classroom at work and we need to every so often delete the student profiles. I understand how to delete a single directory but how would you do it without deleting the All User, Administrator or any other account you wanted to keep? ( I am fairly new to this so I don't have alot of knowlege). TY Link to comment Share on other sites More sharing options...
Bradman Posted January 24, 2007 Author Share Posted January 24, 2007 I have some systems we use in a classroom at work and we need to every so often delete the student profiles. I understand how to delete a single directory but how would you do it without deleting the All User, Administrator or any other account you wanted to keep? ( I am fairly new to this so I don't have alot of knowlege).TYI have gotten this far, but not sure what to do from here?Run('explorer /select, C:\Documents and Settings\All Users'); This would show the folders!DirRemove("C:\Documents and Settings", 1) ; This would delete all the sub-folders and files ! How would you search and keep only the directories you want? Link to comment Share on other sites More sharing options...
Psibernetic Posted January 24, 2007 Share Posted January 24, 2007 (edited) Using Command Prompt, this command works Net User $UserName \delete that would delete the user $UserName's profile so to add that to auto it look up the RunWait function in the helpfile Edited January 24, 2007 by Psibernetic [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
chiners_68 Posted January 24, 2007 Share Posted January 24, 2007 for deleting profiles you want to use Delprof.exe from microsoft. it basically will renmove all profiles bar the lofgged in account & alluser & default user profiles. you can also set it to only delete profiles older than a specified no. of days. if there is profiles you need to keep that i have not mentioned then you have to hide them before running Delprof.exe. i have written a little cleanup script for PC's & removing the profiles is part of that. ;******************************************************************************* ;Remove User Profiles ;******************************************************************************* Run("\\server\Software\OS\Windows XP\DelProf\Delprof.exe") winwait("\\server\Software\OS\Windows XP\DelProf\Delprof.exe") Send("y") Send("{ENTER}") winwaitclose("\\server\Software\OS\Windows XP\DelProf\Delprof.exe") Link to comment Share on other sites More sharing options...
Psibernetic Posted January 24, 2007 Share Posted January 24, 2007 incase you wish to take Chiners method, here is a link so u can download DelProf.exe considering it isn't shipped with XP DelProf.exe is here: http://www.microsoft.com/downloads/details...;displaylang=enDocumentation is here: http://webtools.live2support.com/windows/delprof.php [sup]Psibernetic[/sup]My Creations:X-HideSecuracy Link to comment Share on other sites More sharing options...
ptrex Posted January 24, 2007 Share Posted January 24, 2007 (edited) @Psibernetic Maybe this can get you going. Use it on you own risk !! expandcollapse popup#include <date.au3> $strComputer = "." $today = _NowDate () Const $ForAppending = 8 $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colSubfolders = $objWMIService.ExecQuery _ ("ASSOCIATORS $OF {Win32_Directory.Name=;C:\Documents and Settings;} " _ & "WHERE AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") ; & $objfso = ObjCreate("Scripting.Filesystemobject") $objFile = $objfso.OpenTextFile("C:\profilelog.txt", $ForAppending) $objFile.writeline ("Computer Name: " & $strComputer ) $objFile.writeline (" " ) For $objFolder in $colSubfolders $lastm=_DateDiff("d",WMIDateStringTODate ($objFolder.LastModified),$today) $objFile.WriteLine ("The Profile: " & $objFolder.name & " ) $was $last $accessed: " & $lastm &" $days ago" $proname=$objFolder.name $res=IsNumber(StringRight($proname,5)) If $res = 1 Then $objFile.WriteLine ( "Profile is a studentes" ) If $lastm > 365 Then $objFile.WriteLine ( $objFolder.name & " is ) $older $the 1 year $it $will $be $deleted " ; $objFolder.Delete EndIf EndIf $objFile.writeline (" " ) Next Consolewrite("All Profiles Checked" ) $objFile.Close () Func WMIDateStringToDate($dtmDate) Local $Return $Return = CDate(StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) & " ") Return $Return EndFunc regards, ptrex Edited January 24, 2007 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Bradman Posted January 24, 2007 Author Share Posted January 24, 2007 Hey everyone, thank you for the reply! I will give it a shot. Thanks, Bradman Link to comment Share on other sites More sharing options...
Bradman Posted February 2, 2007 Author Share Posted February 2, 2007 Hey, I have tried to get the DELPROF from Microsoft to run remotely, and I am not sure what I have been doing wrong!Here is what I have so far.My goal is to read from a text file that has the computer names on it.I need the script to read from the first line and turn that comp name into a variable to be put in the remote path soforth with each additional line.I need the script to try and run each computer name and have some kind of error control.Here is what I have so far. All I get is the message box that pops and says the script did not run. I think my syntax is messed up and i am not quite sure how to read from a file AND convert to a variable. Any help or sugestions would be nice.$g_szVersion = "My Script 1.1"If WinExists($g_szVersion) Then Exit AutoItWinSetTitle($g_szVersion)Opt("WinWaitDelay",100)Opt("WinTitleMatchMode",4)Opt("WinDetectHiddenText",1)Opt("MouseCoordMode",0)Opt("RunErrorsFatal", 0)HotKeySet("^!x", "MyExit")RunAsSet("administrator", @ComputerName, "password") Run(@COMSPEC & " /c Start c:\delprof /p /c:\\computername") Run("delprof.exe /p /c:\\computername", "",@SW_MAXIMIZE)If @error Then MsgBox(16, 'WARNING', 'DELPROF.EXE DID NOT RUN!',5)RunAsSet()Func MyExit() Exit EndFuncI am not sure of the syntax for the run! I plan on recording the windows so I can set delays and create a log function. I figured out how to make a log file by using IF WinExists Then.....Thanks to everyone for the help!FromBradman the NOOB! Link to comment Share on other sites More sharing options...
Bradman Posted February 2, 2007 Author Share Posted February 2, 2007 Maybe I am not clear on what I need. I have 21 systems in a classroom environment. I need to periodically delete all the user profiles. I want to do this remotely from one machine. I want to have the script do the following: 1. Log onto each machine to run the Delete Profile from Microsoft. I am having problems with the proper syntax for the network path thats why you see 3 different Run statements in the pervious post. 2. The script needs to read the PC name from a TXT file and write the name in the network path. I know how to open a file and write but not how to read and pass the info off to the network path. 3. I can figure out the basic logging function. I will use the (If WinExists Then Open File Write ) functions to write to a txt file. 4. I am also not familiar with the Loop Until function. This would be nice if the machine is slow to respond. I do not need some one to write the script for me I just need good examples on how to do certain things. I just want to say I see allot of very talented people here that really know how to script and I know that one day I will have the skills to help others here on the Forums. I just started a little over a month ago and I have learned so much. I want to thank those that take their time here on the Forums to help others. Link to comment Share on other sites More sharing options...
Bradman Posted February 2, 2007 Author Share Posted February 2, 2007 Here is the Command options for DELPROF. I am still having problems with the syntax. I am not sure if it is from the network/security side or if I just messed up the script. DELPROF Delete NT user profiles. Syntax DELPROF [options] Key /Q Quiet, no confirmation. /I Ignore errors and continue deleting. /P Prompts for confirmation before deleting each profile. /C:\\computer_name Delete profiles on a remote computer. /D:Number_of_days Only delete profiles that have been inactive for 'X' Number of days (or greater) /R Delete roaming profile cache only ## Link to comment Share on other sites More sharing options...
Recommended Posts