Page 1 of 1 1
Topic Options
#209029 - 2014-06-25 05:43 AM First basic script
Dekkar Offline
Just in Town

Registered: 2014-06-25
Posts: 4
Loc: Syd, Aus
Hi guys, hopefully this is a very basic script... Its the first one ive tried and also my first post.

Basically I wanted the script to do the following:

If C:\file.doc exists exit

else

copy \\server\file.doc c:\

then exit.

Is this possible with Kixtart?

Thanks,
dekkar

Top
#209030 - 2014-06-25 09:31 AM Re: First basic script [Re: Dekkar]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well, yes.

for example:

 Code:
break on

if not exist("c:\file.doc")
    copy "\\server\share\file.doc" "c:\"
endif

exit 1


Possible Failures: User has no rights on server share or may not be privileged to write to C:\

\:\)

Let us hear what the results are.
_________________________



Top
#209036 - 2014-06-27 08:49 AM Re: First basic script [Re: Jochen]
Dekkar Offline
Just in Town

Registered: 2014-06-25
Posts: 4
Loc: Syd, Aus
Excellent... Ill give it a test run.

Thanks for the info.

Top
#209118 - 2014-07-01 07:32 AM Re: First basic script [Re: Dekkar]
Dekkar Offline
Just in Town

Registered: 2014-06-25
Posts: 4
Loc: Syd, Aus
Hi Guys, after a bit of playing around and hunting around, I found that kix can inject registry files directly, so my script now looks like:

IF NOT KeyExist("HKCU\Software\Work\Config\IncludeSubjectLabel")
$rc = WriteValue("HKCU\Software\Work\Config\", "IncludeSubjectLabel", "0", "REG_DWORD")
$rc = WriteValue("HKCU\Software\Work\Config\", "IncludeSubjectLabelOnBrowse", "0", "REG_DWORD")
ENDIF

I do have a question, for some reason, the script is executing even if the key exists.

For example, if I change this key to have a value of "1", then relogon, it changes to "0".... So its changing the registry regardless of the IF NOT.

Is there something I'm missing?

Top
#209119 - 2014-07-01 09:33 AM Re: First basic script [Re: Dekkar]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Small change that should work.

 Code:
Break on

$key = "HKCU\Software\Work\Config"

If ReadValue($key, "IncludeSubjectLabel") = ""
	$rc = WriteValue($key, "IncludeSubjectLabel", "0", "REG_DWORD")
	$rc = WriteValue($key, "IncludeSubjectLabelOnBrowse", "0", "REG_DWORD")
EndIf


Edited by Mart (2014-07-01 09:34 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209122 - 2014-07-01 12:24 PM Re: First basic script [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Actually, Mart's example will show that the value located at the Key path is empty. A small distinction, but important to understand as a new scripter. If you need to know if it didn't exist instead of being empty, you could read the location into a variable, then check @ERROR. If the ERRROR macro contained the value "2", then it did not exist.
 Code:
Break on

$key = "HKCU\Software\Work\Config"

$RC = ReadValue($key, "IncludeSubjectLabel")
If @ERROR = 2
	$rc = WriteValue($key, "IncludeSubjectLabel", "0", "REG_DWORD")
	$rc = WriteValue($key, "IncludeSubjectLabelOnBrowse", "0", "REG_DWORD")
EndIf
Also - Registry objects consist of a Key and Value. Values contain Data of a specific Type - this info is needed to Write the object. You can think of the KEY as the PATH and VALUE like the FILE in a disk structure. Functions that deal with keys won't include the value part, which was the issue in your first attempt.

If it's simply important that the registry object contain specific data, then it doesn't matter what method you use.

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

Top
#209147 - 2014-07-02 02:34 AM Re: First basic script [Re: Glenn Barnas]
Dekkar Offline
Just in Town

Registered: 2014-06-25
Posts: 4
Loc: Syd, Aus
Hi Guys, thanks for shedding some light on this.

Both examples I understand and have expanded my knowledge on scripting...

Its now working as expected! Which is kind of satisfying!

Thanks again.

Top
#209151 - 2014-07-02 10:43 AM Re: First basic script [Re: Dekkar]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
I think your first code was not so bad but you used keyexist to test if a value exist.
If the test on key is enough, use the code below :
 Code:
$key = "HKCU\Software\Work\Config"

If not KeyExist($key)
	$rc = WriteValue($key, "IncludeSubjectLabel", "0", "REG_DWORD")
	$rc = WriteValue($key, "IncludeSubjectLabelOnBrowse", "0", "REG_DWORD")
EndIf

if you want to make configuration if value doesn't exist, use glenn's code
_________________________
Christophe

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.034 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