Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista General Discussion > Need help with batch file

Reply
Thread Tools Display Modes

Need help with batch file

 
 
n o s p a m p l e a s e
Guest
Posts: n/a

 
      10-10-2007
I want a batch file say "myshutdown.bat" that does the following:

* Empties my Recycle Bin
* Deletes Temp files for myself and all users. My OS is Vista Home
Premium and I have administrator's right
* Scan my computer, "C:\Program Files\Alwil Software
\Avast4\ashAvast.exe" C:\
* Does defragmentation of C:\
* shuts down the computer.

I really don't know how I can empty Recycle Bin and how I can execute
one command after the other.

 
Reply With Quote
 
 
 
 
Andrew McLaren
Guest
Posts: n/a

 
      10-10-2007
"n o s p a m p l e a s e" <> wrote...
>I want a batch file say "myshutdown.bat" that does the following:


> * Empties my Recycle Bin
> * Deletes Temp files for myself and all users. My OS is Vista Home
> Premium and I have administrator's right


You can do this using Vista's "Disk Cleanup" tool, cleanmgr.exe.

First, you need to create what Disk Cleansup calls a "sageset" - a list of
things you want to delete, stored in the registry and identified by a
number. You can have up to 64K different sagesets (not that you'd want to).

At a Administrator command prompt, run this command:

C:\>cleanmgr.exe /sageset:1

The Disk Cleanup Settings dialogue will appear. Select the items which you
want to delete in your batch file (eg Recycle Bin and Temporary files), and
press OK. This stores your selection of options in the registry.

To run Disk Cleanup, using the sageset you just saved, use this command:

C:\>cleanmgr.exe /sagerun:1
^^^
with a "run" instead of "set". This causes Disk Cleanup to run
automatically, no user intervention is required. This sagerun command would
be suitable for use in a batch file.

> * Scan my computer, "C:\Program Files\Alwil Software
> \Avast4\ashAvast.exe" C:\
> * Does defragmentation of C:\


At a command prompt, run "defrag /?" to see the command line options. You'll
probably want a command like:

"defrag C: -w -f"

> * shuts down the computer.


At a comand prompt, run "shutdown /? to see the command line options. You'll
probably want a comamnd like:

"shutdown /s /f"

> I really don't know how I can empty Recycle Bin and how I can execute
> one command after the other.


For non-GUI commands, just put them one after the other in the batch file.
For GUI commands, you can try using the START /WAIT command - this will wait
for the GUI app to complete, before going on to the next command. So, yu'll
have something like:

:===========================================
@ECHO OFF
REM Clean recycle bin and temp files
START /WAIT %SystemRoot%\SYSTEM32\CLEANMGR.EXE /Sagerun:1
REM
REM Run anti-virus
START /WAIT "C:\Program Files\Alwil Software\Avast4\ashAvast.exe" C:\
REM
REM Defrag C: drive, with full defrag and forced in nec.
%SystemRoot%\SYSTEM32\DEFRAG C: -W -F
REM
REM Now shut down, frcing apps closed if necessary
%SystemRoot%\SYSTEM32\SHUTDOWN /S /F
:END
:===========================================

Hope it helps,

--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
n o s p a m p l e a s e
Guest
Posts: n/a

 
      10-11-2007
On Oct 10, 3:16 pm, "Andrew McLaren" <and...@fakeaddress.com> wrote:
> :===========================================
> @ECHO OFF
> REM Clean recycle bin and temp files
> START /WAIT %SystemRoot%\SYSTEM32\CLEANMGR.EXE /Sagerun:1
> REM
> REM Run anti-virus
> START /WAIT "C:\Program Files\Alwil Software\Avast4\ashAvast.exe" C:\
> REM


Thanx. The above works.

> REM Defrag C: drive, with full defrag and forced in nec.
> %SystemRoot%\SYSTEM32\DEFRAG C: -W -F


This doesn't work.

> REM
> REM Now shut down, frcing apps closed if necessary
> %SystemRoot%\SYSTEM32\SHUTDOWN /S /F
> :END
> :===========================================


This also works.

The objective of this script is to just double click and everything
happens. I tried to execute %SystemRoot%\SYSTEM32\DEFRAG C: -W -F from
commandline with a command promt open with Administrator's right. It
then works.

Is it possible to tell this command to run with administrator's right
by just double clicking the script?

Thanx/NSP

 
Reply With Quote
 
Rogue
Guest
Posts: n/a

 
      10-11-2007
Create a link to the batch file and configure the link to run as
administrator

"n o s p a m p l e a s e" <> wrote in message
news: ps.com...
> On Oct 10, 3:16 pm, "Andrew McLaren" <and...@fakeaddress.com> wrote:
>> :===========================================
>> @ECHO OFF
>> REM Clean recycle bin and temp files
>> START /WAIT %SystemRoot%\SYSTEM32\CLEANMGR.EXE /Sagerun:1
>> REM
>> REM Run anti-virus
>> START /WAIT "C:\Program Files\Alwil Software\Avast4\ashAvast.exe" C:\
>> REM

>
> Thanx. The above works.
>
>> REM Defrag C: drive, with full defrag and forced in nec.
>> %SystemRoot%\SYSTEM32\DEFRAG C: -W -F

>
> This doesn't work.
>
>> REM
>> REM Now shut down, frcing apps closed if necessary
>> %SystemRoot%\SYSTEM32\SHUTDOWN /S /F
>> :END
>> :===========================================

>
> This also works.
>
> The objective of this script is to just double click and everything
> happens. I tried to execute %SystemRoot%\SYSTEM32\DEFRAG C: -W -F from
> commandline with a command promt open with Administrator's right. It
> then works.
>
> Is it possible to tell this command to run with administrator's right
> by just double clicking the script?
>
> Thanx/NSP
>

 
Reply With Quote
 
Andrew McLaren
Guest
Posts: n/a

 
      10-11-2007
"n o s p a m p l e a s e" <> wrote...
>> REM Defrag C: drive, with full defrag and forced in nec.
>> %SystemRoot%\SYSTEM32\DEFRAG C: -W -F

>
> This doesn't work.
> The objective of this script is to just double click and everything
> happens. I tried to execute %SystemRoot%\SYSTEM32\DEFRAG C: -W -F from
> commandline with a command promt open with Administrator's right. It
> then works.


Unfortunately, that's contrary to the spirit of UAC. If you want an app to
run with administrative prvilege, you need to enter administrator
credentials. Otherwise, you're just returning to the Windows 95 world of
viruses, trojans and other exploits, where processes can quietly run as
administrator, without explicit consent.

A few approaches:

- leave out the defrag. By default on Vista, defrag is scheduled to run
regularly, at a low priority, and in the user context of "System". If your
machine is routinely left running, it will defrag itself.

- instead of double-clicking the batch-file, right-click and then choose
"Run as Administrator" from the context menu. You'll need to enter
credentials, but it happens immediately.

- or, to run the batch file as is, create a shortcut to the batch file and
mark the shortcut "Run as Administrator". Again, you'll still need to give
administrative consent, but it will happen right after you double-click it.

Hope it helps,

--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
n o s p a m p l e a s e
Guest
Posts: n/a

 
      10-12-2007
On Oct 12, 1:06 am, "Andrew McLaren" <and...@fakeaddress.com> wrote:
> A few approaches:
>
> - leave out the defrag. By default on Vista, defrag is scheduled to run
> regularly, at a low priority, and in the user context of "System". If your
> machine is routinely left running, it will defrag itself.
>
> - instead of double-clicking the batch-file, right-click and then choose
> "Run as Administrator" from the context menu. You'll need to enter
> credentials, but it happens immediately.
>
> - or, to run the batch file as is, create a shortcut to the batch file and
> mark the shortcut "Run as Administrator". Again, you'll still need to give
> administrative consent, but it will happen right after you double-click it.
>
> Hope it helps,


Thanx. I got the point.

 
Reply With Quote
 
n o s p a m p l e a s e
Guest
Posts: n/a

 
      10-13-2007
On Oct 12, 9:19 am, n o s p a m p l e a s e <nospam.ple...@alum.com>
wrote:
> On Oct 12, 1:06 am, "Andrew McLaren" <and...@fakeaddress.com> wrote:
>
> > A few approaches:

>
> > - leave out the defrag. By default on Vista, defrag is scheduled to run
> > regularly, at a low priority, and in the user context of "System". If your
> > machine is routinely left running, it will defrag itself.

>
> > - instead of double-clicking the batch-file, right-click and then choose
> > "Run as Administrator" from the context menu. You'll need to enter
> > credentials, but it happens immediately.

>
> > - or, to run the batch file as is, create a shortcut to the batch file and
> > mark the shortcut "Run as Administrator". Again, you'll still need to give
> > administrative consent, but it will happen right after you double-click it.

>
> > Hope it helps,

>
> Thanx. I got the point.


I can confirm the script below when run as administrator works.

:===========================================
@ECHO OFF
REM Clean recycle bin and temp files
START "" /WAIT %SystemRoot%\SYSTEM32\CLEANMGR.EXE /Sagerun:1
REM
REM Run anti-virus
START "" /WAIT "C:\Program Files\Alwil Software\Avast4\ashQuick.exe" C:
\
REM
REM Defrag C: drive, with full defrag and forced in nec.
START "" /WAIT %SystemRoot%\SYSTEM32\DEFRAG C: -W -F
REM
REM Now shut down, frcing apps closed if necessary
START "" /WAIT %SystemRoot%\SYSTEM32\SHUTDOWN /S /F
:END
:===========================================

 
Reply With Quote
 
Andrew McLaren
Guest
Posts: n/a

 
      10-13-2007
"n o s p a m p l e a s e" <> wrote...
>> Thanx. I got the point.

> I can confirm the script below when run as administrator works.


Cool, thanks for the feedback!

Cheers,
--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
n o s p a m p l e a s e
Guest
Posts: n/a

 
      10-14-2007
On Oct 13, 1:08 pm, "Andrew McLaren" <and...@fakeaddress.com> wrote:
> "n o s p a m p l e a s e" <nospam.ple...@alum.com> wrote...
>
> >> Thanx. I got the point.

> > I can confirm the script below when run as administrator works.

>
> Cool, thanks for the feedback!
>
> Cheers,
> --
> Andrew McLaren
> amclar (at) optusnet dot com dot au


Is there any way to get windows update from command line and install
it?

 
Reply With Quote
 
munchie
Guest
Posts: n/a

 
      10-14-2007
On Oct 14, 12:10 am, n o s p a m p l e a s e <nospam.ple...@alum.com>
wrote:
> On Oct 13, 1:08 pm, "Andrew McLaren" <and...@fakeaddress.com> wrote:
>
> > "n o s p a m p l e a s e" <nospam.ple...@alum.com> wrote...

>
> > >> Thanx. I got the point.
> > > I can confirm the script below when run as administrator works.

>
> > Cool, thanks for the feedback!

>
> > Cheers,
> > --
> > Andrew McLaren
> > amclar (at) optusnet dot com dot au

>
> Is there any way to get windows update from command line and install
> it?


Is there anyway to check if a defrag _needs_ to be done in the commad
line? I'm guessing this is either possible by a)checking some error
level or b)using findstr to parse the output of "defrag -a"

Could someone show me how to do this?

-- Munchie

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
batch file help DarthRevan561 Windows Vista General Discussion 6 02-02-2008 12:00 AM
Batch file Bob Windows Vista General Discussion 2 01-20-2008 12:39 PM
Batch file Bob Windows Vista File Management 0 01-06-2008 07:39 PM
batch file calling exe file problem JPS Windows Vista Security 1 12-20-2007 12:18 AM
Batch file copy EruditeBonnie Windows Vista General Discussion 1 09-19-2007 08:34 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59