Solved

help converting bat to vbs or autoit

Posted on 2015-02-10
9
183 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
  • 5
  • 4
9 Comments
 
LVL 43

Expert Comment

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

Author Comment

by:bbimis
Comment Utility
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
Comment Utility
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
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:bbimis
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
glad to hear.
Steve
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now