MrX013 Posted November 20, 2023 Share Posted November 20, 2023 Hi all I am new to this but I am trying to write a function to auto run Delprof2 and delete profiles 60 days old on pc names determined by a gui input delprof2.exe -u /c:\\(pc name) -d:60 this is the command in cmd prompt and this is the scripted function Func _DeleteOldProfiles() $vVariable = GuiCtrlRead ($Input1) $command = "-u /c:\\" $command1 = " -d:60" ShellExecute ("C:\Program Files\PsTools\Delprof2 1.6.0\DelProf2.exe " ,$command &$vVariable &$command1) and it keeps saying this as an error. "C:\Users\a9700172\Desktop\FEtools\V2.1 in works.au3"(241,105) : error: syntax error ShellExecute ("C:\Program Files\PsTools\Delprof2 1.6.0\DelProf2.exe " ,$command &$vVariable &$command1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\a9700172\Desktop\FEtools\V2.1 in works.au3"(241,105) : error: Statement cannot be just an expression. ShellExecute ("C:\Program Files\PsTools\Delprof2 1.6.0\DelProf2.exe " ,$command &$vVariable &$command1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Users\a9700172\Desktop\FEtools\V2.1 in works.au3 - 2 error(s), 0 warning(s) >Exit code: 2 Any help or eyes that can see what I am doing wrong would be appreciated Thanks for the help Link to comment Share on other sites More sharing options...
argumentum Posted November 20, 2023 Share Posted November 20, 2023 ...make sure the spaces are good. I'd: ConsoleWrite('>' & $command & $vVariable & $command1 & '<' & @CRLF) to see what is there Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 20, 2023 Developers Share Posted November 20, 2023 Moved to the appropriate forum. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted November 20, 2023 Share Posted November 20, 2023 Might be a bad character at the end of the statement. Just manually rewrite it. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rsn Posted November 20, 2023 Share Posted November 20, 2023 For "Statement cannot be just an expression" I suspect it's that Func _DeleteOldProfiles() doesn't have a corresponding EndFunc Side note: Since delprof2 uses the modified date of NTuser.dat to determine profile age, and certain AV clients (and WindowsUpdate occasionally) update that date, you may have trouble getting accurate reads on the actual age of the profile. Link to comment Share on other sites More sharing options...
MrX013 Posted November 20, 2023 Author Share Posted November 20, 2023 Thanks all for the help yeah I forgot the EndFunc @rsn so what if I tell it to look at the ntuser.ini file? Does that file update or change when users login? Link to comment Share on other sites More sharing options...
Solution MrX013 Posted November 20, 2023 Author Solution Share Posted November 20, 2023 It now looks like this Func _DeleteOldProfiles() $vVariable = GUICtrlRead ($Input1) $command = "/c:\\" $command1 = " -d:60 /ntuserini /ed:Admin* /i" ShellExecute ("C:\Program Files\PsTools\Delprof2 1.6.0\DelProf2.exe " ,$command &$vVariable &$command1) EndFunc Link to comment Share on other sites More sharing options...
rsn Posted November 21, 2023 Share Posted November 21, 2023 (edited) You're welcome. NTuser.ini is weird too. The example of my currently logged in PC that has been logged in since 8 November: my NTuser.dat mod date is 8 Nov 2023 and NTuser.ini is 18 Jun 2021. But a user who hasn't logged in since 20 April 2023: NTuser.dat is 16 Nov 2023 and NTuser.ini is 20 Mar 2023 If you really want to calculate the age you'll have to use values stored in the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<userSID>\LocalProfileLoadTimeHigh HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<userSID>\LocalProfileLoadTimeLow If you want to try it, combine the hex values above and then convert to decimal (use an actual SID from the registry): #include <AutoItConstants.au3> #include <Array.au3> #include <Date.au3> $sLocalProfileLoadTimeHigh = Hex(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<UserSID>" , "LocalProfileLoadTimeHigh"), 8) $sLocalProfileLoadTimeLow = Hex(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<UserSID>" , "LocalProfileLoadTimeLow") , 8) $iLocalProfileLoadTimeCombined = Dec($sLocalProfileLoadTimeHigh & $sLocalProfileLoadTimeLow, $NUMBER_64BIT) Then you'll need to convert that result to the offset date. A quick and dirty way is to use W32tm.exe (which is built into windows). $iPID = Run("w32tm /ntte " & $iLocalProfileLoadTimeCombined , "", @SW_HIDE , $STDOUT_CHILD) ProcessWaitClose($iPID) $aDateOffset = StringSplit ( StdoutRead($iPID) , " " ) Finally add that offset date to Microsoft's epoch of 01/01/1601 to get the actual date. $iDateOffset = Int($aDateOffset[1], $NUMBER_AUTO) $sLastLogin = _DateAdd("D", $iDateOffset, "1601/01/01") At this point you'll finally have the true last login date (though the help file says initial date must be after 1 Jan 2000, 1 Jan 1601 seems to work). I suppose you could do some quick date math and use delprof2 to delete the specific profile. I forget if it supports deletion by SID but I'll leave that part to you. If it doesn't, I think you can cross reference the SID to the username with the AD UDF. Don't rely on the user's name or the value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<UserSID>\ProfileImagePath since people are in the habit of getting married, divorced or whatever else might change a name. I'm hesitant to even mention this since I don't feel it's quite appropriate but I wrote my own little applet to do this kind of profile directory cleanup in AutoIt, but it's not source available. If you're interested in it, send me a PM and I'll send a link to it's home page. Edited November 21, 2023 by rsn added includes and caveat about DateAdd with the MS epoch MrX013 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now