INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

vbs/wscript debugging: Please Help

vbs/wscript debugging: Please Help

(OP)
Hi All,

I have a script to backup only user profiles that have been modified in the last xx days.

I would be most grateful if anyone could help me resolve or point me in the right direction as to why the script is failing on the line in bold text



'Modified code to get last access time
Dim strPath, objFile, objNTUserFile, objLastAccessDate,

strPath=objWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSubkey & "\ProfileImagePath")
strPath = strPath + "\NTUSER.DAT"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNTUserFile = objFSO.GetFile(strPath)

ShowDebugMessage strPath & " modified: " & CDate(objNTUserFile.DateLastModified)

'Calculate the date 30 days ago
objLastAccessDate = DateAdd("d", -30, Now())


If(objNTUserFile.DateLastModified > objLastAccessDate) Then
ShowDebugMessage "Profile modified in the last 30 days."
Else
ShowDebugMessage "Profile NOT modified in the last 30 days."
blnSkip=true
End If

End If



Many thanks,

Keith

RE: vbs/wscript debugging: Please Help

What's the error, and which line is line 141?

RE: vbs/wscript debugging: Please Help

(OP)
Guitarzan,

it is the line in bold, Red font below:

'Modified code to get last access time
Dim strPath, objFile, objNTUserFile, objLastAccessDate,

strPath=objWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSubkey & "\ProfileImagePath")
strPath = strPath + "\NTUSER.DAT"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNTUserFile = objFSO.GetFile(strPath)

ShowDebugMessage strPath & " modified: " & CDate(objNTUserFile.DateLastModified)

'Calculate the date 30 days ago
objLastAccessDate = DateAdd("d", -30, Now())


Thank you.

RE: vbs/wscript debugging: Please Help

Maybe strPath does not point to an existing file.
Print to see it, before you try to do GetFile :

CODE

Wscript.Echo("strPath =" & strPath)
Set objNTUserFile = objFSO.GetFile(strPath) 

RE: vbs/wscript debugging: Please Help

(OP)
Thanks Mikrom.

When I do a print, as you advised, it returns the strPath - "%SystemDrive%\Documents and Settings\Test1.4RECDOMAIN\NTUSER.DAT" which is what the target is meant to be.
I am running the script from an elevated command prompt, as admin and have rights/access to "%SystemDrive%\Documents and Settings\Test1.4RECDOMAIN\NTUSER.DAT"

Yet is is still returning a File not found/Network path was not found error message. (screenshot attached)

Regards,

Keith

RE: vbs/wscript debugging: Please Help

Then the error seems to be thrown, because the method objFSO.GetFile() can not expand the variable %SystemDrive% in the strPath.

So, before using

CODE

Set objNTUserFile = objFSO.GetFile(strPath) 

you need to expand strPath explicitly like this:

CODE

strPath = "%SystemDrive%\Documents and Settings\Test1.4RECDOMAIN\NTUSER.DAT"
wscript.echo("strPath unexpanded = """ & strPath  & """")

' expand environment variables
set wshShell = CreateObject( "WScript.Shell" )
strPath = wshShell.ExpandEnvironmentStrings(strPath)
wscript.echo("strPath expanded   = """ & strPath  & """") 

Output:

CODE

strPath unexpanded = "%SystemDrive%\Documents and Settings\Test1.4RECDOMAIN\NTUSER.DAT"
strPath expanded   = "C:\Documents and Settings\Test1.4RECDOMAIN\NTUSER.DAT" 

RE: vbs/wscript debugging: Please Help

(OP)
Mikrom,

Just to say a massive THANK YOU!!

Your suggestion did the trick.

You're a gem!

Thanks again,

Keith

RE: vbs/wscript debugging: Please Help

You're welcome

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close