Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delprof and vbscript

59 views
Skip to first unread message

Mike M

unread,
Aug 5, 2003, 5:51:32 PM8/5/03
to
I thought I'd repost this and see if anyone bites...It's becoming very
important to resolve this so I figured I'd try one more time. Thanks for
trying the first time Robert!

<original post>

Hi All,
I was helping someone in another newsgroup and got a little stuck and it
is becoming a scripting issue, so I suggested we discuss the issue here.

Background
Basically, the writer has about 500 workstation and 2000 users. They
for various reasons don't use network profiles and everyone uses local
profiles. What he wants to do is delete from all the workstations any
profiles that are number and leave any profiles that are letters (numeric
profiles are the profiles that he wants removed). I came up with a script
that would look at the subfolders of documents and settings and if the
folder is a number to delete it and if not to not delete it. The problem is
that unless the user logs in as an admistrator, he doesn't have the
permissions to delete the folders. Plus as a microsoft person said,
"Profiles shouldn't be deleted by whacking the "c:\document and
settings\UserName" directory".

Now DELPROF is a command line utility that could do it. And he can even
do it remotely. However, there is no way to specify which users profiles
gets zapped.

The Question

Obviously you can do shell.run to run delprof. There is an option (/p)
to prompt before deleting each profile. What I was wondering if there is a
way to take the output and put it into a string and respond to the question.
For example, if the thing asks should it delete a profile, vbscript can see
what profile it is asking and then do an IsNumeric function and answer y or
n at the command line accordingly
Or is there some other scripting solution? I don't know if WMI can
delete folders like below (which is the script I suggested), but still that
doesn't solve the problem that supposedly you shouldn't delete profiles by
goign after the user's in document and settings.

Robert

</original post>

-Mike


Helge Wunderlich

unread,
Aug 6, 2003, 10:02:59 AM8/6/03
to
On Tue, 5 Aug 2003 15:51:32 -0600, "Mike M"
<no...@pleasereplytogroup.org> wrote:

> Obviously you can do shell.run to run delprof. There is an option (/p)
>to prompt before deleting each profile. What I was wondering if there is a
>way to take the output and put it into a string and respond to the question.
>For example, if the thing asks should it delete a profile, vbscript can see
>what profile it is asking and then do an IsNumeric function and answer y or
>n at the command line accordingly

Delprof does send its output to stdout and also reads the confirmation
from stdin. This means it should be possible to control it using the
Exec method and its stdout and stdin streams. But I cannot get it to
work as I hoped it would. The stdout buffer is empty when delprof
stops to wait for confirmation. I get the same behavior when
redirecting stdout to a file, so it seems Windows does some sort of
buffering that keeps the data until some condition has been met. Maybe
someone can explain or even get around the problem.

I do have another idea, but it is really, really ugly. I won't even
start coding, but the concept is like this:

1. Count the number of profile directories on the computer using fso.
2. Launch Shell.Exec("delprof /C:\\" & Computer & " /P /I")
3. Send "N" & vbCrLf the counted number of times to StdIn.
4. Capture the output from StdOut and analyze.
5. Build a string with the correct sequence of "N" and "Y" (each
followed by vbCrLf)
6. .Exec delprof one more time.
7. Send the string we built under 5 to answer yes and no in the
correct sequence.

The biggest problem here is if someone logs in or out between the two
times delprof is run. You will get out of sync and make a terrible
mess.

--
Helge Wunderlich
(Please remove the spam trap if you wish to send email)

Mike M

unread,
Aug 6, 2003, 10:45:46 AM8/6/03
to
Okay Hugh, I think we're getting somewhere. I am new to vbscript, but I
have done some programming in Visual Basic. I'll try to get the "ugly"
version working today in VB, but I would really like to trap the stdout and
do it that way and avoid deleting profiles in a potentially dangerour
manner. Thanks!

Mike

"Helge Wunderlich" <helge.wunder...@ericsson.no> wrote in message
news:45m1jvceuc396iatt...@4ax.com...

Helge Wunderlich

unread,
Aug 7, 2003, 5:31:09 AM8/7/03
to
On Wed, 06 Aug 2003 16:02:59 +0200, I
<helge.wunder...@ericsson.no> wrote:

>The stdout buffer is empty when delprof
>stops to wait for confirmation. I get the same behavior when
>redirecting stdout to a file, so it seems Windows does some sort of
>buffering that keeps the data until some condition has been met.

It seems I was too quick to blame Windows. A similar approach with
Xcopy /P gives the results I expected. I also tried an internal
command (DEL /P), which also works as expected.

This would mean that DELPROF.EXE has a problem when its output is
redirected.

Mike M

unread,
Aug 7, 2003, 9:51:41 AM8/7/03
to
Interesting. Which version of delprof are you using? I wonder if the
Windows Server 2003 version has the same problem. You can download the
resource kit here:
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en.
Can you post your code for both delprof and xcopy? Thanks for keeping up
with this.

Mike

P.S. Sorry I misspelled your name in my last post!


"Helge Wunderlich" <helge.wunder...@ericsson.no> wrote in message

news:9vv3jvsvvc8a2b481...@4ax.com...

Roibos

unread,
Oct 14, 2003, 1:02:37 PM10/14/03
to

I have been following this thread and have a similar problem. I work
with over 14,000 users. Our problem is on "shared" machines. The
profiles on these machines (located in conference rooms, etc.) end up
with hundreds of profiles. Our problem is that DelProf deletes the
Default, Administrator, and 3 more local profiles we want to leave on
the machine.

My solution was to write a VBscript that writes then deltes a txt file
to the predifined profile folders in the C:\My Documents folder. This
changes the last modified date to the current date. Next I am trying to
call DelProf with the /d:30 switch to delete profiles that have not been
used in 30 days (I plan on adding the /Q switch in the final version).

My problem is that when the script runs the folders are modified,
and the command is passed through and prompts me to answer yes or no
to deleting the profiles older than 30 days. I answer yes, the
system returns to the c: prompt without deleting files or even
giving me an error.

What I have checked..

I am using a local admin account

I can run DelProf at the CMD to delete ALL (not what i want) profiles
flawlessly

I can run DelProf at the CMD and get the exact same results

What am I doing wrong?????

Heres the code...

' NAME: <DelProf.vbs>

'

' COMMENT: <This file is designed to remove exorbitant profiles that
extend the

' system logon time.>

'

dim fso, folderpath, aFile, more, WshShell, Days, strPcName

'======== This section retrieves the computer name
===============================================================

Set WshShell = WScript.CreateObject("WScript.Shell")

strPcName = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

'======== This section creates a file in the folders to change the
modified date so they are not deleted==========

Set fso=CreateObject("Scripting.FileSystemObject")

folderpath = "C:\Documents and Settings\SYSTEM"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\SYSTEM\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

set folderpath = Nothing

folderpath = "C:\Documents and Settings\SMSCliToknAcct&"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\SMSCliToknAcct&\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

folderpath = "C:\Documents and Settings\SMSCliToknAcct&"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\SMSCliToknLocalAcct&\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\All Users"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and Settings\All
Users\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\Administrator"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\Administrator\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\Default User"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and Settings\Default
User\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\SMSSWInstall_EMN"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\SMSSWInstall_EMN\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\Local Settings"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and Settings\Local
Settings\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

If fso.FileExists("C:\Documents and Settings\Local
Settings\output.txt")Then

fso.DeleteFile "C:\Documents and Settings\Local
Settings\output.txt", True

End If

Set folderpath = Nothing

folderpath = "C:\Documents and Settings\SMSCliSvcAcct&"

If fso.FolderExists(folderpath) Then

Set aFile = fso.CreateTextFile("C:\Documents and
Settings\SMSCliSvcAcct&\output.txt", True)

aFile.WriteLine("1234")

aFile.Close()

End If

Set folderpath = Nothing

'==============This section deletes the files created earlier in the
script======================================

If fso.FileExists("C:\Documents and Settings\Default
User\output.txt")Then

fso.DeleteFile "C:\Documents and Settings\Default
User\output.txt", True

End If

If fso.FileExists("C:\Documents and
Settings\Administrator\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\Administrator\output.txt", True

End If

If fso.FileExists("C:\Documents and Settings\All Users\output.txt")Then

fso.DeleteFile "C:\Documents and Settings\All
Users\output.txt", True

End If

If fso.FileExists("C:\Documents and
Settings\SMSCliToknAcct&\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\SMSCliToknAcct&\output.txt", True

End If

If fso.FileExists("C:\Documents and Settings\SYSTEM\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\SYSTEM\output.txt", True

End If

If fso.FileExists("C:\Documents and
Settings\SMSSWInstall_EMN\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\SMSSWInstall_EMN\output.txt", True

End If

If fso.FileExists("C:\Documents and
Settings\SMSCliSvcAcct&\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\SMSCliSvcAcct&\output.txt", True

End If

If fso.FileExists("C:\Documents and
Settings\SMSCliToknLocalAcct&\output.txt")Then

fso.DeleteFile "C:\Documents and
Settings\SMSCliToknLocalAcct&\output.txt", True

End If

DeleteProfiles

Function DeleteProfiles

Days = InputBox ("How many days of inactivity will constitute the
deletion of a profile?")

WshShell.run "cmd /k delprof /i /d:"+ Days

End Function


--
Posted via http://dbforums.com

0 new messages