# Type Mismatch: 'CDate'



## absentmind (Sep 16, 2005)

This script was meant to pull user profile data from remote computers, only problem is I can't get any time stamps due to this CDate mismatch error. Can anyone tell me what I'm doing wrong?


```
Const wbemImpersonationLevelImpersonate = 3
Const wbemAuthenticationLevelPktPrivacy = 6
Const ForAppending = 8

strUser=InputBox ("Domain Admin (domain\user)", "Get Profiles", default, 100, 100)
    If strUser="" Then
        WScript.Echo "Terminated due to missing parameter."
        WScript.Quit
    End If
strPass=InputBox ("Password for "&strUser&"", "Get Profiles", default, 100, 100)
    If strPass="" Then
        WScript.Echo "Terminated due to missing parameter."
        WScript.Quit
    End If
strComputer=InputBox ("Target Computer", "Get Profiles", default, 100, 100)
    If strComputer="" Then
        WScript.Echo "Terminated due to missing parameter."
        WScript.Quit
    End If
strNameSpace = "root\cimv2" 

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
    (strComputer, strNameSpace, strUser, strPass)

objSWbemServices.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objSWbemServices.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy

Set colSWbemObjectSet = objSWbemServices.ExecQuery _
    ("Select * from Win32_NetworkLoginProfile")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("profiles.txt", ForAppending)

objFile.WriteLine "*** " & strComputer & " ***"
objFile.WriteBlankLines(2)
For Each objItem in colSWbemObjectSet
    dtmWMIDate = objItem.AccountExpires
    strReturn = WMIDateStringToDate(dtmWMIDate)
    objFile.WriteLine "Account Expires: " & strReturn
    objFile.WriteLine "Authorization Flags: " & objItem.AuthorizationFlags
    objFile.WriteLine "Bad Password Count: " & objItem.BadPasswordCount
    objFile.WriteLine "Caption: " & objItem.Caption
    objFile.WriteLine "CodePage: " & objItem.CodePage
    objFile.WriteLine "Comment: " & objItem.Comment
    objFile.WriteLine "Country Code: " & objItem.CountryCode
    objFile.WriteLine "Description: " & objItem.Description
    objFile.WriteLine "Flags: " & objItem.Flags
    objFile.WriteLine "Full Name: " & objItem.FullName
    objFile.WriteLine "Home Directory: " & objItem.HomeDirectory
    objFile.WriteLine "Home Directory Drive: " & objItem.HomeDirectoryDrive
    dtmWMIDate = objItem.LastLogoff
    strReturn = WMIDateStringToDate(dtmWMIDate)
    objFile.WriteLine "Last Logoff: " & strReturn
    dtmWMIDate = objItem.LastLogon
    strReturn = WMIDateStringToDate(dtmWMIDate)
    objFile.WriteLine "Last Logon: " & strReturn
    objFile.WriteLine "Logon Hours: " & objItem.LogonHours
    objFile.WriteLine "Logon Server: " & objItem.LogonServer
    objFile.WriteLine "Maximum Storage: " & objItem.MaximumStorage
    objFile.WriteLine "Name: " & objItem.Name
    objFile.WriteLine "Number Of Logons: " & objItem.NumberOfLogons
    objFile.WriteLine "Password Age: " & objItem.PasswordAge
    dtmWMIDate = objItem.PasswordExpires
    strReturn = WMIDateStringToDate(dtmWMIDate)
    objFile.WriteLine "Password Expires: " & strReturn
    objFile.WriteLine "Primary Group ID: " & objItem.PrimaryGroupId
    objFile.WriteLine "Privileges: " & objItem.Privileges
    objFile.WriteLine "Profile: " & objItem.Profile
    objFile.WriteLine "Script Path: " & objItem.ScriptPath
    objFile.WriteLine "Setting ID: " & objItem.SettingID
    objFile.WriteLine "Units Per Week: " & objItem.UnitsPerWeek
    objFile.WriteLine "User Comment: " & objItem.UserComment
    objFile.WriteLine "User Id: " & objItem.UserId
    objFile.WriteLine "User Type: " & objItem.UserType
    objFile.WriteLine "Workstations: " & objItem.Workstations
    objFile.WriteBlankLines(1)
Next

objFile.WriteLine "======================================="
objFile.WriteBlankLines(1)
objFile.Close 

Function WMIDateStringToDate(dtmStart)
    If Not IsNull(dtmWMIDate) Then 
    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, 13, 2))
    End If
End Function




Call MsgBox ("Profile information collected.    ", 64, "Get Profiles")
```


----------



## aewarnick (Sep 3, 2002)

I'm not sure what CDate is, but it looks to me like you are trying to assign the return value of CDate to a function:
WMIDateStringToDate = CDate

You have some explaining to do.


----------

