+ Reply to Thread
Results 1 to 15 of 15
  1. #1
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103

    need VBS script (pausing issue)

     
    I have a script that deletes old user profiles (older than 90 days) on AD Domain computers.

    set wshshell = createobject("WScript.Shell")

    Const ADS_SCOPE_SUBTREE = 2
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCOmmand.ActiveConnection = objConnection
    objCommand.CommandText = _
    "Select Name, Location from 'LDAP://ou=test,DC=mydomain,DC=com' " _
    & "where objectClass='computer'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 30
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Cache Results") = False
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value & " Location: " & objRecordSet.Fields("Location").Value

    wshshell.run "delprof.exe" & " /q /i /c:\\" & objRecordSet.Fields("Name").Value & " /d:90"

    objRecordSet.MoveNext
    Loop
    My current problem: without the Wscript.Echo line, the script runs so fast multiple CMD windows are opened (one for each machine). To be more useful, I need a way to pause & then resume the script when the current computer is done.

    Suggestions?

  2. #2
    Not Really a Member
    Join Date
    Oct 2001
    Posts
    27,856
    WScript.SLeep is what you need I do believe

    WScript.Sleep 6000 will wait a second before continuing

    (its in milliseconds so you can judge how long it needs)

    Just put it in place of the wscript if you want or just after it

    This a script of your own doing?
    Try code tags,they keep the indenting
    Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.

  3. #3
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    If WScript.SLeep is strictly time based it would help but would not be ideal. Some machines take a long time, others a short time.

    I'm not sure what you mean by code tags. I have indenting on the real script but must have lost it with cut, paste, & post.




    This a script of your own doing?
    not entirely, I started with a piece and kept adding stuff. I mostly combine script samples I find.

  4. #4
    Not Really a Member
    Join Date
    Oct 2001
    Posts
    27,856
    hmmm

    OK .. well instead of calling the delprof.exe, you could call a batch file.. the batch file drops a flag file, calls delprof.exe and deletes it after running.
    The script after executing the batch continually checks for the flag file, once its deleted then move forward...
    Would that work out better?

    btw, I meant use the [ code ] tag instead of the [ quote ] tags
    Last edited by vass0922; May 30th, 2003 at 10:39 PM.
    Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.

  5. #5
    Banned qball's Avatar
    Join Date
    Oct 2001
    Posts
    447
    My current problem: without the Wscript.Echo line, the script runs so fast multiple CMD windows are opened (one for each machine).
    Some machines take a long time, others a short time.
    you have a timing issue. pausing is for timing issues to catch up...

    welcome to synchronous vs. asynchronous processing/programming/whatever...

    You seem to invoke:

    "wshshell.run "delprof.exe" "

    for each record in:

    "Do Until objRecordSet.EOF"

    But the script processes:

    "Do Until objRecordSet.EOF"

    without waiting (pause) until each:

    "wshshell.run "delprof.exe" "

    is completed.

    ====================
    What do you gain by this?
    What are you trying to accomplish?
    ====================

  6. #6
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    Vass: that idea should work fine. Now I would just need to figure out how to make that check flag file looping part.

    qball: The generic pausing just won't well because some machines will not need any pause, others may need minutes. Doing this for hundreds of workstations would be inefficient.

    What I gain & accomplish, this is to delete old unused local profiles off user workstations.

  7. #7
    Not Really a Member
    Join Date
    Oct 2001
    Posts
    27,856
    add this to the declarations

    Dim objFSO


    Set objFSO = CreateObject("Scripting.FileSystemObject")


    Then just put this AFTER the call to the batch file



    Code:
    '' Keep waiting until the flag file is deleted through the batch file
    Do While objFSO.FileExists("\\pathto\file\flagfile.txt")
      ' ZZzzzzzzz 
      WScript.Sleep 500
    Loop

    Note: Hopefully not necessary, but the script may be able to continue working past the loop faster than the batch file can create the text file so maybe required to put in a small sleep statement after the call to the batch file to give it a split second to work

    Are you going to be calling this from a logon script?
    Seems like this is going to NAIL your DC if 50 people all log on at roughly the same time especially if you have a large userbase.
    Last edited by vass0922; May 31st, 2003 at 12:59 PM.
    Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.

  8. #8
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    That looks good!

    I won't do it via login script because users would need higher priviledges. I plan to have a Task on a DC or other server that does this once a month or something like that. The first time will be lengthy but after that it shouldn't be too bad.

  9. #9
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    It works as needed! End result requires these two files plus delprof.exe from MS Resource kit.

    main script:
    Code:
    Dim objFSO
    Dim strFilePath 'Path to current directory
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    set wshshell = createobject("WScript.Shell")
    
    Const ADS_SCOPE_SUBTREE = 2
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    
    strFilePath = objFSO.GetAbsolutePathName(".")
    flagfile1 = strFilePath & "\flag1.txt"
    
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCOmmand.ActiveConnection = objConnection
    objCommand.CommandText = _
    "Select Name, Location from 'LDAP://ou=myOU,DC=myDomain,DC=com' " _
    & "where objectClass='computer'" 
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 30 
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    objCommand.Properties("Cache Results") = False 
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    
    ''Next line is just an optional visual display of workstations found
    'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value & "  Location: " & objRecordSet.Fields("Location").Value
    
    wshshell.run "delprof.bat " & objRecordSet.Fields("Name").Value
    WScript.Sleep 2000
    
    '' Keep waiting until the flag file is deleted through the batch file
    Do While objFSO.FileExists (flagfile1)
      ' ZZzzzzzzz 
      WScript.Sleep 500
    Loop
    
    objRecordSet.MoveNext
    Loop
    delprof.bat contains:
    Code:
    echo just a temp file >flag1.txt
    delprof.exe /q /i /c:\\%1 /d:90
    del flag1.txt
    exit

    Thanks for all the help Vass!

  10. #10
    Not Really a Member
    Join Date
    Oct 2001
    Posts
    27,856
    Excellent work, well you're doing the hard part I'm just helpin' ya tie up the loose ends now

    Good job
    Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.

  11. #11
    Banned qball's Avatar
    Join Date
    Oct 2001
    Posts
    447
    qball: The generic pausing just won't well because some machines will not need any pause, others may need minutes. Doing this for hundreds of workstations would be inefficient.
    I understand. some milliseconds, others days...

    Your missing the point, but using the ability of a DOS batch file to run synchronously, to get around the inability for:

    "wshshell.run "delprof.bat " & objRecordSet.Fields("Name").Value"

    to run synchronously.

    Think about what you are doing:

    Looping through records to delete user profiles.

    Looping thru recs, no problem, deleting user profiles has timing problems.

    Your solution:

    Retrieve records and loop, del profile using batch file that effectively creates a flag file. Wait for file to not exist, process next record. That is barely efficient.

    Code:
    WScript.Sleep 2000
    '' Keep waiting until the flag file is deleted through the batch file
    Do While objFSO.FileExists (flagfile1)
      ' ZZzzzzzzz 
      WScript.Sleep 500
    Loop
    objRecordSet.MoveNext
    Loop
    Is useless code if one just does:

    Retrieve records and loop.
    del profile using synchronous method, perhaps winAPI call to delete profile, not command line exe?
    process next record.

    Seems silly to use exe from resource kit to accomplish core OS maintenance...

  12. #12
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    qball: If you know how to "del profile using synchronous method, perhaps winAPI call to delete profile" I'm quite interested in hearing how. I'm not a programmer by any means, I just needed a way to do this maintenance.

    When I say more efficient, I meant as opposed to what I had figured out so far.

    You post seems more like an attempt to be disrepectful than to help. I hope you prove this feeling wrong by offering an improvement or working alternate solution.

  13. #13
    Banned qball's Avatar
    Join Date
    Oct 2001
    Posts
    447
    You post seems more like an attempt to be disrepectful than to help. I hope you prove this feeling wrong by offering an improvement or working alternate solution.
    My bad. Any disrespect is the reality of the situation.

    Couple of questions:

    How do you add profiles (or user?)?
    what profile (and priviliges) does the 'script' that calls:

    "wshshell.run "delprof.bat " & objRecordSet.Fields("Name").Value"

    run under?

    If you don't like my answers, ask better questions. Or ask your winders admin, how to remove profiles efficiently.

    glad it all work out for you...

  14. #14
    addicted DVNT1's Avatar
    Join Date
    Oct 2001
    Location
    Ohio
    Posts
    6,103
    qball: with your questions (and answers) it doesn't seem like you can add any value here. Please disregard this thread and I'll continue working with members who are knowledgeable in this area.

  15. #15
    Banned qball's Avatar
    Join Date
    Oct 2001
    Posts
    447
    qball: with your questions (and answers) it doesn't seem like you can add any value here. Please disregard this thread and I'll continue working with members who are knowledgeable in this area.
    why can't you answer the questions?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews