Link to home
Start Free TrialLog in
Avatar of andyjarvis
andyjarvisFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript - hide command prompt window and AD query

Hi

I have been given a script that creates an additional email folder in Outlook when users log on. The script works fine. When a user logs on and the script runs, it displays a command prompt window.

Where and what do I put in the script that hides the command prompt window from appearing?
I also want the script to run for users in a certain AD security group. How can this be done.

Any help would be greatly appreciated.

Thanks



option explicit
on error resume next
 
'*************************************************************************
'***** VARIABLES TO CHANGE - MIMECAST SERVICE HOSTNAMES and PASSWORD *****
'*************************************************************************
 
dim strMCserv1, strMCserv2, pwd
 
strMCserv1 = "service1.mimecast-offshore.com"
strMCserv2 = "service2.mimecast-offshore.com"
 
pwd = "*********"
 
'************************************
'***** Declare variables to use *****
'************************************
 
dim objNetwork, strUser, strDomain, mailAdr, logstream 
 
'variables to create path to dpeloymimecast.exe
Dim sPath, sPath2, sPath3
 
'variables for outlook connector config - service hostnames, password
Dim sCom
 
'variables for use in script - WHSShell and log file creation
Dim objFSO1, WSHShell, strTempDirectory, strFile, objFolder, objFile
 
 'set system object variables 
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("WScript.Shell")
 
'Determine Path to temp directory
strTempDirectory = WSHShell.Environment("Process")("HOMEDRIVE")
'strTempDirectory = "C\temp"
strFile = "\temp\DeployMimecastLog.txt"
 
sCom = """"
 
OpenLog ("DeployMimecastErrorLog.txt")
  
'************************************
'***** Get username and address *****
'************************************
 Err.clear
 
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
LogError strUSer,  err.number, err.description
 
  if err.number <> 0 then
     LogError "GetUserName", err.number, err.description
     
  end If
  
Err.clear
 
strDomain = objNetwork.UserDomain
LogError strDomain, err.number, err.description
 
 
  if err.number <> 0 then
     LogError "GetUSerDomain", err.number, err.description
     
  end If
 
Err.clear
 
mailAdr = GetEmail(strUser, strDomain)
LogError mailAdr, err.number, err.description
 
 
  if err.number <> 0 then
     LogError "CallGetEmailFunction", err.number, err.description
     
  end if
   
'*****************************************************
'*** DETERMINE PATH TO THE DEPLOYMIMECAST.EXE FILE ***
'*****************************************************
Err.clear
 
'check for "Program Files (x86)" first using environment variables
'sPath = WSHShell.environment("Process")("Program Files (x86)")
sPath = "C:\Program Files (x86)"
 
 
'If we cannot find the path to "Program Files (x86)" using 
'environment variables then read registry to obtain info
 
If sPath = "" Then 
  sPath = WSHShell.RegRead ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir") 
End If 
LogError sPath,  err.number, err.description
 
  if err.number <> 0 then
     LogError "GetProgramFiles", err.number, err.description
     sPath = ""
  end if
 
'adding the "Mimecast" path to "Program Files (x86)" - DeployMimecast.exe
'sPath2 becomes the path to DeeployMimecast.exe on the local machine
'THIS ASSUMES THAT THE CONNECTOR HAS BEEN INSTALLED TO THE DEFAULT DIRECTORY
 Err.clear
                                                   
sPath2 = sPath + "\Mimecast\Mimecast Services for Outlook\deploymimecast.exe"
LogError sPath2,  err.number, err.description
 
  if err.number <> 0 then
     LogError "GetMimecastDir", err.number, err.description
     sPath2 = ""
  end if
 
'add parameters after deploymimecast.exe - config for the Outlook connector
 Err.clear
 
'****************************************************************************************
'****** Command used for AD username and no password - end user will enter password *****
'****************************************************************************************
 
'sPath3 = sCom & sPath2 & sCom & Space(1) & sCom & mailAdr & sCom & Space(1) & sCom & strUser & sCom & _
'                               Space(1) & sCom & sCom & Space(1) & sCom & strMCserv1 & sCom & _
'                              Space(1) & sCom & strMCserv2 & sCom
 
'*********************************************************************************
'****** Command used for all local Mimecast logins - no end user interaction *****
'*********************************************************************************
 
sPath3 = sCom & sPath2 & sCom & Space(1) & sCom & mailAdr & sCom & Space(1) & sCom & sCom & _
                               Space(1) & sCom & pwd & sCom & Space(1) & sCom & strMCserv1 & sCom & _
                               Space(1) & sCom & strMCserv2 & sCom
 
LogError sPath3,  err.number, err.description
 
  if err.number <> 0 then
     LogError "BuildMimecastPath", err.number, err.description
    
  end if
 
'**************************************************
'*** EXECUTE DEPLOYMIMECAST.EXE WITH PARAMETERS ***
'**************************************************
 
'execute deploymimecast.exe with all parameters and write ouput to log file
'WSHShell.exec (sPath3) 
 
Dim objShell,objStdOut,strOutput,objTextFile, regAutoUpdate
Const ForAppending = 8
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
 
Err.clear
 
Set logstream = objFSO1.OpenTextFile(strTempDirectory & strFile, ForAppending, True)
 
  if err.number <> 0 then
     LogError "OpenTextFile", err.number, err.description
     logstream = ""
  end if
 
Err.clear
 
Set objShell = WSHShell.exec (sPath3)
 
  if err.number <> 0 then
     LogError "ExecMimecast", err.number, err.description
     objShell = ""
  end if
 
Set objStdOut = objShell.StdOut
strOutput = objStdOut.ReadAll
logstream.writeline ("*************************************************************************")
logstream.writeline Now()
logstream.writeline ("*************************************************************************")
logstream.writeline strOutput
logStream.Close
'WriteLogEntry("this is a test")
 
Err.clear
'*************************************************************
'*** EDIT REGISTRY ENTRIES TO MANIPULATE DEFAULT STETTINGS ***
'*************************************************************
'set registry to enable/disable auto updates - change true/false
regAutoUpdate = WSHShell.RegRead ("HKCU\SOFTWARE\Mimecast\Mimecast Online\Enable Automatic Updates")
If regAutoUpdate = "true" THEN
	regAutoUpdate = WSHShell.RegWrite ("HKCU\SOFTWARE\Mimecast\Mimecast Online\Enable Automatic Updates", "false", "REG_SZ")
End If
 
'set registry to enable/disable auto failover to Mimecast - change true/false
'regAutoFailover = WSHShell.RegWrite ("HKCU\SOFTWARE\Mimecast\Mimecast Online\EnableAutoFailOver", _
'	"true", "REG_SZ")
 
 
 if err.number <> 0 then
     LogError "RegistryWrite", err.number, err.description
    
  end if
 
CloseLog
 
'**************************************************
'*** get users email address from name & domain ***
'**************************************************
 
Function GetEmail(strAccountName, strDomainName)
  
  err.clear
  
  Dim adoLDAPCon,adoLDAPRS,strLDAP
 
  Set adoLDAPCon = CreateObject("ADODB.Connection")
  adoLDAPCon.Provider = "ADsDSOObject"
  adoLDAPCon.Open "ADSI"
  
  strLDAP = "'LDAP://" & strDomainName & "'"
  Set adoLDAPRS = adoLDAPCon.Execute("select mail from " & strLDAP & " WHERE objectClass = 'user'"& " And samAccountName = '" & strAccountName & "'")
  With adoLDAPRS
     If Not .EOF Then
        GetEmail = .Fields("mail")
     Else
        GetEmail = ""
     End If
  End With
 
  adoLDAPRS.Close
 
  if err.number <> 0 then
     LogError "GetEmail", err.number, err.description
     GetEmail = ""
  end if
 
  Set adoLDAPRS = Nothing
  Set adoLDAPCon = Nothing
 
End Function
 
'**************************
'*** logging functions  ***
'**************************
 
sub OpenLog (logfile)
 
 dim fso
 
 set fso = createobject("scripting.filesystemobject")
 set logstream = fso.opentextfile("c:\temp\" & logfile, 8, true)
 
end sub
 
 
sub LogError (location, number, description)
 
  logstream.writeline now() & ": " & "[" & location & "] (" & number & ") " & description
 
end sub
 
 
sub CloseLog
 
  logstream.close
 
end sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kamaraj Subramanian
Kamaraj Subramanian
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyjarvis

ASKER

Resolved
Avatar of montagu
montagu

Andy,
I am running the MSO for outlook also. I have it sortd for a Citrix environmnet but I am having issues with the desktop side. Woudl you share the script you have customized for using with the desktops in your company please? We are running the beta 3.2 in our farm but are waiting for the new release.
Regards Paul