GPO .bat file not working logoff/shutdown delete files and folderBatch file to delete files older than N daysWindows batch files: .bat vs .cmd?How do I shutdown, restart, or log off Windows via a bat file?How to run multiple .BAT files within a .BAT fileWindows 7 Group Policy Editor- shutdown batch file not executingneed subroutine batch file to ask to prompt to copy each individual file in a folder but it stays on a continuous loopWant six instances of command prompt window to be running at any point of time unless all the 100 commands are completedSelf-deleting batch file to delete a directory not fully deleting and not exiting on Windows 7sending user login data to c# script then to mySql then to php/html for displayShutdown script via GPO displays unwanted window

Can SQL Server create collisions in system generated constraint names?

Discriminated by senior researcher because of my ethnicity

Re-entry to Germany after vacation using blue card

Overlay of two functions leaves gaps

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

How to fry ground beef so it is well-browned

How does Captain America channel this power?

What term is being referred to with "reflected-sound-of-underground-spirits"?

Mistake in years of experience in resume?

Can we say “you can pay when the order gets ready”?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

How to pronounce 'c++' in Spanish

Why do games have consumables?

What happened to Captain America in Endgame?

How would 10 generations of living underground change the human body?

Can I criticise the more senior developers around me for not writing clean code?

Is Diceware more secure than a long passphrase?

Could the terminal length of components like resistors be reduced?

What makes accurate emulation of old systems a difficult task?

What happens in the secondary winding if there's no spark plug connected?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

How to have a sharp product image?

How to write a column outside the braces in a matrix?

Why does nature favour the Laplacian?



GPO .bat file not working logoff/shutdown delete files and folder


Batch file to delete files older than N daysWindows batch files: .bat vs .cmd?How do I shutdown, restart, or log off Windows via a bat file?How to run multiple .BAT files within a .BAT fileWindows 7 Group Policy Editor- shutdown batch file not executingneed subroutine batch file to ask to prompt to copy each individual file in a folder but it stays on a continuous loopWant six instances of command prompt window to be running at any point of time unless all the 100 commands are completedSelf-deleting batch file to delete a directory not fully deleting and not exiting on Windows 7sending user login data to c# script then to mySql then to php/html for displayShutdown script via GPO displays unwanted window






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to create a simple batch file to delete a folder and/or its contents for a user when they logoff or shutdown.



The GPO itself is working and running, I know this because it first creates a .txt document before running the delete commands.



batch file is called "delete.bat"



The GPO first copies over the batch file to C:delete.bat. the GPO does this every time all the time.



it is set to run this file on either shutdown or logoff. right now it only runs on shutdown.



i have several versions of this file



echo.>"C:Usersmyactualnametestyoyo.txt

del "C:Users%username%cpsidata_4*.*" /s /f /q
@RD /S /Q "C:Users%username%cpsidata_4"

exit


.



@echo off
sleep 4
echo.>"C:Usersmyactualnametestyoyo.txt"
sleep 2

set fld=C:Usersmyactualnamecpsidata_4
for /f %%a in ('dir %fld% /b /a-d') do echo del "%fld%%%a"
for /f %%a in ('dir %fld% /b /ad') do echo rmdir /s /q "%fld%%%a%"


.



@echo off
echo.>"C:Usersmyactualnametestyoyo.txt"
@echo off
rem Delete all files and subfolders in directory for temporary files
rem of current user account, but keep the directory itself. Temporary
rem files and subdirectories currently in use are silently ignored.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul

rem Do the same as above for system temporary files directory.
rem This cleanup requires administrator privileges.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul


i also ran some other version which i haven't documented. I've tried hardcoding the file paths for testing and using the %username% wildcard.



on shutdowns it will create the txt file but not on logoffs. and at no time will it delete the files/folders.



the bat files all run fine if manually run.



i am pretty sure the file permissions are good.
however i suspect permissions is what i suspect is the problem.



thanks!!!










share|improve this question

















  • 1





    firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

    – Gerhard Barnard
    Mar 22 at 18:40







  • 1





    If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

    – jwdonahue
    Mar 23 at 0:59











  • So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

    – Jason Dossett
    Apr 1 at 3:02


















0















I am trying to create a simple batch file to delete a folder and/or its contents for a user when they logoff or shutdown.



The GPO itself is working and running, I know this because it first creates a .txt document before running the delete commands.



batch file is called "delete.bat"



The GPO first copies over the batch file to C:delete.bat. the GPO does this every time all the time.



it is set to run this file on either shutdown or logoff. right now it only runs on shutdown.



i have several versions of this file



echo.>"C:Usersmyactualnametestyoyo.txt

del "C:Users%username%cpsidata_4*.*" /s /f /q
@RD /S /Q "C:Users%username%cpsidata_4"

exit


.



@echo off
sleep 4
echo.>"C:Usersmyactualnametestyoyo.txt"
sleep 2

set fld=C:Usersmyactualnamecpsidata_4
for /f %%a in ('dir %fld% /b /a-d') do echo del "%fld%%%a"
for /f %%a in ('dir %fld% /b /ad') do echo rmdir /s /q "%fld%%%a%"


.



@echo off
echo.>"C:Usersmyactualnametestyoyo.txt"
@echo off
rem Delete all files and subfolders in directory for temporary files
rem of current user account, but keep the directory itself. Temporary
rem files and subdirectories currently in use are silently ignored.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul

rem Do the same as above for system temporary files directory.
rem This cleanup requires administrator privileges.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul


i also ran some other version which i haven't documented. I've tried hardcoding the file paths for testing and using the %username% wildcard.



on shutdowns it will create the txt file but not on logoffs. and at no time will it delete the files/folders.



the bat files all run fine if manually run.



i am pretty sure the file permissions are good.
however i suspect permissions is what i suspect is the problem.



thanks!!!










share|improve this question

















  • 1





    firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

    – Gerhard Barnard
    Mar 22 at 18:40







  • 1





    If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

    – jwdonahue
    Mar 23 at 0:59











  • So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

    – Jason Dossett
    Apr 1 at 3:02














0












0








0








I am trying to create a simple batch file to delete a folder and/or its contents for a user when they logoff or shutdown.



The GPO itself is working and running, I know this because it first creates a .txt document before running the delete commands.



batch file is called "delete.bat"



The GPO first copies over the batch file to C:delete.bat. the GPO does this every time all the time.



it is set to run this file on either shutdown or logoff. right now it only runs on shutdown.



i have several versions of this file



echo.>"C:Usersmyactualnametestyoyo.txt

del "C:Users%username%cpsidata_4*.*" /s /f /q
@RD /S /Q "C:Users%username%cpsidata_4"

exit


.



@echo off
sleep 4
echo.>"C:Usersmyactualnametestyoyo.txt"
sleep 2

set fld=C:Usersmyactualnamecpsidata_4
for /f %%a in ('dir %fld% /b /a-d') do echo del "%fld%%%a"
for /f %%a in ('dir %fld% /b /ad') do echo rmdir /s /q "%fld%%%a%"


.



@echo off
echo.>"C:Usersmyactualnametestyoyo.txt"
@echo off
rem Delete all files and subfolders in directory for temporary files
rem of current user account, but keep the directory itself. Temporary
rem files and subdirectories currently in use are silently ignored.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul

rem Do the same as above for system temporary files directory.
rem This cleanup requires administrator privileges.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul


i also ran some other version which i haven't documented. I've tried hardcoding the file paths for testing and using the %username% wildcard.



on shutdowns it will create the txt file but not on logoffs. and at no time will it delete the files/folders.



the bat files all run fine if manually run.



i am pretty sure the file permissions are good.
however i suspect permissions is what i suspect is the problem.



thanks!!!










share|improve this question














I am trying to create a simple batch file to delete a folder and/or its contents for a user when they logoff or shutdown.



The GPO itself is working and running, I know this because it first creates a .txt document before running the delete commands.



batch file is called "delete.bat"



The GPO first copies over the batch file to C:delete.bat. the GPO does this every time all the time.



it is set to run this file on either shutdown or logoff. right now it only runs on shutdown.



i have several versions of this file



echo.>"C:Usersmyactualnametestyoyo.txt

del "C:Users%username%cpsidata_4*.*" /s /f /q
@RD /S /Q "C:Users%username%cpsidata_4"

exit


.



@echo off
sleep 4
echo.>"C:Usersmyactualnametestyoyo.txt"
sleep 2

set fld=C:Usersmyactualnamecpsidata_4
for /f %%a in ('dir %fld% /b /a-d') do echo del "%fld%%%a"
for /f %%a in ('dir %fld% /b /ad') do echo rmdir /s /q "%fld%%%a%"


.



@echo off
echo.>"C:Usersmyactualnametestyoyo.txt"
@echo off
rem Delete all files and subfolders in directory for temporary files
rem of current user account, but keep the directory itself. Temporary
rem files and subdirectories currently in use are silently ignored.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul

rem Do the same as above for system temporary files directory.
rem This cleanup requires administrator privileges.
del /F /Q "C:Users%username%cpsidata_4*" 2>nul
for /D %%D in ("C:Users%username%cpsidata_4*") do rd /Q /S "%%~D" 2>nul


i also ran some other version which i haven't documented. I've tried hardcoding the file paths for testing and using the %username% wildcard.



on shutdowns it will create the txt file but not on logoffs. and at no time will it delete the files/folders.



the bat files all run fine if manually run.



i am pretty sure the file permissions are good.
however i suspect permissions is what i suspect is the problem.



thanks!!!







batch-file command-line windows-10 group-policy gpo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 17:28









Jason DossettJason Dossett

427




427







  • 1





    firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

    – Gerhard Barnard
    Mar 22 at 18:40







  • 1





    If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

    – jwdonahue
    Mar 23 at 0:59











  • So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

    – Jason Dossett
    Apr 1 at 3:02













  • 1





    firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

    – Gerhard Barnard
    Mar 22 at 18:40







  • 1





    If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

    – jwdonahue
    Mar 23 at 0:59











  • So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

    – Jason Dossett
    Apr 1 at 3:02








1




1





firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

– Gerhard Barnard
Mar 22 at 18:40






firstly, you can use %userprofile% instead of the long c:users%username% string.. then to get to the issue. where exactly in GPO did you setup this script? to test which user do in the script echo Test>"%userprofile%test.txt" and then shutdown/logoff then see in which userprofile the file gets created.

– Gerhard Barnard
Mar 22 at 18:40





1




1





If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

– jwdonahue
Mar 23 at 0:59





If it is set to run somefile.bat and the user has .bat files associated with their editor, your script will not run, but the editor will. If you set it to run %comspec% /c somefile.bat, then it should work.

– jwdonahue
Mar 23 at 0:59













So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

– Jason Dossett
Apr 1 at 3:02






So after doing nothing to it while on vacation I came back and it is working. The three people besides myself that make GPOs all say that they made no changes in our environment. Running across the IT depts OU on all computers. Thank you both for your comments I have noted them and will be using both in my next GP that i am writing.

– Jason Dossett
Apr 1 at 3:02













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304932%2fgpo-bat-file-not-working-logoff-shutdown-delete-files-and-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304932%2fgpo-bat-file-not-working-logoff-shutdown-delete-files-and-folder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해