Page 1 of 2 12>
Topic Options
#191446 - 2008-12-28 02:37 AM Create a file
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Hi all,

how do I create a file in kix?


thanks

Top
#191448 - 2008-12-28 03:28 AM Re: Create a file [Re: chipped]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See the OPEN/WRITELINE/CLOSE functions in the KiXtart Manual. They contain an example on how to open and close a file and how to write to it.

Edited by Sealeopard (2008-12-28 03:28 AM)
_________________________
There are two types of vessels, submarines and targets.

Top
#191453 - 2008-12-28 07:17 AM Re: Create a file [Re: Sealeopard]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Damn, so you cant create one?
Top
#191454 - 2008-12-28 10:28 AM Re: Create a file [Re: chipped]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Reread the OPEN function.

 Quote:

Action


Opens a text file.



Syntax


OPEN (file handle, "file name", mode)



Parameters


File handle

A numeric expression indicating the file handle of the file to open. Possible values range from 1 to 10.

File name

A string expression indicating the path and name of the ASCII file to open.

Mode

Optional parameter that indicates what should happen if the file does not exist. This parameter can have the following values:




0
If the file does not exist, OPEN fails with return code 2 (default).

1
If the file does not exist, OPEN will create a new file.

2
Opens the file for read access (default).

4
Opens the file for write access.






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.




Remarks


OPEN opens the ASCII file specified by file name, for the internal buffer indicated by file handle. KiXtart supports a maximum of ten open files, so file handle must be within the range of 1 to 10.



Returns




-3
File handle already in use

-2
Invalid file handle specified

-1
Invalid file name specified

0
File opened successfully

>0
System error




Example


IF Open(3, @LDRIVE + "\CONFIG\SETTINGS.INI") = 0

$x = ReadLine(3)

WHILE @ERROR = 0

? "Line read: [" + $x + "]"

$x = ReadLine(3)

LOOP

ENDIF

_________________________
Today is the tomorrow you worried about yesterday.

Top
#191457 - 2008-12-28 09:43 PM Re: Create a file [Re: Gargoyle]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeah.

Using open with 5 as the parameter opens the file for writing and creates it if it does not exist. Then closing it will get you an empty (0KB) file.

 Code:
Break on

$rc = Open(1, "c:\somefile.txt",5)
$rc = Close(1)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#191458 - 2008-12-29 01:55 AM Re: Create a file [Re: Mart]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Genius!! I so missed that, thanks.

This is what I have so far

 Code:
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Checking to see if Install folder exists, if it dosent then it is created.

IF 0=EXIST("C:\install")
       MD "C:\install"
ENDIF

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Installing Programs, the name of each program is writen to a folder as a text file, if the file does not esxist then the program will be installed, if the file exists then the program will not be installed. You can include version numbers in the file name of each program so if you need to you can upgrade.

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Installing Adobe Reader 9.0

IF 0=EXIST("C:\install\AdobeReader9.0.txt")
	Open(1, "C:\install\AdobeReader9.0.txt", 1)
	RUN "\\stingray\share\AdbeRdr90_en_US.exe /update-no /sAll /rs /l /msi"/qb-! /norestart ALLUSERS=1 EULA_ACCEPT=YES SUPPRESS_APP_LAUNCH=YES""
ENDIF

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Unfortunately using RUN wont let me use install switches, is there another method that will let me use switches?


Edited by chipped (2008-12-29 01:56 AM)

Top
#191459 - 2008-12-29 08:59 AM Re: Create a file [Re: chipped]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You can also use Shell.

If you are just using the file to see if acrobat 9 is installed then there is an easier way.

 Code:
Break on

$reader = ReadValue("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe", "")

If Not Exist($reader) or $reader = ""
	;Install reader 9.
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#191460 - 2008-12-29 10:24 AM Re: Create a file [Re: Mart]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
No it will be used to roll out programs to about 300 pc's, the script actually has 9 programs in it. So far.

This way I can add programs to the script, chuck it on the logon file and boot all the pc's before everyone comes in, easy peesy.

Top
#191461 - 2008-12-29 10:33 AM Re: Create a file [Re: chipped]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Ok.

Just one small comment.
You use
 Code:
 If 0 = Exist(bla bla bla)

This works but is a bit weird formatting.


 Code:
If not Exist(bla bla bla)

is a bit easier to follow in my humble opinion.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#191467 - 2008-12-29 01:45 PM Re: Create a file [Re: Mart]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Thanks, did that and its a lot easier to read now.
Top
#191470 - 2008-12-29 02:00 PM Re: Create a file [Re: chipped]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Ah, got it working, my syntax was wrong. The RUN command target has to be in brackets like this

 Code:
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Checking to see if Install folder exists, if it dosent then it is created.

IF NOT EXIST("C:\install")
       MD "C:\install"
ENDIF

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Installing Programs, the name of each program is writen to a folder as a text file, if the file does not esxist then the program will be installed, if the file exists then the program will not be installed. You can include version numbers in the file name of each program so if you need to you can upgrade.

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;Installing Adobe Reader 9.0

IF NOT EXIST("C:\install\AdobeReader9.0.txt")
	Open(1, "C:\install\AdobeReader9.0.txt", 1)
	RUN ("\\stingray\share\AdbeRdr90_en_US.exe /update-no /sAll /rs /l /msi"/qb-! /norestart ALLUSERS=1 EULA_ACCEPT=YES SUPPRESS_APP_LAUNCH=YES"" )
ENDIF

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Edited by chipped (2008-12-29 02:01 PM)

Top
#191476 - 2008-12-29 09:05 PM Re: Create a file [Re: chipped]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Well there may be a couple of issues.

1 - you should probably add a bit more error checking and what-if code such as if the file does not get written for some reason even if the installer did install it already it will keep installing it.

2 - Normally users would not have rights to install software on their own system

Top
#191485 - 2008-12-30 04:38 AM Re: Create a file [Re: NTDOC]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
I'm going to edit the logon script to automatically launch the script if only the admin is logging in.

I have been extensively testing it on a test machine.

Thanks for your input \:\)

Top
#191486 - 2008-12-30 06:13 AM Re: Create a file [Re: chipped]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
A much better approach would be to push the installs/updates to the target computers remotely. It seems you're still relying on sneaker-net to distribute the updates. You could for example use the Task Scheduler to install the updates.
_________________________
There are two types of vessels, submarines and targets.

Top
#191487 - 2008-12-30 07:36 AM Re: Create a file [Re: Sealeopard]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Push the installs/updates remotely? Thats pretty vague, please elaborate \:\)

I have looked at Windows AD integrated solutions but the free ones are only for MSI packages.

I like using scripts because I know whats going on in the background, its free and when it all works it gives you most satisfaction.

Top
#191498 - 2008-12-30 03:42 PM Re: Create a file [Re: chipped]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Instead of having an admin that has to log onto each machine to make the installs happen, write an "admin" script that goes out and touches each machine on your network, verify if the install has taken place, and if not either fire off the installer or set a scheduled task to fire off the installer at your time of choice.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#191532 - 2008-12-31 01:30 PM Re: Create a file [Re: Gargoyle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
This is what our SWDIST product does - you can sit at your desk and run the Deploy command to push an install process to a list of computers. It uses the task scheduler on the target comptuer to initiate the install command with admin rights - no need to physically touch any of the systems. I'm using it at my current project to push software to 3000+ desktops at over 300 locations.

Point is if you create an unattended install package and put it on a share, you can use Kix to push out a scheduled task to remote systems to run with specific credentials at a specified time. Staggering the time prevents saturating the network, and using a network share with OTN install process - especially for many concurrent product installs - eliminates any issues with limited disk space on the client. Using push technology requires enough space for the install package and the installed product. OTN installs only require the space for the installed product, and there's no cleanup. SWDIST is a hybrid, since it pushes a small batch file (no software dependencies on the client using BAT files) to the client, and defines a pull install. The intelligence comes from the Deploy process, which determines the target system's IP address, identifies the closest deployment server, and creates a scheduled task with the server name, product, and any arguments.

Your complex arguments would be in the install.bat file on the server and not passed to the task. Speaking of "your complex arguments"... your problem is really mismatched quotes. Shell/Run are commands, not functions, and do not require "()". When you use these commands, you should use single quotes for Kix and double quotes for the internal commands. I also prefer building command strings instead of using a monolithic statement, similar to:
 Code:
$Cmd = '%COMSPEC% /c '
$Cmd = $Cmd + 'some_prog.exe '
$Cmd = $Cmd + 'Arg="argument 1" /switchA'
'About to run: ' $Cmd ? ; for debugging
Shell $Cmd

This is easier to troubleshoot, as it breaks the command into managable segments.

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

Top
#191533 - 2008-12-31 01:33 PM Re: Create a file [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
BTW - there are two Kix packages to manipulate the task scheduler subsystem:
ScheduleTask - written by Jens, uses JT.EXE to create tasks
tcLib - my library of UDFs that uses JT.EXE, can create, modify, query, delete, update security, and trigger/terminate task execution.

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

Top
#191538 - 2009-01-01 10:51 AM Re: Create a file [Re: Glenn Barnas]
chipped Offline
Fresh Scripter

Registered: 2008-12-09
Posts: 40
Does that leave behind a log so that when I run the script again it dosent try install everything all over?
Top
#191539 - 2009-01-01 02:04 PM Re: Create a file [Re: chipped]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
The SWDIST tools log every action with a complete audit trail, but the logs are not used to prevent reinstallation. The task UDFs don't do any logging.

Generally, you'd define a custom registry key, like "ABC_Co" under HKLM\Software. You'd create a value for each app you install, which could be a simple "1" value indicating the install is done, or a datestamp, indicating when it was done. Thus, using either BAT or KIX scripts, you can read that registry key, and if an error 2 occurs (not found), you perform the install.

Using log (or tag) files to indicate an install or action is generally unreliable as users, AV software, and other cleanup processes can remove the files.

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

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1179 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.216 seconds in which 0.014 seconds were spent on a total of 14 queries. Zlib compression enabled.

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