Kevin
asked on
Batch file to delete a folder
Good Afternoon,
I want to write a batch script to delete a directory from a users computer on the network.
I will be running this script from my machine.
So far what I have is below.
The part I am stuck on is line 31 and down. I want the script to remove the directory if it doesnt see the outlook.exe process running. Once the folder is removed I want it to start outlook on the users machine.
Any ideas as to why my else statement is not working?
Kindly advise.
Regards,
N
I want to write a batch script to delete a directory from a users computer on the network.
I will be running this script from my machine.
So far what I have is below.
The part I am stuck on is line 31 and down. I want the script to remove the directory if it doesnt see the outlook.exe process running. Once the folder is removed I want it to start outlook on the users machine.
Any ideas as to why my else statement is not working?
Kindly advise.
Regards,
N
@ECHO OFF
set /P "ComputerName=Input users computer name. Example <computer01>: "
set /P "UserProfile=Input users profile. Example <username>: "
echo.
If Not Exist "\\%ComputerName%\C$\" (
Echo.
Echo ************************ERROR***************************
Echo.
Echo Computer name entered incorrectly or computer is off.
Echo.
Echo ************************ERROR***************************
Echo.
Pause
Goto :End
)
If Not Exist "\\%ComputerName%\C$\Users\%UserProfile%" (
Echo.
Echo ************************ERROR***************************
Echo.
Echo %UserProfile% does not exist on %ComputerName%.
Echo.
Echo ************************ERROR***************************
Echo.
Pause
Goto :End
)
If Exist "\\%ComputerName%\C$\Users\%UserProfile%" (
tasklist /FI "IMAGENAME eq OUTLOOK.exe" 2>NUL | find /I /N "OUTLOOK.exe">NUL
if "%ERRORLEVEL%"=="0" echo Outlook is still running. Tell user to close it completely and restart script.
pause
else goto :DELETEFILES
)
:DELETEFILES
rmdir /S /Q "\\%ComputerName%\C$\Users\%UserProfile%\AppData\Local\Microsoft\Outlook\"
Start "" "\\%ComputerName%\C$\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"
Echo.
Echo ************************SUCESS***************************
Echo.
Echo Outlook files have been removed and Outlook has been launched.
Echo.
Echo ************************SUCESS***************************
Echo.
Pause
Goto :End
:End
ASKER
Somethings wrong.
The script is suppose to check if outlook process is running, if it is, show the messages and go to end. If its not running then it needs to remove the directory and then start up outlook again on the users machine.
I left outlook open on purpose on the test machine and ran the script again.
The script sees outlook open and pauses at the message which is fine. But when i hit enter it tries to remove the directory, obviously it had trouble doing this because outlook was open and that why you see the errors.
Then it opened my outlook on my machine.
See below screenshot when I add your additions.
Kindly advise.
N
The script is suppose to check if outlook process is running, if it is, show the messages and go to end. If its not running then it needs to remove the directory and then start up outlook again on the users machine.
I left outlook open on purpose on the test machine and ran the script again.
The script sees outlook open and pauses at the message which is fine. But when i hit enter it tries to remove the directory, obviously it had trouble doing this because outlook was open and that why you see the errors.
Then it opened my outlook on my machine.
See below screenshot when I add your additions.
Kindly advise.
N
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Open in new window