?
Solved

Check if word is installed vb.net

Posted on 2011-10-17
6
Medium Priority
?
472 Views
Last Modified: 2012-05-12
HI,
This script failed on computers with and with out word installed.


Set objNetwork = CreateObject("Wscript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objUnder = GetObject(objUser.Parent)
Set objHoved = GetObject(objUnder.Parent)

strUser = objUser.Get("sAMAccountName")

If Not Type (objword) = "Nothing" Then
Set objWord = CreateObject("Word.Application")

objWord.UserName = objUser.givenName & " " & objUser.SN
objWord.UserInitials = objUser.sAMAccountName
objLogFile.WriteLine "Jobbet er fuldført: " & "Office initialer er rettet."
objWord.Quit
Else
objLogFile.WriteLine "Der blev ikke fundet Word:" & "Ingen rettelser."
End If
0
Comment
Question by:dkjean
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:AmitKB
ID: 36980146
I have modifed the code please take a look.
You will error at the line where "objLogFile" is there becuase it is not created.
Set objNetwork = CreateObject("Wscript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objUnder = GetObject(objUser.Parent)
Set objHoved = GetObject(objUnder.Parent)

strUser = objUser.Get("sAMAccountName")


Set objWord = CreateObject("Word.Application")

If Not objword Is Nothing Then
objWord.UserName = objUser.givenName & " " & objUser.SN
objWord.UserInitials = objUser.sAMAccountName
objLogFile.WriteLine "Jobbet er fuldført: " & "Office initialer er rettet."
objWord.Quit
Else
objLogFile.WriteLine "Der blev ikke fundet Word:" & "Ingen rettelser."
End If

Open in new window

0
 

Author Comment

by:dkjean
ID: 36984096
I get a error in line "set objword = CreateObject("word.Application")
On a machine were there is no word installed.
Yes about the log :-)
0
 
LVL 2

Accepted Solution

by:
AmitKB earned 500 total points
ID: 36984296
Ok I have fixed the Word installation check and I have attached here two fixed code.
I have attached two code do the same stuff but in different way.

Solutio1:
It has a drawback that it won't show you the error after the line "On Error Resume Next"

Solution2:
It set the variable value in a seprate sub.

I am sure it will work.

Set objNetwork = CreateObject("Wscript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objUnder = GetObject(objUser.Parent)
Set objHoved = GetObject(objUnder.Parent)

strUser = objUser.Get("sAMAccountName")

On Error Resume Next
Set objWord = CreateObject("Word.Application")

If Not objword Is Nothing Then
objWord.UserName = objUser.givenName & " " & objUser.SN
objWord.UserInitials = objUser.sAMAccountName
objLogFile.WriteLine "Jobbet er fuldført: " & "Office initialer er rettet."
objWord.Quit
Else
objLogFile.WriteLine "Der blev ikke fundet Word:" & "Ingen rettelser."
End If

Open in new window

Set objNetwork = CreateObject("Wscript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objUnder = GetObject(objUser.Parent)
Set objHoved = GetObject(objUnder.Parent)

strUser = objUser.Get("sAMAccountName")

Dim objWord
SetWordApp

If Not objword Is Nothing Then
objWord.UserName = objUser.givenName & " " & objUser.SN
objWord.UserInitials = objUser.sAMAccountName
objLogFile.WriteLine "Jobbet er fuldført: " & "Office initialer er rettet."
objWord.Quit
Else
objLogFile.WriteLine "Der blev ikke fundet Word:" & "Ingen rettelser."
End If 

Sub SetWordApp()
	On Error Resume Next
	Set objWord = CreateObject("Word.Application")	
End Sub

Open in new window

0
 

Author Comment

by:dkjean
ID: 36984792
Thanks a lot
I did'net work on the machines without word.
But I have use your script with the string.... On error Resume Next
It works.
0
 
LVL 2

Expert Comment

by:AmitKB
ID: 36984817
You can simulate as Word (or any other application not installed) not installed by using following code:
Set objWord = CreateObject("NoWord.Application")

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

749 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