Scripts and Mods
Non Exchange user file script
Credit: Forum member Evilgohst
Assuming you have a list of email addresses,
in a single flat file, each line containing the email
address, you can use the below VBS script, in conjunction
with the below batch file. We'll assume DataUser.txt
is the list of email addresses you want to import. The
VBS script below is called TXTImp.vbs
code:
--------------------------------------------------------------------------------
@echo off
SETLOCAL
REM // Nathan Fowler
SET TEMPFILE=%TEMP%\datauser.dat
SET OUTFILE=DataUser.dat
SET INFILE=DataUser.txt
SET SCRIPT=TXTImp.vbs
echo Parsing...
CSCRIPT %SCRIPT% %INFILE% %TEMPFILE%
IF ERRORLEVEL 1 GOTO ERROR
IF NOT EXIST %TEMPFILE% GOTO ERROR
IF NOT EXIST %OUTFILE% GOTO COPYFILE
REM // Be sure at least one address exists in %TEMPFILE%
and it wasn't a bad export.
TYPE %TEMPFILE%|FIND /I "@" && GOTO
COMPARE
REM //COMPARE TEMP AND OUTFILE
:COMPARE
ECHO Comparing %TEMPFILE% and %OUTFILE%
FC /B %TEMPFILE% %OUTFILE% > NUL
IF ERRORLEVEL 1 GOTO COPYFILE
GOTO END
:COPYFILE
echo Copying %TEMPFILE% to %OUTFILE%
COPY %TEMPFILE% %OUTFILE% /Y
DEL %TEMPFILE%
GOTO END
:ERROR
:END
--------------------------------------------------------------------------------
code:
--------------------------------------------------------------------------------
'
' Copyright (c) DataEnter, Michael Kocum 1991-2004
'
' TXTImp.vbs reads SMTP addresses from a flat TXT file
and
' writes them into datauser.dat.
'
' Usage: TXTImp.vbs file
'
'
' Note: datauser.dat is always overwritten and user
defined
' addresses are trashed. And datauser.dat is created
in
' the directory where TXTImp.vbs resides.
'
'
' History:
'
' v1.00 2004-07-14 Created
' v1.01 2004-08-29 Output files as second paramter
'
'Verify that we have a domain
If WScript.Arguments.Count < 1 Then
WScript.Echo "Usage: TXTImp.vbs inputfile outputfile"
WScript.Quit( 1 )
End If
' Create the output file
Dim oFileSystem, oOutFile, lOutFileCreated , szOutFile
Set oFileSystem = WScript.CreateObject( "Scripting.FileSystemObject"
)
lOutFileCreated = False
szOutFile = GetFullDataPath()
' Convert the Domain to a AD path
Dim oData , szLDAPBase , szLDAPQuery , szTXTFile , lOk
' Get the inputfile
szTXTFile = WScript.Arguments( 0 )
' Get the outputfile
If WScript.Arguments.Count >= 1 Then
szOutFile = WScript.Arguments( 1 )
End If
WScript.Echo " File: " & szTXTFile
WScript.Echo "Output: " & szOutFile
WScript.Echo ""
lOk = oFileSystem.FileExists( szTXTFile )
If lOk Then
lOk = ReadTXTFile( szTXTFile )
Else
WScript.Echo "Error: " & szTXTFile &
" does not exist"
End If
If lOutFileCreated Then
oOutFile.Close
End If
'Set errolevel on error
If Not lOk Then
WScript.Quit( 1 )
End If
WScript.Quit( 0 )
'-----------------------------------------------------------------------------
Function ReadTXTFile( ByVal szTXTFile )
On Error resume Next
Dim hSource
set hSource = oFileSystem.OpenTextFile( szTXTFile )
Dim szLine , lOk
lOk = FALSE
Do While hSource.AtEndOfStream <> True
szLine = hSource.ReadLine
szLine = LTrim( szLine )
szLine = RTrim( szLine )
WScript.Echo szLine
If szLine <> "" Then
lOk = AppendRecord( szLine , szLine )
If Not lOk Then
Exit Do
End If
End If
Loop
hSource.Close
ReadTXTFile = lOk
End Function
'-----------------------------------------------------------------------------
Function AppendRecord( ByRef szDispName , ByRef szSMTPAddress
)
' #define _SizeDataUserRec 256
' #define _SizeDataUserFree 88 // not used
'
' typedef struct
' {
' BYTE _D01 ;
' BYTE _Deleted[1] ; // Deleted if not Blank
' BYTE _D02 ;
' BYTE _SMTPAddress[128] ; // SMTPAddress
' BYTE _D03 ;
' BYTE _UserName[ 30 ] ; // FullName
' BYTE _D04 ;
' BYTE _Free[_SizeDataUserFree] ;
' BYTE _D05 ;
' BYTE _AutoImport[1] ; // Auto Imported
' BYTE _D06 ;
' BYTE _Chr13 ;
' BYTE _Chr10 ;
' } DataUserRec ;
If Not lOutFileCreated Then
Set oOutFile = oFileSystem.CreateTextFile( szOutFile
, True )
lOutFileCreated = True
End If
Dim szLine
szLine = "| |" & LStr( szSMTPAddress ,
128 ) & _
"|" & LStr( szDispName , 30 ) & _
"|" & space( 88 ) & _
"|" & "*" & "|"
oOutFile.WriteLine szLine
AppendRecord = True
End Function
'-----------------------------------------------------------------------------
Function LStr( ByRef szData , ByVal nLen )
Dim szRet
szRet = szData & space( nLen )
szRet = Left( szRet, nLen )
LStr = szRet
End Function
'-----------------------------------------------------------------------------
Function GetFullDataPath()
' Get the full path from the script and build a
' full filename for datauser.dat
Dim szPath , szScript
szPath = WScript.ScriptFullName
szScript = WScript.ScriptName
' Remove the script name from the full path
szPath = Left( szPath , Len( szPath ) - Len( szScript
) )
GetFullDataPath = szPath & "datauser.dat"
End Function
'-----------------------------------------------------------------------------
--------------------------------------------------------------------------------
[/code]
|