We help IT Professionals succeed at work.

Deleting a file using a VBScript run as a restricted user

2,056 Views
Last Modified: 2012-08-13
I need to delete a file from c:\windows during logon. The file being run at logon is a VBS file. When I use WSHFilesys.DeleteFile({filename.xxx}) I get permission denied. I've tried using CPAU and RUNAS but neither work. I have set a cmdPATH = "del /f {filename.xx} and then added WSHShell.Run "+cpau.exe -u {username} -p {password} -ex " & Chr(34) & cmdPath & Chr(34) & " -lwp -hide",0 ,True. Any assistance would be great.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Group Policy runs before the user is able to login, the VBScript I need to run does a number of things in sequence that rely on each other to process.

The scripts does the following, and is reliant on the user being logged in, because of everything else that needs to be done....

Checks Add-in's Exist
Removes Add-in's
Cleans the Add-in Manager Registry Key
Removes the Add-in toolbars
Then I need to delete to add-in Admin files from windows.

When I need to run something in a script as the user that needs elevated privilge, I usually use the CPAU program using the following syntax:

cpau -u{user} -p{password} -ex "What to run" -lwp -hide.

The problem was that all I was trying to pass into the "What to run" section was simply "del /f {filename}" and it kept telling me the parameters were incorrect.

So about 10 minutes after posting my question I sort-of cheated and simply used CPAU to run xcacls which gave EVERYONE full control to the two files I need to delete and the simply used WSHShell.Run "cmd /c del /f " & Chr(34) & "{filename} & Chr(34), 0, True.

This seemed to work fine.

I know this solution works, and of cource because I am using CPAU which has an admin password I encrypt all my VBS files, but if you know a clean way to elevate privilege, using WMI, WSH or anything else that will run inside a VBScript, then that would be great.....

Otherwise I'm happy to close this call as completed. (P.S) How do I do that??? - Close this call?

Regards
SummO!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
No - for some reason CPAU doesn't like the 'del /F command'. I'm happy with my solution at this stage. It's probably not a bad way to do it anyway, I'm not elevating privilege. All i'm doing is giving users access to files that are then deleted, so it's probably a better solution.

Regards
SummO!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.