Sign in to follow this  
Followers 0

Searching The Root Of Users Profile Directory

2 posts in this topic

I have a VB logon script that we used to migrate users to our new print servers. I had it place a flag file at the root of the users profile to check for during subsequent logons to prevent the script from running more then once for each user.

I now want run a script from my machine that will go through each domain profile on each domain computer, and report back if it finds the flag file. I have a VB script (that could be converted to AutoIT of course) that comes close, but doesn't get each domain profile.

I usually prefer AutoIT to VB, but someone else started this as a VB project, and I took it over.

Question: Is there an easier way to do this with AutoIT?

Thanks for any help or suggestions!

My current effor with VB

On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet
Dim objFSO, objFile

Dim WshShell : Set WshShell = createobject("")
Dim Wshsysenv : Set WshSysEnv = WshShell.Environment("Process")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(WshSysEnv("userprofile")& _
              "\desktop\ProfileFlag.log", forappending, false)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

strBase = "<LDAP://ou=DIVISION-OU,ou=DEPT-OU,ou=ad," & strDNSDomain & ">" 
strFilter = "(&(objectCategory=computer))"
strAttributes = "Name"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF

    On Error Resume Next
     strComputer = objRecordSet.Fields("Name")

    Set objComputer = GetObject("WinNT://" & strComputer)

    objComputer.Filter = Array("user")

    For Each objUser In objComputer
        Wscript.Echo "Username = " & objUser.Name & VbCrLf & _
                     "Computername = " & strComputer

    If objFSO.FileExists("\\" & strComputer & "\Documents and Settings\" _
                        & strCurrUser & "\PTRMIG_FLG_.txt") Then    
        objFile.WriteLine "Computer Name: " & strComputer & _
            "   PTRMIG_FLG.txt FOUND"
        objFile.WriteLine "Computer Name: " & strComputer & _
            "   PTRMIG_FLG.txt not found"
    End If



Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing

Share this post

Link to post
Share on other sites

You could run a simple script on every workstation during logon:

If FileExists(@UserProfileDir & "\PTRMIG_FLG.txt") Then
    FileWriteLine("\\server\share\file.txt", "Computer Name: " & @ComputerName & "   PTRMIG_FLG.txt FOUND")
    FileWriteLine("\\server\share\file.txt", "Computer Name: " & @ComputerName & "   PTRMIG_FLG.txt not found")

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0