Solved

Group policy and running a .bat file

Posted on 2006-11-02
4
394 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 500 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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Many of us in IT utilize a combination of roaming profiles and folder redirection to ensure user information carries over from one workstation to another; in my environment, it was to enable virtualization without needing a separate desktop for each…
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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