Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbs/wscript debugging: Please Help 1

Status
Not open for further replies.

kaz44

Technical User
Oct 28, 2016
4
GB
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

 
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.
 
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)
 
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
 
 http://files.engineering.com/getfile.aspx?folder=b64bd49d-976c-4f20-8e29-cbcbfa9f890f&file=vbscript_error.JPG
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"
 
Mikrom,

Just to say a massive THANK YOU!!

Your suggestion did the trick.

You're a gem!

Thanks again,

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top