VB script outlook and filesite

I have this script where it check to see if outlook is installed then it doesn't do anything.. But if outlook hasn't been run it then runs outlook to create a profile then closes reopenes then adds in an outlook.prf file closes outlook then adds in a third party application.

The third party application needs outlook to be installed first before being add in.

The problem I have is on line 41
Error is Argument not optional wscript.getobject

Can anyone help... Sorry I'm only new at scripting.

Dim objNetwork, strUserName, WshShell, lServer, strDirectory, objFSO
Dim objShell, objOutlook, objGetOutlook, sOutlookVersion 
' Create Outlook object and Shell object 
Set objOutlook = CreateObject("Outlook.Application")
Set objGetOutlook = GetObject(, "Outlook.Application")
Set objShell = CreateObject("WScript.Shell") 
'Get logged on user's name
Set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName
'Get user's logon server
Set WshShell = WScript.CreateObject("WScript.Shell")
lserver = WshShell.ExpandEnvironmentStrings("%logonserver%")
'See if the user needs Outlook configured
strDirectory = "C:\Documents and Settings\" & strusername & "\Application Data\Microsoft\Outlook"
' Create the various objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Determine outlook version
If objOutlook.Version >= "11.0" And objOutlook.version <= "11.1" Then 
  sOutlookVersion = "11" 
End If 
' Import PRF
If Not objFSO.FolderExists(strDirectory) Then
  Set oShell = CreateObject("WScript.Shell")
  oShell.Run Chr(34) & "C:\Program Files\Microsoft Office\OFFICE" & sOutlookVersion & "\Outlook.exe" & Chr(34) & " /importprf \\servername\IT\Outlook\OutlookProfile.PRF", 1, False
End If
' Sleep for a second to give Outlook enough time to create the profile before we kill it 
WScript.Sleep 5000 'sleep for 5 miliseconds
' Close Outlook , so we can register FileSite
Dim Outlook 'As Outlook.Application 
Set Outlook = Wscript.GetObject (, "Outlook.Application") 
If objGetOutlook Is Nothing Then 
'no need to do anything, Outlook is not running 
  'Outlook running
End If 
Set objoutlook = Nothing
' Sleep for a second to give Outlook enough time to close before we register FileSite
WScript.Sleep 20000 'sleep for 4 seconds
objshell.run("cmd /c ""C:\Program Files\Interwoven\WorkSite\addiman.exe"" servername")

Open in new window

Who is Participating?
wmeerzaConnect With a Mentor Commented:
strange, although i did see a problem on line 6, change it to:
Set objGetOutlook = GetObject("", "Outlook.Application")

if you want to debug it try checking the variables as they are set e.g. put a wscript.echo variablename after the line where it gets set to confirm things are happening where you want it.

e.g. after line 41 put in:
Wscript.Echo objGetOutlook

this will then display the value.

I would also check what you are trying to achive from line 41 onwards, it's confusing me a bit!
I have tested it and it closes outlook.
change line 41 to:
Set Outlook = Wscript.GetObject ("", "Outlook.Application")
gladminsAuthor Commented:
Thank you wmeerza.. That fixed it..

But now I'm getting an error on line 42 saying object required
gladminsAuthor Commented:
Thank you mate.. You have point me in the right direction I just need top fix up the last part.. Basically after outlook has opened and closed and imported in the outlook.prf file is to close again run a third party addin for outlook (its our document management system) then open outlook.
no problem, sounds like your nearly there, as you said, a bit of a tidy up and things should start to look good.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.