SFImpersonator 
Author Message
 SFImpersonator

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



Sat, 17 Jul 2004 00:05:30 GMT  
 SFImpersonator
Hi Karin,
One thing that can cause a message like this is if the files or folders you
are attempting to delete are in use.  Don't know if that is helpful or not .
. .

Schnibitz

Quote:
> 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



Sat, 17 Jul 2004 00:58:49 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. SFImpersonator running called apps

2. sfImpersonator and RegOBJ.dll

3. SFImpersonator

4. SFImpersonator.dll

5. SFImpersonator running called apps

6. SFImpersonator Question

7. Sfimpersonator.dll - required privilege

8. sfimpersonator doesn't work ??

9. Required privilege using SFImpersonator.dll

10. Sfimpersonator error: required priviledge...

11. Defrag without admin rights + SFImpersonator

 

 
Powered by phpBB® Forum Software