Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Problem Running script 2

Status
Not open for further replies.

w33mhz

MIS
May 22, 2007
529
US
OK I have a script that I want to run as a startup script, but when I run it I get an Permission Denied error. I want to run it on my term servers so that when they reboot they will delete profiles that didn't get deleted off when users log off. I have all the profile folders that I don't want deleted are hidden.

Code:
dim colsubfolders, colSubfolders2, fso, objWMIService, objSubfolder, objFolder, strComputer

strComputer = "."

Set fso = CreateObject ("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder("M:\Documents and Settings")
Set colSubfolders = objFolder.Subfolders


Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


For Each objSubfolder in colSubfolders
	If Not objSubfolder.Attributes AND 2 then
		objSubfolder.Delete
    	End If
Next

Now i can delete the folders when i log in manually i just get the error when I run the script. I have verified that there are no locks on the files, and I have checked the permissions and I have all the correct perms.
 
and I have checked the permissions and I have all the correct perms.

When the startup script runs it does not run as you it runs as the system account.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
A startup script runs with the credentials of a LOCAL admin ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That is correct, but I get the same error while running the script manually loged in as Administrator.
 
So this:

Set objFolder = fso.GetFolder("M:\Documents and Settings")


makes me think that you are working with folders on a share. Will the local admin and/or the admin account that you are logging in a running it as have access rights to the share where M: is?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
local admins have full control of all the folders to delete in question. System has full control of the root folder "M:\Documents and Settings", System does not appear on the subfolders, but local administrators do. I get the same error running as local admin as I do on start up. I could believe that it would have something to do with system, but when I changed that it didn't help at all.
 
well the "M:\" drive is the system drive, I remapped it to M:\ instead of C:\. The mapping is not the problem, I know that for sure, I ran the mapping on my local computer and got the same results with C:\Documents and Settings, and yes as local admin.
 
Um... Try this...

objSubFolder.Delete [red]True[/red]

Any system/readonly files in any Subdirectory will cause the script to crash if you don't force the deletion.


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I get the same error running as local admin as I do on start up
So, reread my previous reply ...
 
Try changing this:

objSubfolder.Delete

to this:

objSubfolder.Delete [red]True[/red]

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
PHV,

I don't understand what do you have wrong with my post? I know I didn't give the error code at the begining, but it I have given a fairly detailed post of my problem. It might not be the best post, but if you need more info from me please ask what it is and I will be happy to research what you want and post it.
 
PScottC and EBGreen,

That seemed to work. Thank you for your posts.
 
The "SYSTEM" security principal should be granted Full permissions to all subfolders of Documents and Settings. When the startup script runs, it will use that security principal to access the files.

IMHO, the problem is files with the "System" attribute set in the subfolders. A quick check on my system shows ntuser.ini and ntuser.pol having that attribute set.

[URL unfurl="true"]http://www.devguru.com/Technologies/vbScript/quickref/folder_delete.html[/url]


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top