1

I am deleting log files >= 2 days old on a server with the following code:

        'Iterate through all files in specified path
        For Each file As IO.FileInfo In New IO.DirectoryInfo(sDirPath).GetFiles(sFileType)

            'Delete all log files 2 days old or older
            If (Now - file.CreationTime).Days >= iNumDays Then
                file.Delete()
            End If

        Next

This code works find on a regular windows machine. On the server, it is setup to query the user for Administrative permissions and click continue to delete the file. I have admin rights on the server. My question is, how do you "click Continue" in code when the file.Delete method is executed?

KenZ
  • 49
  • 10

1 Answers1

1

Hope these are useful:

Community
  • 1
  • 1
Deja Vu
  • 413
  • 3
  • 6
  • It's a great workaround. But I need to run this as an automated task each day. – KenZ Apr 17 '14 at 14:05
  • Why don't you make it as 'Windows Service' and run it using`LocalSystem` account, this will solve you issue. – Deja Vu Apr 17 '14 at 14:33
  • I ended up using scheduler and created the elevated shortcut as suggested. It worked as advertised. – KenZ May 02 '14 at 19:20