JRA Posted July 3, 2018 Posted July 3, 2018 Morning all - hopefully got that across right in the title, but the long and the short of it is that in some places there (still) Office 2013 and in some others there's (STILL) Office 2010. Before I get onto 2016 over the summer, I'd like to replace a couple of scripts that run at logon and copy shortcuts, but lordy am I bad at VBS. I'd really like a VB script that looks to a PC and sees if Office 2010 is installed, and if so copy some shortcuts from "X" but if Office 2013 is installed copy some other ones instead from "Y". Is that something that's do-able? By people a bit cleverer than me? Thanks for any and all replies and assistance!
sister_annex Posted July 3, 2018 Posted July 3, 2018 I'd take a look at the functions here: https://www.tachytelic.net/2017/10/function-check-file-exists-vbscript/ Then it would just be a case of adding the file path for the word exe: "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE" (obviously this is Office 2016 on a 64bit machine) *There may be easier ways but if you're not good at VBS then this is a good start 1
JRA Posted July 3, 2018 Author Posted July 3, 2018 I'd take a look at the functions here: https://www.tachytelic.net/2017/10/function-check-file-exists-vbscript/ Then it would just be a case of adding the file path for the word exe: "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE" (obviously this is Office 2016 on a 64bit machine) *There may be easier ways but if you're not good at VBS then this is a good start Lol, yes I'm really not and that looks perfect, thanks for that!
JRA Posted July 5, 2018 Author Posted July 5, 2018 (edited) Had another though (which is dangerous if you're me!)Current script has sections, one for each of Word, Excel, Ppt, Publisher thus (third function onwards): Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Calculator.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Paint.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Word 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Excel 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Powerpoint 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Publisher 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next WScript.Quit Would it be possible and/or more graceful to add in a bit at the end of each function that went "If however that link you're copying out the All Programs > Microsoft Office folder isn't there, then try copying this link from the All Programs > Microsoft Office 2013 folder instead. And then if NEITHER are there, stop chirpring about error messages." My best stab is the following, but it's hard to test here unless I do some AD and Group Policy juggling. Does the following look sane to anyone clever? ... Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Word 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt elseif (fso.FileExists(strAllUsersProgramsPath & "\Microsoft Office 2013") Set Set objFolderItem = objFolder.ParseName("Word 2013.lnk") Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt end if Next ... Okay, how bonkers is the above? Sorry if this is painful btw. Edited July 5, 2018 by JRA
3s-gtech Posted July 5, 2018 Posted July 5, 2018 You can do this with GPP, using the Shortcut or File option and using Item Level Targeting with the File Match option. This will be nice and slick, and works very well in my experience. 1
JRA Posted July 5, 2018 Author Posted July 5, 2018 You can do this with GPP, using the Shortcut or File option and using Item Level Targeting with the File Match option. This will be nice and slick, and works very well in my experience. You know I battered away at it for an afternoon and could not for the life of me actually get it to work at all. I wrote it off as "one of those things that just sucks a bit" and went back to the scripts...
3s-gtech Posted July 5, 2018 Posted July 5, 2018 Some people find that with GPP, I rely on it very heavily and it's been great (other than using it for adding printers can be unreliable, but I found the fix for that).
AJWhite1970 Posted July 5, 2018 Posted July 5, 2018 Some people find that with GPP, I rely on it very heavily and it's been great (other than using it for adding printers can be unreliable, but I found the fix for that). Thread hijack Care to share about fixing GPP and printers? Driving me nuts under Windows 10, I've gone back to .vbs distribution which works but doesn't always set the default printer.... Andrew
JRA Posted July 5, 2018 Author Posted July 5, 2018 Hijack away - lol you folks ain't going to want to hear it but GPP printer mapping has worked beautifully for me here and is a glorious trouble-free joy. 100% seriously.
3s-gtech Posted July 5, 2018 Posted July 5, 2018 Thread hijack Care to share about fixing GPP and printers? Driving me nuts under Windows 10, I've gone back to .vbs distribution which works but doesn't always set the default printer.... Andrew My fix was that they weren't reliable when added to a machine OU (i.e. for this group of PCs, use this shared printer). I had to switch to doing them by user (i.e. for students OU, specify all shared printers and use Item Level targeting to target them to the PC that user is using). It is much more reliable, very weirdly - this has been documented elsewhere online which is why I tried it.
JRA Posted July 5, 2018 Author Posted July 5, 2018 My fix was that they weren't reliable when added to a machine OU (i.e. for this group of PCs, use this shared printer). I had to switch to doing them by user (i.e. for students OU, specify all shared printers and use Item Level targeting to target them to the PC that user is using). It is much more reliable, very weirdly - this has been documented elsewhere online which is why I tried it. Yeah that's what we do - guess I lucked out on it. Usually do user policies for users, machine for machine though as habit. 1
LeMarchand Posted July 5, 2018 Posted July 5, 2018 I had to switch to doing them by user (i.e. for students OU, specify all shared printers and use Item Level targeting to target them to the PC that user is using). It is much more reliable, very weirdly - this has been documented elsewhere online which is why I tried it. This is what we do; seems to be fine at my 3 sites. 1
AJWhite1970 Posted July 5, 2018 Posted July 5, 2018 This is what we do; seems to be fine at my 3 sites. @LeMarchand remind me to pick your brains about this when I see you in a couple of weeks Thread tangent over, sorry everyone, as you were.....
LeMarchand Posted July 5, 2018 Posted July 5, 2018 @LeMarchand remind me to pick your brains about this when I see you in a couple of weeks Thread tangent over, sorry everyone, as you were..... I'll try... 1
JRA Posted July 5, 2018 Author Posted July 5, 2018 Oh yeah, that script I was doing... Does anyone know how I might go about knocking that into shape?
Bedders Posted July 5, 2018 Posted July 5, 2018 A simple way to get the current version: Function GetVersion() As Long GetVersion = Application.Version End Function Source: https://www.techrepublic.com/blog/microsoft-office/use-vba-to-return-the-current-version-number-of-any-office-application/ 1
gshaw Posted July 5, 2018 Posted July 5, 2018 This is what we do; seems to be fine at my 3 sites. @LeMarchand are you running Windows 10 and Wi-Fi with it out of interest? Had GPP set up for printers as part of our 10 migration but found it to be unreliable, printers mapping every second login and suchlike. With constantly changing users and short-lived profiles it wasn't stable enough and caused complaints during the pilot roll out. Ended up going a bit retro and using GPO Deployed Printers, which map under the Computer rather than User session and seem to be working better. Only downside being that setting default printer needs to be done via script but I've done a really nifty VBS for that, so far so good if a slightly less friendly method to admin. 1
LeMarchand Posted July 5, 2018 Posted July 5, 2018 @LeMarchand are you running Windows 10 and Wi-Fi with it out of interest? WiFi yes, W10 no (at least that people would see a problem on). The only W10 machines are my desktops at the 2 sites I have an office. Will check 'em tomorrow (as I hardly ever print). One of those 2 has a trolley of W10 convertibles and I'll check the one I have with a damaged screen in my office. The kids use them for "research" so no-one tends to use them to print from.
JRA Posted July 9, 2018 Author Posted July 9, 2018 Okay, getting back to it and cack-handing my way through it, I've encased the lot in two 'if' statements that *should* work. I guess working 'ugly' is still working! Does anyone have any opinions on the following? '******************************************************************************************** '* * '* PIN TO START MENU SCRIPT - V2 for 2013 and 2010 in harmony * '* writing this SSSUUUCCCKKKEEEDDD.* '* * '******************************************************************************************** If exist fso.FileExists "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" Then Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Calculator.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Paint.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Word 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Excel 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Powerpoint 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Microsoft Publisher 2010.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next ElseIf exist fso.FileExists "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE" Then Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Calculator.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Paint.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office 2013") Set objFolderItem = objFolder.ParseName("Word 2013.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office 2013") Set objFolderItem = objFolder.ParseName("Excel 2013.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office 2013") Set objFolderItem = objFolder.ParseName("PowerPoint 2013.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") Set objFolderItem = objFolder.ParseName("Publisher 2013.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next WScript.Quit
sister_annex Posted July 10, 2018 Posted July 10, 2018 Tidied it up a bit for you* Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path PinToStart("Accessories","Calculator.lnk") PinToStart("Accessories","Paint.lnk") If exist fso.FileExists "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" Then PinToStart("Microsoft Office","Microsoft Word 2010.lnk") PinToStart("Microsoft Office","Microsoft Excel 2010.lnk") PinToStart("Microsoft Office","Microsoft Powerpoint 2010.lnk") PinToStart("Microsoft Office","Microsoft Publisher 2010.lnk") end if If exist fso.FileExists "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE" Then PinToStart("Microsoft Office 2013","Word 2013.lnk") PinToStart("Microsoft Office 2013","Excel 2013.lnk") PinToStart("Microsoft Office 2013","Powerpoint 2013.lnk") PinToStart("Microsoft Office 2013","Publisher 2013.lnk") end if sub PinToStart(Folder as string, Link as string) Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\" & Folder) Set objFolderItem = objFolder.ParseName(Link) Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next end sub *not tested it however 2
JRA Posted July 10, 2018 Author Posted July 10, 2018 You're very very VERY kind, thanks muchly! I'll have a bravery pill later and throw the switch... Thanks again!
JRA Posted July 31, 2018 Author Posted July 31, 2018 Hi - thanks over again first off for the help. It objects to parentheses in the sub though. I'm not clever enough to know what to do to remove the parentheses you see! Just thought I'd ask if you had chance for a fiddle with it. Very grateful still.
Knil92 Posted August 31, 2018 Posted August 31, 2018 (edited) 'ObjectsSet fso = CreateObject("Scripting.FileSystemObject")Set shl = CreateObject("WScript.Shell")'I would check if the newer version exists firstpath="C:\Path to the windows\" exists = fso.FolderExists(path)if (exists) then set objFso=createObject("scripting.fileSystemObject")set objWShell=wScript.createObject("WScript.Shell")usrName=objWShell.expandEnvironmentStrings("%USERNAME%")strFileToCopy="C:\Path to the shortcut to copy\"strFolder="C:\Documents and Settings\"&usrName&"\Desktop"if objFso.folderExists(strFolder) thenobjFso.copyFile strFileToCopy,strFolder&"\",trueend ifend if'check if the older version existspath="C:\Path to the windows\"exists = fso.FolderExists(path)if (exists) then set objFso=createObject("scripting.fileSystemObject")set objWShell=wScript.createObject("WScript.Shell")usrName=objWShell.expandEnvironmentStrings("%USERNAME%")strFileToCopy="C:\Path to the shortcut to copy\"strFolder="C:\Documents and Settings\"&usrName&"\Desktop"if objFso.folderExists(strFolder) thenobjFso.copyFile strFileToCopy,strFolder&"\",trueend ifend if Check.txt Added as an attachment because the code tags kept loosing the formatting Something like this should work. It checks to see if a directory exists and then if it does, copies a shortcut the the desktop. Test it first before deploying it first though Edited August 31, 2018 by Knil92 1
JRA Posted September 17, 2018 Author Posted September 17, 2018 Thanks to all the people who chipped in and helped. You've pointed me far enough towards the solution to get me working! I ended up writing a script that stuck the first two shortcuts up, then if the Office14 folder was there run one script, and the Office15 folder runs a different one from a couple of 'If' statements. Thanks again all.
caffrey Posted September 17, 2018 Posted September 17, 2018 Be careful with the pinning, when I upgraded to office 2016 I couldn't easily get rid of the 2010 pinned items for some reason I wonder if this script can be modified to add it to "C:\Users\%%a\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\Startmenu" instead
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now