#31206 - 2002-10-22 03:23 PM
Re: Help with WriteProfileString
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you want to write a file of computer names:
computer1 computer2 computer3 etc...
Use WriteLog2() in the UDF Library as step #1 in your logon script.
WriteLog2("\\server\share\@wksta.","")
Then use this code to gather up all the filenames and write them to a file after some period of time. this will let all the computers create a file.
code:
$Files=WshPipe("%comspec% /c dir /s /b \\server\share",1) for each $file in $Files WriteLog2("c:\computers.txt",$file) next
WSHPIPE is a UDF that you can find in the UDF Library also.
This is almost exactly what you need. code:
WriteLog2("c:\data\scripts\fasttrack\@wksta","") $Files=WshPipe("%comspec% /c dir /s /b c:\data\scripts\fasttrack",1) for each $file in $Files $file = substr($file,instrrev($file,"\")+1) ? $file next
;Function WshPipe() ; ;Author Christopher Shilt (christopher.shilt@relizon.com) ; ;Version 1.1 ; ;Version History ; ; 14 June 2002 Version 1.1 ; Removed ReadAll Function and incorporated it into WshPipe. Added ; $WshErrorMsg to return the actual error message generated by the ; shelled command. ; ; 14 June 2002 Version 1.0 ; ;Action Performs a shell-like command and pipes the output to an array and returns the ; exitcode of the command to the @error macro. ; ;Syntax WshPipe(COMMAND, optional NOECHO) ; ;Parameters ; COMMAND : REQUIRED. The "shell" command you want to perform. ; ; NOECHO : OPTIONAL. Suppress the command's output to the screen, ouput ; is still stored in an array. ; ;Remarks ; ; ;Returns Output of shell command in an array, exitcode of the command in the @error ; macro, and the error message of the command to $WshErrorMsg. By default, the output ; is echoed to the screen but can be suppressed. ; ;Dependencies KiX 4.02 ; WSH 5.6 (Included with Microsoft Internet Explorer 6.0. Also available for download ; from Microsoft's MSDN website.) ; ;Example: ; ; Display all KiX files in C:\ directory: ; $rc=WshPipe("%comspec% /c dir c:\*.kix") ; ? "Exit Code: " @error " " $WshErrorMsg ; ; ; Display all KiX files in C:\ directory, but suppress output to screen: ; $rc=WshPipe("%comspec% /c dir c:\*.kix",1) ; ? "Exit Code: " @error " " $WshErrorMsg ; ; ; Display all KiX files in C:\ directory, suppress output to screen. Then use FOR/NEXT ; ; to exclude data. ; $rc=WshPipe("%comspec% /c dir c:\*.kix",1) ; for each $line in $rc ; if not instr($line, "File Not Found") ; ? $line ; endif ; next ; ? "Exit Code: " @error " " $WshErrorMsg ; ;Source Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode $WshErrorMsg="" $WshShell=CreateObject("WScript.Shell") $oExec=$WshShell.Exec($ShellCMD) While $Exit<>1 Dim $Output Select Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll $WshErrorMsg = $Output Case 1 $Output=-1 EndSelect If $Output=-1 If $oExec.Status=1 $Exit=1 Endif Else If $NoEcho<>1 ? $Output Endif $AllOutput = $AllOutput + $Output Endif Loop $WshExitCode=$oExec.ExitCode $WshPipe=split($AllOutput,chr(10)) Exit($WshExitCode) EndFunction
;-------------------------------------------------------------------------------------------------- ;FUNCTION WriteLog2() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;ACTION Generic logging facility for scripts. Appends log entry to a file with an ; optional TimeStamp. ; ;SYNTAX WriteLog2($File, $text, [0|1]) ; ;PARAMETERS $File (Required) - String value ; $text (Required) - String value ; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0) ; ; ;REMARKS This function writes (appends) an optionally time stamped log entry to the file ; defined in function. This function searches for the first unused file handle, ; open the file, and write the entry. The file handle is then closed. When the ; function is unable to perform its it write the error is displayed in a message box. ; ;RETURNS Nothing ; ;DEPENDENCIES None ; ;EXAMPLES WriteLog2("junk.txt","This is a test") ; WriteLog2("junk.txt","This is a test",0) ; WriteLog2("junk.txt","This is a test",1) ; ; Function WriteLog2($File, $Text, optional $TimeStamp) dim $RC, $File, $text, $FH, $TimeStamp $FH=1 $RC=Open ($FH, $File, 5) while $RC = -3 $FH=$FH +1 $RC=Open ($FH, $File, 5) Loop Select Case $RC=0 if ($TimeStamp=1) $TimeStamp = @Date + " " + @Time + " - " else $TimeStamp = "" endif $RC=Writeline ($FH, $TimeStamp + $Text + @CRLF) $RC=Close ($FH) Case $RC=-2 $text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File." $RC=MessageBox ($text,"Script Error",48) Case $RC=-1 $text = "WriteLog2: Invalid file name ($File) specified for log file." $RC=MessageBox ($text,"Script Error",48) Case $RC=>0 $text = "System Error($RC) while attempting to open log file ($File)." $RC=MessageBox ($text,"Script Error",48) Endselect EndFunction ;--------------------------------------------------------------------------------------------------
code:
[ 22. October 2002, 15:32: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|