Quantcast
Channel: Randy Riness @ SPSCC aggregator
Viewing all articles
Browse latest Browse all 3015

MSDN Blogs: Script to run MAPI executable at logon via GPO

$
0
0

 

The script below allows you to run a MAPI executable at logon via GPO. It detects the office version and bitness and it runs the exe version matching the bitness of Outlook.

The syntax to use is the following:

RunExe.vbs ROOT_FOLDER  EXE_NAME  PARAMETERS  RUN_OPTION_RERUN

For example, presuming I’ve stored the 32 bit version of an executable in \\CONDC-01\Netlogon\Myexe\x86 and the 64 bit version in \\CONDC-01\Netlogon\Myexe\x64 and the executable name is myexe.exe, to run the executable once and prevent future executions you would use the following syntax:

RunExe.vbs “\\CONDC-01\Netlogon\Myexe” “Myexe.exe” “param1 param2 param3” false

If your parameters contain quotes, please replace them with apostrophes “’”. For example instead of “param1 “C:\Temp”” use “param1 ‘C:\temp”"’”


Dim checkpoint, OfficeVersion, OfficeBitness, ServerSIPUri, PublicMeeting, strDirectory, objFSO, objFSOText, objFolder, objFile, strBitness
strDirectory = WScript.Arguments(0)
strExeName = WScript.Arguments(1)
strArguments = Replace(WScript.Arguments(2),Chr(39), Chr(34))
boolRerun = CBool(WScript.Arguments(3))
Const HKEY_CLASSES_ROOT    = &H80000000
Const HKEY_CURRENT_USER    = &H80000001
Const HKEY_LOCAL_MACHINE   = &H80000002

Function GetOfficeVersion
    strTempKeyPath = "Outlook.Application\CurVer"
    strTempValueName = ""
    oReg.GetStringValue HKEY_CLASSES_ROOT, strTempKeyPath, strTempValueName, strValue
    If (Not IsNull(strValue)) Then
        Select Case strValue
               Case "Outlook.Application.16"
                   GetOfficeVersion = "16.0"
            Case "Outlook.Application.15"
                      GetOfficeVersion = "15.0"
               Case "Outlook.Application.14"
                   GetOfficeVersion = "14.0"                                                       
        End Select
    End If
End Function

Function GetOutlookBitness
    strTempKeyPath = "SOFTWARE\Microsoft\Office\" & GetOfficeVersion & "\Outlook"
    strTempValueName = "Bitness"
    oReg.GetStringValue HKEY_LOCAL_MACHINE, strTempKeyPath, strTempValueName, strValue
    If (Not IsNull(strValue)) Then
        GetOutlookBitness = strValue
    End If
End Function

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
If (Not boolRerun) then
    strKeyPath = "SOFTWARE\Microsoft\Office\" & GetOfficeVersion & "\Outlook"
    strValueName = "checkpoint"
    oReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
End if
If ((IsNull(strValue)) or (strValue = 0)) Then
    strBitness = GetOutlookBitness
    cmd = strDirectory & "\" & strBitness & "\" & strExeName & " " & strArguments
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run cmd
    If (Not boolRerun) then
        oReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, 1
    End if
End If   
Set oReg = Nothing



Viewing all articles
Browse latest Browse all 3015

Trending Articles