Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group Policy and Windows 7 1

Status
Not open for further replies.

scmoh

Technical User
Aug 28, 2001
59
SG
Hi,

i have a batch file to execute when users log off or shutdown via 2003 group policy for windows xp prof. workstations.

How to include this batch file for Windows 7 prof. workstations ?

Please advise.
With regards,
SC Moh
 
Just apply (i.e. link) the GPO to the OU containing the Windows 7 machines.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
have linked the GPO to the domain but the batch is not executed for Windows 7 prof.

windows XP prof. can execute the batch file when log off or shutdown.

Please advise.
with regards,
SC Moh
 
First thing to check is, does the script even work on Windows 7 PCs (i.e. when run manually, not with the GPO)?

If so, on one of the PCs that the GPO applies to, open a command prompt and enter this command:
Code:
gpresult /r
Does the output from that command list the GPO in question?

If so, it will list it either under the 'Applied Group Policy Objects' heading (which will mean it at least tried to run it) or another heading underneath called something like 'The following Group Policy Objects were not applied' (which means it didn't and will give a clue as to why).

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Hi Jeffery,

Thank you so much for your reply.

Yes, there is a default GPO applied to the Windows 7 prof.
For Windows XP, folder {31B2F340-016D-11D2-945F-00C04FB984F9} is assigned to the policies. How about Windows 7? is it using the same folder?

Please advise.
With regards,
 
Sorry, been busy.

Yes, a GPO is contained within a folder on each Domain controller within the Sysvol share like this:
C:\Windows\SYSVOL\sysvol\yourdomain.com\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}

The fact that you're trying to apply this GPO to Windows 7 PCs as well as XP doesn't change this path at all.

So, are you saying that the output from 'GPRESULT /r' on one of the Windows 7 PCs shows that the GPO IS being applied to the PC?

Also, have you confirmed that the script does actually work on Windows 7 (open a command prompt, drag and drop the script file in to the command prompt, then run the command line that drag-and-drop creates)?

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Hi Jeffery,

Yes, "GPRESULT /r" shown that the default GPO is applied to Windows 7 prof. and i can run the batch manually when the users signed in to the network.

maybe, i should add in the time stamp and log to the batch in order to check whether the batch file is executed during shutdown or log off.

with regards,
SC Moh
 
Yes, I'm a big fan of including some kind of logging within batch files.
Code:
set logfile=%windir%\DoStuff.log
echo Starting to DoStuff>%logfile%
::Stuff happens
echo Stuff happened with error level = %errorlevel%>>%logfile%
::more stuff happens
echo More stuff happened with error level = %errorlevel%>>%logfile%
::stuff all done
echo Finished doing stuff>>%logfile%

That kind of thing.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Hi Jeffrey,

in the domain server, GPO logoff path, the batch file will call and execute user's batch file (mailback.bat) to backup outlook pst files to their network home drive (in the batch, if exist d:\email call d:\mailback.bat).

GPO logoff batch file
if exist d:\mailback.bat call d:\mailback.bat

user's batch file (d:\mailback.bat)
echo %Date% %Time% >> d:\email\mailback.log
xcopy d:\email\*.* h:\email /s /e /v /y /d /f > d:\email\mailback.log
echo %Date% %Time% > d:\email\mailback.log
exit

in windows 7 prof. log file, only the first time is executed. is it too fast for windows 7 prof. to shutdown? or is the network home drive disconnected when call for the batch file? is there setting that can wait for the batch file to complete?

Please advise.

with regards,
SC Moh
 
Firstly, your batch file is using mixed redirection. The first line uses >> to APPEND to the log file, but the others use > which will REPLACE the log file. So, at the moment the only thing you'll see in the batch file is the result of the last line! i.e.

Code:
echo %Date% %Time% > d:\email\mailback.log

Which will produce a log file ONLY containing:

Code:
18/05/2012  9:37:04.80

So, you may find that the batch file is working, just that the log file implies it isn't.

Secondly, I would try to avoid using the mapped drive if you can. If you only have one file server hosting their home drives use the UNC path as this will remove the dependency on the drive being mapped at all.

So, instead of xcopy targetting "h:\email" target "\\servername\%username%\email".

Lastly, I don't see any value in running the script from the local PC (d:\mailback.bat). At the moment, you have a script in the GPO which checks for another script on the PC to run. That gives you an admin headache should you want to update the batch file on all those PCs.

So, instead, just have the mailback.bat in your GPO. Here's my edited version:
Code:
echo %Date% %Time% >> d:\email\mailback.log
xcopy d:\email\*.* \\yourservername\%username%\email /s /e /v /y /d /f >> d:\email\mailback.log
echo %Date% %Time% >> d:\email\mailback.log

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Hi Jeffery,

Noted and Thank you.

Will modify the batch file and test it.

With regards,
SC Moh
 
i have script order in GPO is not configured (shown in the gpresult under scripts, logoff).

what should i do to script order in GPO?

Please advise.

with regards,
SC Moh
 
Are you saying your GPO now has more than one script?

To make them run in the order you want:
[ul]1 Open up the GPO to edit it.
2 Drill down to the 'Logoff' option under User Configuration/...(etc).../Scripts and double-click on it.
3 Use the 'Up' and 'Down' buttons to place them in the order you want (top one runs first).
[/ul]

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
i only have one scripts in the "Logoff" option.

Wednesday, i installed admin pack (according to one of the url in the forums) to Windows 7 prof. and now the scripts (or batch is able to execute during shutdown).

Thank you so much for your help.

with regards,
SC Moh
 
Good to hear it's all working.

Give me a star! :)

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top