Solved

Group policy and running a .bat file

Posted on 2006-11-02
4
384 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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...
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now