Jump to content

VBS for "If Office 2010 Do This, If Office 2013 Do Something Else"?


Recommended Posts

Posted

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! :)

Posted
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! :)

Posted (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 by JRA
Posted
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.
  • Thanks 1
Posted
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...

Posted
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).
Posted
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

Posted
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.
Posted
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.
Posted
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.

  • Thanks 1
Posted
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.

  • Thanks 1
Posted

Oh yeah, that script I was doing...

 

Does anyone know how I might go about knocking that into shape?

Posted
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.

  • Thanks 1
Posted
@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.

Posted

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

Posted

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

  • Thanks 2
Posted

You're very very VERY kind, thanks muchly! I'll have a bravery pill later and throw the switch...

 

Thanks again! :)

  • 3 weeks later...
Posted

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. :)

  • 5 weeks later...
Posted (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 by Knil92
  • Thanks 1
  • 3 weeks later...
Posted

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. :)

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...