Solved

Script to Copy Word Normal.Dotm File

Posted on 2014-09-19
3
177 Views
Last Modified: 2015-01-17
Hi I am having an issue, I need to create a script to rename (some users have macros don't want to delete)  the existing copy of Word's Normal.dotm file and copy a new one from a network share. The problem is I need the script to copy one normal file to a specific group, then copy a different normal to everyone else in an AD environment.



I tried using a batch file through sccm doesn't work, tried using file copy through GPO and it doesn't work as well. Thanks experts in advance for your help.
0
Comment
Question by:jaya31
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 40335939
Hi, as an example,
Here is what I use to copy a newer normal.dotm from a server share.
It checks whether the user template on N drive is older than the server copy, will backup up the user copy, then copy over the new version.

Regards,

Rob.

If objFSO.FileExists("\\server\apps\Template\Normal.dotm.new") = True Then
	If CDate(objFSO.GetFile("\\server\apps\Template\Normal.dotm.new").DateLastModified) > CDate(objFSO.GetFile("N:\Normal.dotm").DateLastModified) Then
		intBkpNum = 1
		While objFSO.FileExists("N:\Normal.dotm_bak" & intBkpNum) = True
			intBkpNum = intBkpNum + 1
		Wend
		objFSO.MoveFile "N:\Normal.dotm", "N:\Normal.dotm_bak" & intBkpNum
		objFSO.CopyFile "\\server\apps\Template\Normal.dotm.new", "N:\Normal.dotm"
	End If
End If

Open in new window

0
 

Author Comment

by:jaya31
ID: 40342916
Thank you for you response. This is actually what I am looking for, but I need to do it based on groups in AD\GPO. We have one department that needs  a specific normal while other departments require another. Is there any way to do that
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40345262
Hi, sorry for my delay. I have been quite busy.  This script will now check for the group membership, and set a different Normal template for each group.

Regards,

Rob.

' THIS LINE MUST BE PLACED IN THE MAIN CODE TO ALLOW THE DICTIONARY
' OBJECT TO REMAIN PERSISTENT FOR THE ISMEMBEROFGROUP FUNCTION
Dim objMemberships

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)

If IsMemberOfGroup(objUser, "Group 1") = True Then
	strNormal = "\\server\apps\Template\NormalGroup1.dotm.new"
Else
	strNormal = "\\server\apps\Template\NormalGroup2.dotm.new"
End If
If objFSO.FileExists() = True Then
	If CDate(objFSO.GetFile(strNormal).DateLastModified) > CDate(objFSO.GetFile("N:\Normal.dotm").DateLastModified) Then
		intBkpNum = 1
		While objFSO.FileExists("N:\Normal.dotm_bak" & intBkpNum) = True
			intBkpNum = intBkpNum + 1
		Wend
		objFSO.MoveFile "N:\Normal.dotm", "N:\Normal.dotm_bak" & intBkpNum
		objFSO.CopyFile strNormal, "N:\Normal.dotm"
	End If
End If

Function IsMemberOfGroup(objADUser, strGroupCN)
	If IsEmpty(objMemberships) = True Then
		Set objMemberships = CreateObject("Scripting.Dictionary")
		objMemberships.Add LCase("ALL"), 0
		If IsNull(objADUser.MemberOf) = False Then
			If TypeName(objADUser.MemberOf) = "String" Then
				objMemberships.Add LCase(Mid(Split(objADUser.MemberOf, ",")(0), 4)), 0
			Else
				For Each strGroupName In objADUser.MemberOf
					objMemberships.Add LCase(Mid(Split(strGroupName, ",")(0), 4)), 0
				Next
			End If
		End If
	End If
	If objMemberships.Exists(LCase(strGroupCN)) = True Then
		IsMemberOfGroup = True
	Else
		IsMemberOfGroup = False
	End If
End Function

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 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