Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Boolean operators in Windows Batch Script


  • Please log in to reply
1 reply to this topic

#1 Mirtica

Mirtica

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 PM

Posted 01 August 2016 - 11:18 AM

Hello All!

 

This is my first post on Bleeping Computer, so bear with me. If this should be in a different forum topic, feel free to kindly inform me.  :clapping:  :welcome:

 

I have a question about incorporating boolean operators into this Windows Batch file script. But first I will give you a little background information on this project and what i'm trying to accomplish.

 

First off, this is a script to copy our custom Microsoft Office templates off of our server, into the correct folders within each of our employees computers / local accounts on our domain. We are currently in the process of migrating from MS Office 2013 to the 2016 version. The only piece of the puzzle holding me back from full deployment is getting this script to work properly. I am a bit of a novice with scripting.

 

Here is the script:

ECHO ON

SET filecheck="%APPDATA%\templates-201607.txt"

IF EXIST "%APPDATA%\templates-201607.txt" (EXIT)

ECHO %date% %time% > %filecheck%

IF EXIST "%APPDATA%\Microsoft\QuickStyles\" (

robocopy \\thunder\Databases\Templates\20160421\ %APPDATA%\Microsoft\QuickStyles\ "The Center.dotx" /is >> %filecheck% )

IF EXIST "%APPDATA%\Microsoft\Document Building Blocks\1033\16" (

robocopy \\thunder\Databases\Templates\20160421\ "%APPDATA%\Microsoft\Document Building Blocks\1033\16" "Building Blocks.dotx" /is >> %filecheck% )

IF EXIST "%APPDATA%\Microsoft\Templates\" (

robocopy \\thunder\Databases\Templates\20160421\ %APPDATA%\Microsoft\Templates\ *.potx /is >> %filecheck%

robocopy \\thunder\Databases\Templates\20160421\ "%APPDATA%\Microsoft\Templates\Document Themes" *.thmx /is >> %filecheck%

robocopy \\thunder\Databases\Templates\20160421\ %APPDATA%\Microsoft\Templates\ *.dotm /is >> %filecheck% )

EXIT

The way this script stands right now is functional, HOWEVER, after running a clean install of MS office 2016, I noticed that the folders that are a prerequisite for this script to work properly are not created by the installer. They are only created once the user first time launches some of the MS office 2016 apps. These are: Word, Powerpoint, and Outlook.

 

If the user does not launch the applications prior to the script being ran, the folders will temporarily not exist, causing the script to either result in error or install the templates incorrectly. This will happen the way the script is now, since it runs when the user logs in through group policy.

 

The folders in question here are:

 

- %APPDATA%\Microsoft\QuickStyles\

-%APPDATA%\Microsoft\Templates\

-%APPDATA%\Microsoft\Document Building Blocks\1033\16

 

Now, what i'm looking for help on is how to incorporate the correct boolean operators so that the script checks for these folders EACH TIME the user logs in until the user has launched the applications and the folders exist and the script can finally go ahead and robocopy the files into their locations. My ultimate goal here is to have the script know it needs to wait until the second time it runs at system startup, or whatever number of times it takes for the users to launch the apps, to fully run. I already have IF EXIST statements that check to see if the folders are their, but these will not work for this circumstance i believe. If there is a way, please let me know. If i have to write new statements with different operators, please also let me know. 

 

I appreciate all your help, thank you!  :thumbup2:

 



BC AdBot (Login to Remove)

 


#2 KingDavidlll

KingDavidlll

  • Malware Study Hall Junior
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:43 AM

Posted 01 August 2016 - 06:31 PM

Hey!  Welcome to Bleeping Computer!

 

You're in the right forum.  

 

There are many ways to do this.  You could set up a task that runs on every users log in regardless, and check if the dir exists every time and try copy those files in.  As it seems to be a local file system then it should be very quick if it's already there.  If you are doing hundreds of these tasks on login then it might slow it down.  

 

Another way is to copy that script into a local location on the computer and create a task within the task scheduler for that user (easier to do for all users, however if more than one user is using workstation then should do it per user), to run that script every log in until it works, when it succeeds/all file files are there, then it should delete itself.  Much quicker than the last option, harder to implement.  Another way to do it is to just chuck it within the startup folder of the user and then delete itself when it completes successfully.

 

The Boolean operator for the operation of checking if the dir exists is: IF NOT EXIST.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users