Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with Logon Script

Posted on 2005-02-24
4
Medium Priority
?
239 Views
Last Modified: 2010-04-17
I'd like to write a logon script that will help be with a PC auditing progrma that we run.  Currently I can run the program with a simple script but I'd like to set something up that would only allow the app to run if it's been more than 7 days since the last time it was run.  The program modifies a hidden file on C:\ and what I would like is to have a command shell script that compares the modified date of the file against the current system time and determines is it's been more than 7 days since it was modified.  I have done other scripts that do similar tasks but i can't seem to get this one right.  Thanks
0
Comment
Question by:Chryyys
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
ScrptMasta earned 1000 total points
ID: 13404184
Here ya go... This is a ScrptMasta special so you should feel priveldge it was wrote just for you.

**********************************************************************
Function DiffADate(theDate)
   DiffADate = DateDiff("d", Now, theDate)
   Wscript.Echo diffadate
End Function

Function WMIDateStringToDate(dtmInstallDate)
    WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
        Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
            & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
                Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
                    13, 2))
End Function


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_Datafile Where name = 'c:\\test.doc'")

For Each objFile in colFiles
    Wscript.Echo "Last modified: " & objFile.LastModified
   
    mydate = WMIDateStringToDate(objFile.LastModified)

    If DiffADate(mydate) > 7 Then
       msgbox "More then 7 days"
    Else
       msgbox "Not 7 days"
    End if  
Next
**********************************************************************
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 13405314
I like the idea of updating the LastModified tag, just thought i'd add that using that method you have to make sure no one touches the file or it will change. Another alternative is simply to store the date in a text file.
0
 
LVL 3

Author Comment

by:Chryyys
ID: 13406850
And I thank you.  After I put my speicifc information in, it wokred like a champ.  
0
 
LVL 7

Expert Comment

by:ScrptMasta
ID: 13419896
Your welcome, glad I could help.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Starting up a Project
Loops Section Overview

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question