?
Solved

Group policy and running a .bat file

Posted on 2006-11-02
4
Medium Priority
?
395 Views
Last Modified: 2013-12-04
Hello experts...

I have a question with regard to .bat files and group policies.  Have a log off .bat file that runs defrag and disk cleanup when users log off each night.  The .bat file is located on the file server.  Since removing the user from the local admin group to power users group, I've noticed the .bat file not running when users log off at night.  

So the question is, how do I get the batch file to execute on the local machine using group policies when the user is power user and not an local admin user?

Windows 2000 DC and XP Pro workstations.

Thanks.
0
Comment
Question by:braman1
[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
  • 3
4 Comments
 
LVL 38

Expert Comment

by:Shift-3
ID: 17860281
The file should execute, but only administrators have the right to defragment disks.  Since the job is running in the user's context, it doesn't have the rights necessary.

It would be better to use scheduled tasks to run your disk cleanup and defrag jobs.  That way they won't slow down logoffs and they will run even if nobody logs in.  Here are some instructions:
http://www.edbott.com/weblog/?p=1268
http://www.microsoft.com/windowsxp/using/setup/expert/crawford_october08.mspx

You can mass-deploy these scheduled tasks to all of your workstations using the AT command.
0
 

Author Comment

by:braman1
ID: 17866751
Could you expand on the AT command?  I really wanted to avoid having to visit each workstation and setting up the scheduled task.  I was hoping to roll out using GP.  

Thanks.

0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 17868031
You can view the parameters of the AT command by typing "at /?" at the command line.  As an example, running the following command creates a scheduled task on the target computer which defrags the C: drive at 2:00 am every Saturday.
at "\\targetcomputer" 02:00 /every:saturday defrag c:

Setting up Disk Cleanup to run unattended is a little trickier, as you first have to customize it using the /sageset switch.  See these instructions:
http://www.edbott.com/weblog/?p=1274

Running "cleanmgr /sageset:5555" and selecting Temporary Files creates a REG_DWORD named StateFlags5555 with a value of 2 under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files.  It creates a similar entry for any other option you select.

You can use a script to pull this all together.  First create a text file named computerlist.txt.  Enter the names of all the workstations into it, one per line.  Then create a file named schedule.cmd in the same directory and paste the text between the lines into it.

__________
@echo off
setlocal

set RegPath=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches

for /F "tokens=*" %%G in (computerlist.txt) do (

 REM Sets Disk Cleanup registry entries.  Add additional lines here to include other cleanup options.
 reg add "\\%%G\%regpath%\Internet Cache Files" /v StateFlags5555 /t REG_DWORD /d 2 /f
 reg add "\\%%G\%regpath%\Old ChkDsk Files" /v StateFlags5555 /t REG_DWORD /d 2 /f
 reg add "\\%%G\%regpath%\Temporary Files" /v StateFlags5555 /t REG_DWORD /d 2 /f

 REM Schedules Disk Cleanup
 at "\\%%G" 01:00 /every:saturday cleanmgr /sagerun:5555

 REM Schedules Defrag
 at "\\%%G" 02:00 /every:saturday defrag c:

)

endlocal
__________

Running this creates a scheduled task on each computer which runs Disk Cleanup at 1:00 am and defrags the C: drive at 2:00 am every Saturday.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 17868060
Oops, those reg add commands aren't right.  You might have to deploy those using a startup script instead.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently, a new law in my state forced us to get a top-to-bottom analysis of all of our contract client's networks. While we have documentation, it was spotty at best for some - and in any event it needed to be checked against reality. That was m…
SHARE your personal details only on a NEED to basis. Take CHARGE and SECURE your IDENTITY. How do I then PROTECT myself and stay in charge of my own Personal details (and) - MY own WAY...
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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