fluluk
Goto Top

Nur wenn Office installiert Autosignatur ausführen

Hallo,

ich versuche habe in VBS ein Programm, welches mir eine Autosignatur für Outlook erstellt. Das ganze funktioniert gut, allerdings würde ich dieses gerne in die Gruppenrichtlinien aufnehmen. Da es in unserem Unternehmen jedoch einige PCs gibt, die kein Office installiert haben, liefert mir das Skript einen Fehler.

Das ganze möchte ich gerne für 32 und 64 Bit Clients umgehen.

Nur für 32 Bit habe ich etwas im Internet gefunden:
dim bExists
ssig="Unable to open registry key"  

set wshShell= Wscript.CreateObject("WScript.Shell")  
strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office"  
on error resume next
present = WshShell.RegRead(strKey)
if err.number<>0 then
    if right(strKey,1)="\" then  
        if instr(1,err.description,ssig,1)<>0 then
            bExists=true
        else
            bExists=false
        end if
    else
        bExists=false
    end if
    err.clear
else
    bExists=true
end if
on error goto 0
if bExists=vbFalse then

else
----SIGNATUR----
end if

da die Einträge unter 64Bit in der Registry noch unter Wow6432Node stehen, funktioniert das so nicht.
was muss ich einfügen, dass es auch unter 64-Bit Systemen erkannt wird?
ich habe mich schon mit OR daran gewagt aber so ganz funktioniert das nicht wie ich das will.

Es kann auch gerne ein komplett anderer Code sein der funktioniert.

Danke.

Content-Key: 211007

Url: https://administrator.de/contentid/211007

Printed on: April 16, 2024 at 21:04 o'clock

Mitglied: 76109
76109 Jul 10, 2013 at 06:04:02 (UTC)
Goto Top
Hallo fluluk!

Versuchs mal damit:
Option Explicit

'Backslash am Ende beachten  
Const sReg32Key = "HKLM\Software\Microsoft\Office\"  
Const sReg64Key = "HKLM\Software\Wow6432Node\Microsoft\Office\"  

Dim sOffice32, sOffice64
    
On Error Resume Next
With CreateObject("WScript.Shell")  
    sOffice32 = .RegRead(sReg32Key)
    sOffice64 = .RegRead(sReg64Key)
    
    If IsEmpty(sOffice32) And IsEmpty(sOffice64) Then
        MsgBox "Office nicht installiert"  
    Else
        MsgBox "Office installiert"  
    End If
End With
On error Goto 0

Gruß Dieter
Member: fluluk
fluluk Jul 10, 2013 at 08:07:22 (UTC)
Goto Top
ja, so wird Office schonmal erkannt, wenn ich nun allerdings die MsgBox durch mein Skript ersetze, wird es nicht ausgeführt

Option Explicit

'Backslash am Ende beachten  
Const sReg32Key = "HKLM\Software\Microsoft\Office\"  
Const sReg64Key = "HKLM\Software\Wow6432Node\Microsoft\Office\"  

Dim sOffice32, sOffice64
    
On Error Resume Next
With CreateObject("WScript.Shell")  
    sOffice32 = .RegRead(sReg32Key)
    sOffice64 = .RegRead(sReg64Key)
    
    If IsEmpty(sOffice32) And IsEmpty(sOffice64) Then
        MsgBox "Office nicht installiert"  
    Else
		On Error Resume Next
		Set objSysInfo = CreateObject("ADSystemInfo")  

		Set WshShell = CreateObject("WScript.Shell")  

		strUser = objSysInfo.UserName
		Set objUser = GetObject("LDAP://" & strUser)  

		strName = objUser.FirstName & " " & objUser.LastName  
		strTitle = objUser.Title
		strDepa = objUser.Department
		strCred = objUser.info
		strCompany = objUser.Company
		strStreet = objUser.StreetAddress
		strLocation = objUser.l
		strPostCode = objUser.PostalCode
		strPhone = objUser.TelephoneNumber
		strMobile = objUser.Mobile
		strFax = objUser.FacsimileTelephoneNumber
		strEmail = "mailto:" & objUser.mail  
		strEmail2 = objUser.mail
		strHP = objUser.HomePage
		 




		Set objWord = CreateObject("Word.Application")  

		Set objDoc = objWord.Documents.Add()
		Set objSelection = objWord.Selection

		Set objEmailOptions = objWord.EmailOptions
		Set objSignatureObject = objEmailOptions.EmailSignature

		Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
	 
                                   .
                                   .
                                   .


		Set objSelection = objDoc.Range()

		objSignatureEntries.Add "complete Signature", objSelection  
		objSignatureObject.NewMessageSignature = "complete Signature"  

		objDoc.Saved = True
		objWord.Quit

		Set objWord = CreateObject("Word.Application")  

		Set objDoc = objWord.Documents.Add()
		Set objSelection = objWord.Selection

		Set objEmailOptions = objWord.EmailOptions
		Set objSignatureObject = objEmailOptions.EmailSignature

		Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

                                   .
                                   .
                                   .


		Set objSelection = objDoc.Range()

		objSignatureEntries.Add "Reply Signature", objSelection  
		objSignatureObject.ReplyMessageSignature = "Reply Signature"  

		objDoc.Saved = True
		objWord.Quit

    End If
End With
On error Goto 0
Mitglied: 76109
76109 Jul 10, 2013 at 11:36:09 (UTC)
Goto Top
Hallo fluluk!

Der Fehler liegt wohl in erster Linie daran, dass am Code-Anfang 'Option Explicit' steht und Du keine Variablen per Dim deklariert hast. Also entweder die erste Codezeile entfernen oder die Variablen deklarieren...

Ansonsten würde ich es eher so machen:
Option Explicit

'Backslash am Ende beachten  
Const sReg32Key = "HKLM\Software\Microsoft\Office\"  
Const sReg64Key = "HKLM\Software\Wow6432Node\Microsoft\Office\"  

Dim objShell, strOffice32, strOffice64
    
On Error Resume Next

Set objShell = CreateObject("WScript.Shell")  

With objShell
    strOffice32 = .RegRead(sReg32Key)
    strOffice64 = .RegRead(sReg64Key)
End With
    
If IsEmpty(strOffice32) And IsEmpty(strOffice64) Then
    MsgBox "Office nicht installiert":  WScript.Quit 1  
End If
        
Err.Clear

Set objSysInfo = CreateObject("ADSystemInfo")  

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)  

strName = objUser.FirstName & " " & objUser.LastName  
strTitle = objUser.Title
strDepa = objUser.Department
strCred = objUser.info
strCompany = objUser.Company
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephoneNumber
strEmail = "mailto:" & objUser.mail  
strEmail2 = objUser.mail
strHP = objUser.HomePage
         
Set objWord = CreateObject("Word.Application")  
Set objDoc = objWord.Documents.Add()
        
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
                                   .
                                   .
                                   .
Set objSelection = objDoc.Range()

objSignatureEntries.Add "complete Signature", objSelection  
objSignatureObject.NewMessageSignature = "complete Signature"  

objDoc.Saved = True
objWord.Quit

Set objWord = CreateObject("Word.Application")  

Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
                                   .
                                   .
                                   .
Set objSelection = objDoc.Range()

objSignatureEntries.Add "Reply Signature", objSelection  
objSignatureObject.ReplyMessageSignature = "Reply Signature"  

objDoc.Saved = True
objWord.Quit

If Err.Number Then
    MsgBox "Fehler beim Erstellen der Email-Signaturen ":  WScript.Quit 1  
End If

WScript.Quit 0

Gruß Dieter
Member: fluluk
fluluk Jul 10, 2013 at 12:37:44 (UTC)
Goto Top
ach, vielen Dank, so funktionierts.

Gruß Lukas