Hello,
I would like to ask you something about the SFImpersonator.dll.
We don't want to work with roaming profiles for the students, although
we know that whenever you work with roaming profiles, it is possible
to have the locally cached profile deleted when the user logs off.
Since we don't work with roaming profiles, the local profile of every
student who logs on on a client is saved in the map c:\Document and
settings\'name of the user';. Since during one day several students
log on on one client, many local profiles are saved in that map. The
local profiles have to be deleted, for instance once a day when the PC
is started.
Therefore I have written a script to clean up the student profiles.
But you have to have enough permissions to delete a profile map of a
user. Therefore I used the SFImpersonator.dll. But it does not do what
I expected. The impersonification seems to work, but when the script
tries to delete the profile map of a user, I get the error message
'access denied', although the user impersonated to, has full control
on the specific profile map.
I would appreciate it a lot if you could tell me what I am doing
wrong. Perhaps it is not possible to do the job this way.
Here is the script:
Option Explicit
Dim Text, Title
Dim fso, oFolders, oSubFolders, oFolder, wsh, oNet, impo 'Object
variables
Const path = "C:\Documents and Settings"
Const LOGON_INTERACTIVE = 2
Const LOGON_NETWORK = 3
Const LOGON_BATCH = 4
Const LOGON_SERVICE = 5
Text = "Folders" & vbCrLf & vbCrLf
Title = "WSH sample - Labo informatica"
Set wsh = WScript.CreateObject("WScript.Shell")
Set oNet = CreateObject("Wscript.Network")
'Object for impersonification
Set impo = CreateObject("sfImpersonator.Impostor")
'Creation of FileSystemObject object for access to the file system
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
MsgBox "Logged on as " & oNet.UserDomain & "\" & oNet.UserName
'Impersonification to the administrator of the domain
impo.Impersonate "administrator", "xxxxxxx", "edu", LOGON_INTERACTIVE
MsgBox "Impersonification to " & oNet.UserDomain & "\" & oNet.UserName
' List all the folders of C:\Documents and Settings
' Collect the folders collection
Set oFolders = fso.GetFolder(wsh.ExpandEnvironmentStrings(path))
Set oSubFolders = oFolders.SubFolders
For Each oFolder In oSubFolders
Text = Text & oFolder.Name & vbCrLf
If (MsgBox("Delete folder " & oFolder.Name & " ? ", _
vbYesNo + vbQuestion, Title) = vbYes) Then
'User answered Yes
fso.DeleteFolder("C:\Documents and Settings\" & oFolder.Name)
End if
Next
MsgBox Text, vbOKOnly + vbInformation, Title
'Impersonification to the user who was logged on
impo.RevertToSelf
MsgBox "Terug naar " & oNet.UserDomain & "\" & oNet.UserName