Solved

Group policy and running a .bat file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
As I write this article, I am finishing cleanup from the Qakbot virus variant found in the wild on April 18, 2011.  It was a messy beast that had varying levels of infection, speculated as being dependent on how long it resided on the infected syste…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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