# VB Outlook script



## JanTM

I found and slightly modified a script on the net. The purpose of this script is to automatically create an Outlook profile. The idea is that when people in our business move from one computer to another, their profile is automatically created - thus eliminating the need for them to manually input the exchange server name and so on.

The script works! However - it works too well. That is to say that it deletes and creates a new profile every time a users logs on. I only want it to create a profile if non exist.

sort of like:
if profile = exists.
Then stop! :wink: 

So what is missing in this little script?



Code:


Option Explicit
On error resume next
Dim WshShell
Dim onet
Dim strUser
Dim strGroup
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
Set oNet =  WScript.CreateObject("WScript.Network") 
Set WshShell = WScript.CreateObject("WScript.Shell")
wshShell.RegRead "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile"
if err.number <> 0 then
WshShell.RegDelete ("HKCU\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run")
WshShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup\ImportPRF","\\yoda\SYSVOL\sj.local\scripts\SJOutlook.PRF","REG_SZ"
wshShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\UserData","1","REG_DWORD"
end if

Thanks in advance,
JanTM


----------



## pphfl04

*Hello*

Did you ever find a fix for this? If so how do you place this VB script into outlook? 

Thank in Advance!!
Jonathan


----------



## JanTM

Nope... I never solved this  

But I run the script as part of the logon script that runs when users log onto my domain.

Basically I've put the script in a file called outlook.vbs.
Then I've made a txt file in Notepad and entered the line:

call outlook.vbs

Save the .txt file as logon.bat and make sure that file is run when users log on.


----------



## Fr4665

you could query the drive where the profiles are saved and look for the profile

so lets say 
userlogon is what ever the user logs in with or his default profile name should be

userlogon = profile
query
if 
{
profile = query
}
then 
{
gotoend of script
}
else
{
create profile
}

no clue if this is doable in VB and if you can query a database or the outlook folder i know you can in perl and propably could also create a profile


----------



## JanTM

It is exactly something like that I am looking for. Unfortunately I know next to nothing about vb script. I can just copy paste ;-)

But the script could look in the windows registry and check there. If a profile is already there is has made entries into the registry.

I just don't know the syntax...


----------



## Fr4665

JanTM said:


> It is exactly something like that I am looking for. Unfortunately I know next to nothing about vb script. I can just copy paste ;-)
> 
> But the script could look in the windows registry and check there. If a profile is already there is has made entries into the registry.
> 
> I just don't know the syntax...


post on a VB board ? im sure thers some scripters that know how todo it


----------



## TopWop

*VB Outlook Script*

Try this script;


' set Outlook Default profile key even if it does not exist
Dim MSOKey
MSOKey = oWSHShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile")

' determine if a profile has already been setup if not import variables according
If MSOKey = "" Then
oWSHShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup\importPRF", strlogonserver & "\netlogon\Outlook\Outlook.prf", "REG_EXPAND_SZ"
oWSHShell.Regdelete "HKCU\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run"
End If


----------

