Page 1 of 1 1
Topic Options
#7765 - 2001-03-28 01:28 AM Sending a string to a text file?
Anonymous
Unregistered


Hi! First place I've worked at where Kixtart is used, so I'm stumbling along. My goal is to have an automated uninstall of McAfee at logon. I've got the uninstall part worked out for 99% of our users, but the remaining few have older versions of McAfee that will require a different approach. Part of the uninstall sends a log file to a server to log errors. However, if the version is incorrect, there is no uninstall and no logging. I want to include a script that checks version of McAfee and appends this, along w/ computer name, to a separate file on a server. The problem I am having is with writeline. Can anyone give me an idea how I could take the results from each check and send it to a file,like this:

somecomputer, 4.5.496.0
anotherone, 4.3.021

etc? I need the info to be stored to one file on 1 network server, and appended as different machines log on. I looked through writeline and can't figure it out. This is what I have so far:


DIM $vsver ; local variable for storing McAfee version

$vsver = getfileversion ("c:\program files\network associates\virusscan\vshwin32.exe")

shell "msiexec /x {63CB7620-B423-4BF1-A7E4-75BB8B64740E} /q /lwe \\myserver\test\%computername%.txt"

Thanks for any help!

[This message has been edited by srpoage (edited 28 March 2001).]

Top
#7766 - 2001-03-28 02:47 AM Re: Sending a string to a text file?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
AFAIK there are 4 ways to write info to a file in KiX:

1. KiX functions OPEN, WRITELINE, CLOSE

; first, delete the file if it exists
; this is because KiX will append by default. If you want to append, remove this DEL line.
del "filename"

; open the file for write access.
; The 1 is the file handle, all future operations on this file will be done via this handle
; The 5 is 1 + 4: 1=Create file if it does not exist and 4=open file for write access
$nul=open(1, "filename", 5)

; write workstation name and $vsver to our text file
; the chr(13)+chr(10) is CR/LF. If you intend to use this more than once in a script, create a $variable for it instead
$nul=writeline(1, @wksta+", "+$vsver+chr(13)+chr(10))

; now close the file
$nul=close(1)


2. KiX function REDIRECTOUTPUT

; This will redirect most screen writes to the file instead of the screen. This is basically KiX's version of >file in DOS.
; The 1 is overwrite, change this to 0 to append
$nul=RedirectOutput("filename", 1)

; now just write the info to the screen with ? for CR/LF
@wksta ", " $vsver ?

; turn off redirection by assigning a blank filename
$nul=RedirectOutput("")


3. S(h)elling out to DOS

; This will use DOS's > redirect command to send info that would normally echo to the screen, to a file instead.
shell "%comspec% /c echo @wksta, $vsver> filename"


4. OLE/VBS external code calls. NT only!

; create file for writing
$fText=val("&"+olecallfunc(olecreateobject("Scripting.FileSystemObject"), "CreateTextFile", "s", "filename"))

; write a line to the file
$nul=olecallfunc($fText, "WriteLine", "s", @wksta+", "+$vsver)

; close the file
$nul=olecallfunc($fText, "Close")


The $nul= is used because that KiX function returns a value. If you remove it, you will see lots of zeros while the script runs. If there is a bul in the script, remove them and look for non zeros.

Hope this helps and if you find another file write method, let me know. I will post another message soon with speed test results of the four methods...


cj

------------------
For more scripts goto my website and click the hammer and spanner icon.

chrismat@ozemail.com.au

Top
#7767 - 2001-03-28 03:17 AM Re: Sending a string to a text file?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
5. SendKeys and Notepad. NT only!

; clear the screen
cls

; write your string to the screen
@wksta ", 123.45.67" ?

; use sendkeys to select all of the text on the screen (should be only one line) and put it on the clipboard
$=sendkeys("~ es{enter}")

; run notepad
run "notepad"

; wait until notepad has finished loading and has focus
while setfocus("Untitled - Notepad")<>0 loop

; paste the clipboard contents to notepad
; save the file as c:\path\filename.txt
; and exit notepad
$=sendkeys("^v^sc:\path\filename.txt{enter}~{f4}")


cj

 


[This message has been edited by cj (edited 28 March 2001).]

Top
#7768 - 2001-03-28 07:32 PM Re: Sending a string to a text file?
Anonymous
Unregistered


Thanks greatly, CJ! The first example looks like it will do nicely. The way you explained things (like the numbers) helped greatly. However, now I am getting a weird error, which I will post separately. Thanks for the help, and if you can help w/ the new one, it's much appreciated. Sean

Top
#7769 - 2001-03-29 03:06 AM Re: Sending a string to a text file?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Note!!! Bug fix! The OLE/VBS test c:\temp path was missing. If you ran this script before this message was here, you will have 1000 7 byte text files in your current directory.


Speed test results:

Redirect test - 11 sec
OPEN, WRITELINE, CLOSE test - 15 sec
DOS shell test - 31 sec
OLE/VBS External Call test - 21 sec

this is creating 1000 randomly named files.

Here is the code:


WriteFileSpeedTest.KiX

code:

break on cls
; write file speed test


$iCount=1000


$sFilename=""
shell "%comspec% /c time <cr >time.txt" $=open(1, "time.txt") srnd(val(substr(readline(1), 31, 2))) $=close(1)
$iCount " files created by each method." ? ?


"Redirect test..." ?
@time ?
$i=0
do
$sFilename=chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+".tst"
$=redirectoutput("c:\temp\$sFilename", 1)
"Hello" ?
$i=$i+1
until $i=$iCount
$=redirectoutput("")
@time ? ?


"OPEN, WRITELINE, CLOSE test..." ?
@time ?
$i=0
do
$sFilename=chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+".tst"
$=open(1, "c:\temp\$sFilename", 5)
$=writeline(1, "Hello"+chr(13)+chr(10))
$=close(1)
$i=$i+1
until $i=$iCount
@time ? ?


"DOS shell test..." ?
@time ?
$i=0
do
$sFilename=chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+".tst"
shell "%comspec% /c echo Hello> c:\temp\$sFilename"
$i=$i+1
until $i=$iCount
@time ? ?


"OLE/VBS External Call test..." ?
@time ?
$i=0
do
$sFilename=chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+chr(rnd(25)+97)+".tst"
$fText=val("&"+olecallfunc(olecreateobject("Scripting.FileSystemObject"), "CreateTextFile", "s", "c:\temp\"+$sFilename))
$=olecallfunc($fText, "WriteLine", "s", "Hello")
$=olecallfunc($fText, "Close")
$i=$i+1
until $i=$iCount
@time ? ?


"Deleting " $iCount*4 " files..."
del "c:\temp\*.tst"
"done" ? ? quit


cj

 

[This message has been edited by cj (edited 29 March 2001).]

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 735 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.08 seconds in which 0.041 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