?
Solved

help converting bat to vbs or autoit

Posted on 2015-02-10
9
Medium Priority
?
192 Views
Last Modified: 2015-02-12
@echo off
rem Enter into top level folder, process it and go back to original folder
pushd x
call :processFolder
popd
goto :EOF

:processFolder
rem For each folder in this level
for /D   %%a in (*) do (
   rem Enter into it, process it and go back to original
   cd %%a
   call :processFolder
   cd ..
   rem If is the target folder, delete it
   if /I "%%a" == "downloads" (
      del  /Q "%%a"\*.* 
   )
)
exit /B

Open in new window


I need to convert this to a vbs or exe so I can run it in the background with scheduled task. AS of current, I can make it run but it shows the command window (black screen) and disrupts the users workflow.  I can not figure out how to hide it as there isn't an option.

Thanks!
0
Comment
Question by:bbimis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40601811
Quick look but are you just trying to delete the contents of any folders called download?
0
 

Author Comment

by:bbimis
ID: 40601821
trying to delete the contents of the download folder but since there are several profiles on the computer the download directory is not always in the same spot could be like like
manager\downloads
manager.mydomain\downloads and so on

but yes any folder within the root path that is named downloads i want wiped.
0
 

Author Comment

by:bbimis
ID: 40601830
what my ultimate goal is to program a script/task that will purge the files that Outlook Web app downloads. This will prevent other users from viewing download history and seeing files other privilege users have opened.  I know this can be done with firefox settings  but i would prefer a script to do it so it doesn't get turned off/on..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 40602031
How long does your current script take to run, and when does it run?  You could simplify it as follows, might only take a fraction of a second then?

@echo off
for /f "tokens=*" %%a in ('dir /b /s /ad "%userprofile%\..\downloads"') do ECHO del /Q "%%~a\*.*"

Remove the word ECHO once you are happy it is doing what you want.

Can write something similar in VBScript but if you scheduled the task right then it shouldn't appear anyway?  I just created a batch script and it ran ok by the log file it produced, showed cmd.exe in task list and no window, this is on Windows 7.

Create the task
"Run whether user is logged on or not"
"Run with the highest priveleges" - if appropriate as accessing other profiles etc.
Triggers = as needed
Actions = run your .cmd file
Would suggest adjusting the settings for "stop the task if it runs for longer than" since by default = 3 days - you can type in 5 mins for instance even though not in the drop down list.

Steve
0
 

Author Comment

by:bbimis
ID: 40603188
That will work thanks. I was originally taking and pushing it into memory and then running it trying to speed it up. but your method is way faster.  Thanks for the help.  AS for the task, they are in some cases still running xp. Anyway thanks again!
0
 

Author Comment

by:bbimis
ID: 40603472
one thing I notice in the script at times though
the directory name "whatever path it may be" is too long
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40604557
OK.  You could try converting to short names (old 8.3 format) to see if that will get around the length issue - does it do it if you leave ECHO In so in the dir/for part, or when it does the delete, which below will be shorter path.

for /f "tokens=*" %%A in ('dir /b /s /ad "%userprofile%\..\downloads"') do ECHO del /Q "%%~sA\*.*"

Steve
0
 

Author Comment

by:bbimis
ID: 40605562
The method you posted in terms of short names worked. it was at the delete that i was having the issue.
Thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40605582
glad to hear.
Steve
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Simple Linear Regression
Starting up a Project
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question