Jump to content

Configure UserInfos in Office 2003


Recommended Posts

Hello,

I have written a script, which starts automatically on first logon and set the userinformations (UserName, UserAdress, ...)

I had problems to get out the classnameNN in office 2003, so I always used (Send() or MouseMove().

Is it possible to optimize my script?

Here is my script:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:    German
; Platform:    Windows XP SP2
; Author:        Björn
;
; Script Function:
;   Konfiguriert Office 2003. Trägt Benutzerinformationen ein.
;
; ----------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; Set up our defaults
; ----------------------------------------------------------------------------

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("RunErrorsFatal", 0)
AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("WinTitleMatchMode", 4)


; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
#include <File.au3>

Dim $sLogPath, $benutzername, $initialen, $adresse, $file
$sLogPath = @ProgramFilesDir & "\Word-Konfiguration.log"

$file = FileOpen("l:\autoit\UserInfos.ini", 0)

; Check if file opened for reading OK
If $file = -1 Then
    _FileWriteLog($sLogPath, "UserInfos.ini konnte nicht geöffnet werden")
    Exit
EndIf

$benutzername = IniRead("l:\autoit\UserInfos.ini", @UserName, "UserName", "")
If $benutzername == "" Then
    _FileWriteLog($sLogPath, "Benutzername nicht gefunden")
    Exit
EndIf
$initialen = IniRead("l:\autoit\UserInfos.ini", @UserName, "UserInitial", "")
If $initialen == "" Then
    _FileWriteLog($sLogPath, "Initialen nicht gefunden")
    Exit
EndIf
$adresse = IniRead("l:\autoit\UserInfos.ini", @UserName, "UserAdress", "")
if $adresse == "" Then
    _FileWriteLog($sLogPath, "Adresse nicht gefunden")
    Exit
EndIf


Run(@ProgramFilesDir & "\Microsoft Office\OFFICE11\WINWORD.EXE", @ProgramFilesDir & "\Microsoft Office\OFFICE11\")

BlockInput(1)
WinWait("Benutzername", "", 120)
If WinExists("Benutzername") Then
    WinActivate("Benutzername", "")
    sleep(500)
    Send("{Enter}")
    sleep(500)
    _FileWriteLog($sLogPath, "Benutzername erschienen")
Else
;_FileWriteLog($sLogPath, "Benutzername nicht erschienen")
EndIf

WinWait("Dokument1 - Microsoft Word", "", 120)
If WinExists("Dokument1 - Microsoft Word") Then
    WinActivate("Dokument1 - Microsoft Word", "")
    Send("!x")
    sleep(500)
    Send("O")
    _FileWriteLog($sLogPath, "Dokument1 - Microsoft Word erschienen")
    WinWait("Optionen", "", 60)
    If WinExists("Optionen") Then
    ; Registerkarte "Benutzerinformationen" selektieren
        sleep(1000)
        MouseMove(400, 40)
        MouseClick("left")
        sleep(1000)
        ControlSetText("Optionen", "", "RichEdit20W1", $benutzername)
        ControlSetText("Optionen", "", "RichEdit20W2", $initialen)
        ControlSetText("Optionen", "", "RichEdit20W3", $adresse)
        sleep(2000)
        Send("{Enter}")
        _FileWriteLog($sLogPath, "Optionen erschienen")
        sleep(500)
        WinClose("Dokument1 - Microsoft Word")
        WinWait("Microsoft Office Word", "", 30)
        If WinExists("Microsoft Office Word") Then
            sleep(2000)
            WinActivate("Microsoft Office Word", "")
            sleep(500)
            Send("{TAB}")
            sleep(500)
            Send("{Enter}")
            sleep(500)
            _FileWriteLog($sLogPath, "Microsoft Office Word erschienen")
        Else
        ;_FileWriteLog($sLogPath, "Microsoft Office Word nicht erschienen")
        EndIf
    Else
        _FileWriteLog($sLogPath, "Optionen nicht erschienen")
    EndIf
Else
;_FileWriteLog($sLogPath, "Dokument1 - Microsoft Word nicht erschienen")
EndIf

BlockInput(0)

Remember:

The script works on the first start of office. So there is no profile for office.

The "WinWait("Microsoft Office Word", "", 30)" exists, because the user have no writable access to the normal.dot

Thanks,

Björn

Link to comment
Share on other sites

...

Remember:

The script works on the first start of office. So there is no profile for office.

The "WinWait("Microsoft Office Word", "", 30)" exists, because the user have no writable access to the normal.dot

Thanks,

Björn

<{POST_SNAPBACK}>

Hello Bjön,

I don't want to offend you, but with this script you could do exactly the same:

; Set userinformation in Microsoft Word
;
; See also Word VBA Helpfile: Application Object -> properties
;
$oWord=ObjCreate("Word.Application")   ; Create an instance of Word
$oWord.Username="Benutzername"       ; Name
$oWord.Userinitials="I.N.I."           ; Initialen
$oWord.UserAddress="Adresse"           ; Addresse
$oWord=""                             ; Release Word

However, it will only work in the BETA version of AutoIt3.

Regards,

-Sven

Link to comment
Share on other sites

Hello Sven,

thank you for your answer.

But:

Is it a VB-Script or autoIt-Script? It seems to be an vb-script.

I don't understand this line:

$oWord=""                              ; Release Word

If this is an vb-script, is this code complete?

Thanks,

Björn

Link to comment
Share on other sites

Hello Sven,

thank you for your answer.

But:

Is it a VB-Script or autoIt-Script? It seems to be an vb-script.

I don't understand this line:

If this is an vb-script, is this code complete?

Thanks,

Björn

<{POST_SNAPBACK}>

Björn,

The example IS a working AutoIt script. If you download the latest AutoIt3 beta from http://www.autoitscript.com/autoit3/files/beta/autoit/ and run this script you will see the result in the Word Tools->Options-> Userinformation window.

The last line in the script is not really required. MS-Word will automatically be closed when the script exits. See in the AutoIt3 help file: Chapter: Function Reference->Obj/COM Reference.

By the way: you don't HAVE to use this solution..

Regards,

-Sven

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...