Solved

Script to Copy Word Normal.Dotm File

Posted on 2014-09-19
3
147 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now