Page 1 of 1 1
Topic Options
#135912 - 2005-03-18 12:56 AM Writeline isn't actually writing a line... ideas?
Georges_K Offline
Getting the hang of it

Registered: 2005-02-17
Posts: 83
Loc: Chino, CA
Hello all,

I'm writing a quick'n'dirty script to gather all printers installed on the clients for a project I'm working on. I wrote this script, and everything seems to be working ok, EXCEPT for actually writing the line with the Writeline command. I checked this script for quite a while, and I can't figure out why Writeline isn't working, maybe someone can see it clearer than me?
Thanks for your assistance.
Below is the code that I got.

Break ON
$prKey = "HKEY_CURRENT_USER\Printers\Settings"
$count = 0
$value = EnumValue($prKey,$count)
Do
if open(1,"c:\kix\printers.txt",6) = 0
$lenValue = Len($value)
$lenTilSlash = InStrRev($value,"\")
$unc = Left($value, InStrRev($value,"\"))
$prLen = $lenValue - $lenTilSlash
$printer = Right($value, $prLen)
? "Working on Printer: "$unc$printer

$line = ReadLine(1)
; if the file doesn't have any data in it, then just write a new line
if $ERROR <> -1
; Otherwise, go ahead and search for that printer to see if it's already in the
list
If InStr($line,$printer)
? "already in the list"
Else
Do
$line = ReadLine(1)
Until @ERROR = -1
EndIf
Else
WriteLine(1,$printer)
EndIf

Else "Something wrong with opening file"
EndIf

$count = $count + 1
$ = Close(1)
$value = EnumValue($prKey,$count)
Until @ERROR = 259

_________________________
Network Specialist
Chino Unified School District

Top
#135913 - 2005-03-18 01:03 AM Re: Writeline isn't actually writing a line... ideas?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Wazzup with the 6 on Open()? You cannot open the file for both read and write. It's one or the other.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135914 - 2005-03-18 01:06 AM Re: Writeline isn't actually writing a line... ideas?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Generally, most people will use an INI file and use ReadProfileString() and WriteProfileString(). I wrote a FAQ on that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135915 - 2005-03-18 01:07 AM Re: Writeline isn't actually writing a line... ideas?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
5 should allow you to write to the file.

Also, don't get in a bad habit of not Dimming your code, you may want to go back at a later date and plug this into a larger script and you might run into issues with scope if other vars have same names.

Top
#135916 - 2005-03-18 01:11 AM Re: Writeline isn't actually writing a line... ideas?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
AFAIK, even a 5 won't let you read AND write! You need to rethink the code and it is more than just DIMming a var or two.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135917 - 2005-03-18 01:17 AM Re: Writeline isn't actually writing a line... ideas?
Georges_K Offline
Getting the hang of it

Registered: 2005-02-17
Posts: 83
Loc: Chino, CA
Thanks for the quick responses guys. yes you're right, I do need to DIM my variables.

As for the Open function, this is the first time I use it, usually I use an INI file. I wasn't aware that you can't open a file for both reading AND writing. I assumed you can, because the documentation said that the mode numbers for the Open function are cumulative. but i guess it doesn't work for 4+2 .... oh well.. I'll figure another way then.
Thanks again,
_________________________
Network Specialist
Chino Unified School District

Top
#135918 - 2005-03-18 03:06 AM Re: Writeline isn't actually writing a line... ideas?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Quote:

Note: These values are cumulative. So if you want to open a file for write access, and create it if it does not yet exist, you should specify 5. Notice, however, that a file can not be opened for read and write access at the same time.





Code:
Break On

Dim $File, $OpenFile, $WL, $CloseFile
$File='C:\TEMP\TEST.TXT'
$OpenFile=Open(1, $File,5)
$WL=WriteLine(1,'Wow my data was written to the file'+@CRLF)
$CloseFile = Close(1)


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 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.055 seconds in which 0.023 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