VBS script not working on windows 7 64 bit

Hi all I have a script that worked great to clear out a file with XP and windows xp
and works great on servers when run for a 2003 server

Im trying to modify it to work on windows 7 64bit as we have an autocad virus multiplying and I need to crush it on end users machines,  now i just dabble in code and grab some from sites but this has been great in the past see code below however when I run it one windows 7 64 bit it errors out and says like 10 character 3

Permission denied

Any help would be great so I dont have to manually search each machine in our office

START_FOLDER = "D:\"
PREFIX = "acad.lsp"

Set oFSO = CreateObject("Scripting.FileSystemObject")

ProcessSubFolders oFSO.GetFolder(START_FOLDER), iCount

Sub ProcessSubFolders(oFolder, iCount)
  Set cFiles = oFolder.Files
  For Each oFile In cFiles
    If Left(oFile.Name, Len(PREFIX)) = PREFIX Then
      oFile.Delete
      iCount = iCount + 1
    End If
  Next
  For Each oSubFolder In oFolder.SubFolders
    ProcessSubFolders oSubFolder, iCount
  Next
End Sub

WScript.Echo "Files deleted: " & iCount

Open in new window

LVL 1
tgphelpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
Post a screen shot of the error you're having.
0
tgphelpAuthor Commented:
Here you go
Capture.JPG
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
Definitely need a screen shot of your error message - your script works fine on my Win8 x64 system.
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Lee W, MVPTechnology and Business Process AdvisorCommented:
Are you running as an administrator?  Try that.  Your issue appears to be NTFS permissions based, not script based.  The user running this does not have appropriate access to the path you are looking at.
0
Bill PrewIT / Software Engineering ConsultantCommented:
What is the Windows system drive, C: or D:?

~bp
0
tgphelpAuthor Commented:
System drive is c I've tried both and running as the domain admin on the computer as well as the local admin

Have tried launching from elevated cmd but same issue
0
tgphelpAuthor Commented:
I've tried this on my home computer with same results to make sure it wasn't a domain gpo stopping it
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Locate the path the message is caused by, e.g. by printing out each path processed.
You can also ignore the error with on error resume next, but that should be the means of last resort only.
My take is that you have virtual folders on D:. Those came starting with Vista/2008 to stay "compatible" with prior releases, as predefined paths changed a lot then. Example is Documents and Settings, which is Users now.
0
tgphelpAuthor Commented:
What would I add to the code to show that right now targeting each drive and get the number of files deleted
0
Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try, it will skip folders it can't access.

START_FOLDER = "D:\"
PREFIX = "acad.lsp"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

ProcessSubFolders objFSO.GetFolder(START_FOLDER, intCount)

Sub ProcessSubFolders(objFolder, intCount)
    On Error Resume Next

    For Each objFile In objFolder.Files
       If Left(objFile.Name, Len(PREFIX)) = PREFIX Then
          Wscript.Echo "Deleted file: " & objFile.Path
          objFile.Delete
          intCount = intCount + 1
       End If
    Next

   If Err.Number = 0 Then
      For Each objSubFolder In objFolder.Subfolders
         ProcessSubFolders objSubFolder, intCount
      Next
   Else
      Wscript.Echo "Skipped folder: " & objFolder.Path
   End If
End Sub

WScript.Echo "Files deleted: " & intCount

Open in new window

~bp
0
tgphelpAuthor Commented:
error got an error with your code
0
tgphelpAuthor Commented:
now if i just add  on error resume next, in my sub procedure in my code it works but i don't see where it error-ed
0
Bill PrewIT / Software Engineering ConsultantCommented:
Sorry, was pasting your code and some of my code together, paren in wrong place...

START_FOLDER = "D:\"
PREFIX = "acad.lsp"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

ProcessSubFolders objFSO.GetFolder(START_FOLDER), intCount

Sub ProcessSubFolders(objFolder, intCount)
    On Error Resume Next

    For Each objFile In objFolder.Files
       If Left(objFile.Name, Len(PREFIX)) = PREFIX Then
          Wscript.Echo "Deleted file: " & objFile.Path
          objFile.Delete
          intCount = intCount + 1
       End If
    Next

   If Err.Number = 0 Then
      For Each objSubFolder In objFolder.Subfolders
         ProcessSubFolders objSubFolder, intCount
      Next
   Else
      Wscript.Echo "Skipped folder: " & objFolder.Path
   End If
End Sub

WScript.Echo "Files deleted: " & intCount

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tgphelpAuthor Commented:
Bill thanks so much for the help its working it seems but there is one thing that is off it seems to count the skipped files/folders in the count so say it skipped 7 folders and there were no files to delete it says deleted 7 files

any quick adjustment so that doesnt count skips as deletes? thats so much for the help!
0
Bill PrewIT / Software Engineering ConsultantCommented:
Not positive is this will work, but give it a try...

START_FOLDER = "D:\"
PREFIX = "acad.lsp"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

ProcessSubFolders objFSO.GetFolder(START_FOLDER), intCount

Sub ProcessSubFolders(objFolder, intCount)
    On Error Resume Next

    For Each objFile In objFolder.Files
       If Left(objFile.Name, Len(PREFIX)) = PREFIX Then
          objFile.Delete
          If Err.Number = 0 Then
             Wscript.Echo "Deleted file: " & objFile.Path
             intCount = intCount + 1
          End if
       End If
    Next

   If Err.Number = 0 Then
      For Each objSubFolder In objFolder.Subfolders
         ProcessSubFolders objSubFolder, intCount
      Next
   Else
      Wscript.Echo "Skipped folder: " & objFolder.Path
   End If
End Sub

WScript.Echo "Files deleted: " & intCount

Open in new window

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.