?
Solved

Help with Logon Script

Posted on 2005-02-24
4
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

771 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