Page 1 of 1 1
Topic Options
#211188 - 2016-03-09 08:32 PM Overwrite file contents each time it's ran (Inventory Script)
MackMan Offline
Just in Town

Registered: 2016-03-09
Posts: 4
Loc: Kentucky
I have an inventory script I'm using inside Kixtart but I can't get it to overwrite the existing contents of the file, it just adds to it.

There's no need for me to keep stacking this information - any help would be appreciated.

I had it working before with RedirectOutput, but I couldn't figure out how to end that command so it wouldn't run any commands after that so I switched to WriteLine instead.

 Quote:

$rc = Open(1, "\\SERVER\public\IS\kixtartlogs\"+ @WKSTA+".html", 5)

$wmiColl1 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_ComputerSystem ")
$wmiColl2 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_BIOS ")
$wmiColl3 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Printer ")

$rc = WriteLine(1, "<HTML>")
$rc = WriteLine(1, "<BODY>")
$rc = WriteLine(1, "<center>")
$rc = WriteLine(1, "<table border=1>")
$rc = WriteLine(1, "<tr>")
$rc = WriteLine(1, " <th>Full Name</th>")
$rc = WriteLine(1, " <th>UserID</th>")
$rc = WriteLine(1, " <th>IP Address</th>")
$rc = WriteLine(1, " <th>Make</th>")
$rc = WriteLine(1, " <th>Model</th>")
$rc = WriteLine(1, " <th>Serial Number</th>")
$rc = WriteLine(1, " <th>Default Printer</th>")
$rc = WriteLine(1, "</tr>")
$rc = WriteLine(1, "<tr>")
$rc = WriteLine(1, "<td>@FULLNAME</td>")
$rc = WriteLine(1, "<td>@USERID</td>")
$rc = WriteLine(1, "<td>" + @IPADDRESS0)
$rc = WriteLine(1, "</td>")
For Each $wmiObj in $wmiColl1
$rc = WriteLine(1, "<td>" + $wmiObj.Manufacturer)
$rc = WriteLine(1, "</td>")
$rc = WriteLine(1, "<td>" + $wmiObj.Model)
$rc = WriteLine(1, " </td>")
Next
For Each $wmiObj in $wmiColl2
$rc = WriteLine(1, "<td>" + $wmiObj.SerialNumber)
$rc = WriteLine(1, "</td>")
$rc = WriteLine(1, "<td>" + join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),''))
$rc = WriteLine(1, "</td>")
$rc = WriteLine(1, "</tr>")
$rc = WriteLine(1, "</table>")
Next
$rc = WriteLine(1, "<h1>Inventory taken on " + @DATE + " at " + @TIME + ".</h1>")
$rc = WriteLine(1, "</BODY>")
$rc = WriteLine(1, "</HTML>")
$rc = Close(1)


Edited by MackMan (2016-03-09 08:35 PM)

Top
#211189 - 2016-03-09 09:12 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: MackMan]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
just delete the file before opening it
 Code:
$filename = "\\SERVER\public\IS\kixtartlogs\"+ @WKSTA+".html"
Del $filename
$rc = Open(1, $filename, 5)
_________________________
Christophe

Top
#211190 - 2016-03-09 09:14 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: ChristopheM]
MackMan Offline
Just in Town

Registered: 2016-03-09
Posts: 4
Loc: Kentucky
 Originally Posted By: ChristopheM
just delete the file before opening it
 Code:
$filename = "\\SERVER\public\IS\kixtartlogs\"+ @WKSTA+".html"
Del $filename
$rc = Open(1, $filename, 5)


I tried that as well, but the users aren't administrators so it won't let you delete those files even though that have read/write access to the files.

Top
#211192 - 2016-03-09 10:18 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: MackMan]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Here's how RedirectOutput works:
 Code:
$Rc = RedirectOutput($File, 1) ; send output, overwrite file
'blah blah...' @CRLF
; done writing out put
$Rc = RedirectOutput('') ; close the output stream
I use RedirectOutput almost exclusively for logging.. \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211193 - 2016-03-09 10:19 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
BTW - Welcome to KORG!

G-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211194 - 2016-03-09 10:22 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: MackMan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Without the ability to delete the file, your only other option would be to create different file names (possibly based on date/time). If you don't have to have a html file, you could also use INI files.
Top
#211195 - 2016-03-09 10:23 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I never use RedirectOutput, so Glenn may have something there... \:\)
Top
#211196 - 2016-03-09 10:25 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Allen - INI was going to be my recommendation until I saw all the HTML! \:\)

With INI, it's like a database that you can clear, modify, etc.. You might consider INI for maintaining the data and creating the .HTM file in a temp location on demand.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211197 - 2016-03-09 10:38 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
In "columbo" mode now... How about adding this instead of "Del File"?
 Code:
$File = '\\SERVER\public\IS\kixtartlogs\' + @WKSTA + .html'
Shell '%COMSPEC% /c Echo. >' + $File
, then use "4" as the mode instead of "5". This uses the shell to overwrite the file - not sure if it's a write at position 0 or a delete/create - technically.

It works on my machine, but I don't have the same delete restrictions.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211201 - 2016-03-10 08:33 PM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: Glenn Barnas]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
OK, users aren't administrators but they can write data.
I think your problem is not with kix.
it is with permissions.
Users can create files, write in existing file but can't delete files !!!

i am not sure there is a way to truncate a file in kix. So you need to delete file before writing in it.
_________________________
Christophe

Top
#211202 - 2016-03-11 04:22 AM Re: Overwrite file contents each time it's ran (Inventory Script) [Re: ChristopheM]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Have not updated in forever but perhaps some ideas for coding



http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=139295#Post139295



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 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org