Jump to content

Just seeing what I am doing wrong - (Moved)


MrX013
 Share

Go to solution Solved by MrX013,

Recommended Posts

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

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

  • Solution

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

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 by rsn
added includes and caveat about DateAdd with the MS epoch
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...