Page 1 of 1 1
Topic Options
#114349 - 2004-02-19 12:21 PM Changing registry key for smtp server. ??
juupken Offline
Lurker

Registered: 2004-02-19
Posts: 3
I need a script that can do the following thing:
I there any smtp server configured ? (register)
no --> quit
yes --> is that server xxx.yyyyyyy.zz then change it to aaa.bbbbbbbb.cc
Can anyone help me with this ?


Top
#114350 - 2004-02-19 12:48 PM Re: Changing registry key for smtp server. ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You'll need to supply a bit more information.
1) What are the Windows versions of the client machines that you are checking?
2) What is the software using the SMTP host that you want to change?

If you know which registry key and value you want to change this is an easy task - post the key and value names and we'll show you how to do it.

Top
#114351 - 2004-02-19 02:38 PM Re: Changing registry key for smtp server. ??
juupken Offline
Lurker

Registered: 2004-02-19
Posts: 3
The OS:Win2000 as

Outlook 2000:
[HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\OMI Account
Manager\Accounts\00000001]

name:SMTP server
TYPE:REG-SZ
value:xxx.yyyyyyy.zz

When this 'key' is present it has to be changed to: aaa.bbbbbbbb.cc


Thanx for helping me

Top
#114352 - 2004-02-19 02:45 PM Re: Changing registry key for smtp server. ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
That's easy then:


$sKeyName="HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts\00000001"
$sValueName="SMTP Server"

$sOldServer="xxx.yyyyyyyyyy.zzz"
$sNewServer="aaa.bbbbbbbbbb.ccc"

If ReadValue($sKeyName,$sValueName)=$sOldServer $sIgnore=WriteValue($sKeyName,$sValueName,$sNewServer,"REG_SZ") EndIf



This will obviously only work if the sub-key always ends "0000001".

You may need to use EnumKey() to check each of the keys if it does not remain the same. If you get stuck, post again.

Top
#114353 - 2004-02-19 02:54 PM Re: Changing registry key for smtp server. ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
This slightly more complex version changes the "SMTP server" entry on all accounts.



$sMainKeyName="HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts"
$sValueName="SMTP Server"

$sOldServer="xxx.yyyyyyyyyy.zzz"
$sNewServer="aaa.bbbbbbbbbb.ccc"

$iIndex=0
$sKeyName=EnumKey($sMainKeyName,$iIndex)
While @ERROR=0
If ReadValue($sKeyName,$sValueName)=$sOldServer $sIgnore=WriteValue($sKeyName,$sValueName,$sNewServer,"REG_SZ") EndIf
$iIndex=$iIndex+1
$sKeyName=EnumKey($sMainKeyName,$iIndex)
Loop


Top
#114354 - 2004-02-19 05:23 PM Re: Changing registry key for smtp server. ??
juupken Offline
Lurker

Registered: 2004-02-19
Posts: 3
You were right about the sub-key. It doesn't always ends with: "0000001". it can also be "0000002" enz...

I tried the last script and it doesn't work.
I don't get an error message or something, but the registry settings are not changed.



Top
#114355 - 2004-02-20 12:01 AM Re: Changing registry key for smtp server. ??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, you should change:
Code:
 If ReadValue($sKeyName,$sValueName)=$sOldServer $sIgnore=WriteValue($sKeyName,$sValueName,$sNewServer,"REG_SZ") EndIf


to:
Code:

If ReadValue($sMainKeyName+'\'+$sKeyName,$sValueName)=$sOldServer
$sIgnore=WriteValue($sMainKeyName+'\'+$sKeyName,$sValueName,$sNewServer,"REG_SZ")
EndIf


_________________________
!

download KiXnet

Top
#114356 - 2004-02-20 12:56 AM Re: Changing registry key for smtp server. ??
AndyD Offline
Fresh Scripter
*

Registered: 2001-11-26
Posts: 17
Do be careful with these entries.....windows doesnt seem to re-use the 00000001 etc entries. Make sure you check upto a high enuff value....just because 00000001 doesn't exist, it doesn't mean that 00000002 doesn't exist too.

Clumsily written, but I hope you get the jist
_________________________
AndyD England, UK.

Top
#114357 - 2004-02-20 01:09 AM Re: Changing registry key for smtp server. ??
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Yup...Thats why Richard posted the second version of code which will cycle through every sub key under that primary key.
Top
#114358 - 2004-02-20 08:25 AM Re: Changing registry key for smtp server. ??
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and that's why we have a habit to call kixtart the wonderfull
_________________________
!

download KiXnet

Top
#114359 - 2004-02-20 10:52 AM Re: Changing registry key for smtp server. ??
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

ja, you should change:
Code:
 If ReadValue($sKeyName,$sValueName)=$sOldServer $sIgnore=WriteValue($sKeyName,$sValueName,$sNewServer,"REG_SZ") EndIf


to:
Code:

If ReadValue($sMainKeyName+'\'+$sKeyName,$sValueName)=$sOldServer
$sIgnore=WriteValue($sMainKeyName+'\'+$sKeyName,$sValueName,$sNewServer,"REG_SZ")
EndIf







Oops. My bad. Thanks Lonk.

Straight from brain to post without an intervening test

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org