Thread: need VBS script (pausing issue)
-
May 30th, 2003, 05:44 PM #1
need VBS script (pausing issue)
I have a script that deletes old user profiles (older than 90 days) on AD Domain computers.
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.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
Suggestions?
-
May 30th, 2003, 06:37 PM #2Not 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.
-
May 30th, 2003, 10:05 PM #3
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.
not entirely, I started with a piece and kept adding stuff. I mostly combine script samples I find.This a script of your own doing?
-
May 30th, 2003, 10:10 PM #4Not 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.
-
May 30th, 2003, 11:43 PM #5My current problem: without the Wscript.Echo line, the script runs so fast multiple CMD windows are opened (one for each machine).you have a timing issue. pausing is for timing issues to catch up...Some machines take a long time, others a short time.
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?
====================
-
May 31st, 2003, 12:32 PM #6
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.
-
May 31st, 2003, 12:54 PM #7Not 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.
-
May 31st, 2003, 03:51 PM #8
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.
-
June 2nd, 2003, 11:58 AM #9
It works as needed! End result requires these two files plus delprof.exe from MS Resource kit.
main script:
delprof.bat contains: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
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!
-
June 2nd, 2003, 12:03 PM #10Not 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.
-
June 2nd, 2003, 09:15 PM #11I understand. some milliseconds, others days...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.
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.
Is useless code if one just does: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
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...
-
June 2nd, 2003, 11:39 PM #12
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.
-
June 3rd, 2003, 10:40 PM #13My bad. Any disrespect is the reality of the situation.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.
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...
-
June 4th, 2003, 01:41 PM #14
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.
-
June 5th, 2003, 12:31 AM #15why can't you answer the questions?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.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)



LinkBack URL
About LinkBacks



Reply With Quote

People like DooG and I are older farts. Hell, he can't even post unless he's asleep. The country is in your hands, Bingo . . .
Who Pays Corporate Income Taxes ?