Using the ‘forfiles.exe’ to manage log files

Here is a good tip I received in the IIS newgroups managing log files.   Thanks ‘Tomek’ for passing this along.


1) Create – BAT-File (in the same Path like forfiles.exe)
2) forfiles.exe – syntax


forfiles – pC:pathtolog-files – s -m*.* -d-60 -c”cmd /C del /q @FILE”


-m : defines the Filename and extension
-d : the age of the Files in days
-c : command to run (in our case – delete)

Joe Stagner presenting at our July 20th (GLUGnet) user group meeting.

Mark your calender, here is information about our next user group meeting!   The evolution of the Web Application User Experience with Microsoft Atlas – Web 2.0 & AJAX are  the buzzwords of the next generation of web development. This session will provide a look into Microsoft’s new Web Development technology “Atlas”. Atlas combines rich, cross browser client side libraries with ASP.NET’s  popular server side development technology to offer an ideal  developer’s toolbox for developing the next generation of Web Applications.


Speaker: Joe Stagner (http://www.joeon.net/) is a Program Manager in Microsoft Corporation’s Developer Tools and Platform Group and has been with Microsoft since 2001 focusing on highly scalable and performant web application architectures, multiplatform interoperability and software security.  Joe brings 30 years technical and business strategy experience to Microsoft which affords him a unique experiential perspective.




  •  

       Sponsor: GLUGnet                



  • !!-Prizes: Dell 19inch LCD monitor, books, and other cool swag will be given out for our July meeting-!!

    Local .NET user groups – attend one!

    I attended two local user groups this week.  West Michigan .NET user group (http://www.grdotnet.org) and GLUG – Greater Lansing user group (http://www.glugnet.org/ ).  It has been a while since I attended a user group meeting but this is a real jewel to network with people who are “geeks” and learn too.  I plan on helping as much as I can, I am not sure where to start. ?  If you have any tips or tricks in having a successful user group. Let me know either by replying here or contact me at [email protected]

    Show friendly display name in the "FROM" and "TO" fields using CDOSYS

    I was trying to find an example that would display a “Friendly name” vs. an “email address” when generating emails using CDOSYS.   Here is the code to do this.


                 Set imsg = Createobject(“cdo.message”)

    With iMsg


       .To = “John Monday <[email protected]>”


       .From = “Steve Friday <[email protected]>”


       .Subject = “A Subject Line: ” & Now()


       .TextBody = “A Text body message”


    .Send


    End With


    Set imsg = nothing


    Other links I found


     


     


     

    Sample Chapter 1.21 CDO library
    http://www.cdolive.com/procdo.htm

     

    Sample code
    http://www.microsoft.com/mspress/books/sampchap/3449.asp

    WMI – start a process on remote machine and passing custom credentials.

    I use System.Management in .NET 2.0 to connect, pass custom credentials to a remote machine and query with WMI frequently.   This is straight forward and there are many examples showing the syntax how to do this.   However, while working with remote IIS7 installs,  I wanted to execute a command on a remote machine while passing custom credentials.  I couldn’t find an example that provided this functionality, hopefully this will save someone time searching for the syntax.  This sample starts an instance of ‘calc.exe’ on a remote machine. 


    The code accepts four parameters



    • Command to run,
    • Machine to connect to,
    • UserName,
    • Password





    Module Module1


        Sub Main()
            Dim retValue As String
            retValue = RunCommand(“calc.exe”, “MachineName”, “MachineNameUserID”, “Password”)
            Console.WriteLine(retValue)
        End Sub


        Function RunCommand(ByVal strCommand As String, ByVal strMachineName As String, ByVal strUserName As String,
    ByVal strPassword As String) As String
            Dim options As New System.Management.ConnectionOptions
            options.Username = strUserName
            options.Password = strPassword


            Dim path As New System.Management.ManagementPath(“\” & strMachineName & “rootcimv2:Win32_Process”)
            Dim scope As New System.Management.ManagementScope(path, options)


            scope.Connect()


            Dim opt As New System.Management.ObjectGetOptions()
            Dim classInstance As New System.Management.ManagementClass(scope, path, opt)


            Dim inParams As System.Management.ManagementBaseObject = classInstance.GetMethodParameters(“Create”)
            inParams(“CommandLine”) = strCommand


            ‘ Execute the method and obtain the return values.
            Dim outParams As System.Management.ManagementBaseObject = classInstance.InvokeMethod(“Create”, inParams, Nothing)
            Return “ReturnValue:” & outParams(“returnValue”) & ” Process ID: {0}” & outParams(“processId”)


        End Function


    End Module


    Some links I found useful



    Return code s
    Description (these are the codes returned once a process has executed)

    0 Successful completion
    2 Access denied
    3 Insufficient privilege
    8 Unknown failure
    9 Path not found
    21 Invalid parameter