troubleshooting Question

GPO or logon script - Need elevate admin rights

Avatar of llarava
llaravaFlag for Afghanistan asked on
Active DirectoryMicrosoft Legacy OS
11 Comments1 Solution2869 ViewsLast Modified:

We would like to execute the following script which requires admin rights in order to work. Basically the script checks the user profiles that are created locally in the workstation and deletes the documents that are older than 1 day within the profile.

We would like to use the script as part of the logon script or via gpo and I was wondering if there is any way to elevate the rights so that script runs with admin rights and does its job?

Any help?

Thank you!
On Error Resume Next

''' Set Registry Hive
Const HKEY_LOCAL_MACHINE = &H80000002

'''  This section of code creates the list of user profiles
strComputer = "."
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
''' Create a loop to cycle through the profiles

For Each objSubkey In arrSubkeys
  strValueName = "ProfileImagePath"
  strSubPath = strKeyPath & "\" & objSubkey
  objRegistry.GetExpandedStringValue _
  strValue = strValue & "\Desktop"

''' Delete any file on desktop that is older than one day old
''' Skip the default user desktop (although this may not be necessary)

  If NOT strValue ="C:\WINDOWS\system32\config\systemprofile\Desktop" _

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strValue) Then
      Set Folder = objFSO.GetFolder(strValue)
      For Each File in Folder.Files
        If DateDiff("d",File.DateLastModified,Now) > 1 Then _
        objFSO.DeleteFile File
    End If

  End If

  Set objFSO = Nothing


Set objRegistry = Nothing

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros