Page 1 of 1 1
Topic Options
#154826 - 2006-01-09 02:26 PM What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
Hello, Im new to scripting and Im having problems with a script I wrote. What Im trying to do is copy a file to some computer and then run that program. The issue that Im having is I have both 98 and xp machine. I can get the program to copy to both machine but cant get it to run on the 98. The xp machine seem to be fine. Here is a copy of my script. Can someone take a look and see what Im doing wrong. Thanks

debug on

;------------------------------------------------------------------------------------------
;Copies Stng259.exe to local computer and runs script. Then send log of scan to mas90
;------------------------------------------------------------------------------------------




$Y = "%temp%\stng259.exe"
Copy @ldrive + "\stng259.exe" "$Y"
if @error = 0
; goto "product"
else
shell "%comspec% /c echo copy of stng259.exe to @wksta on @date Failed >> \\mas90\scripts$\stinger.txt
GOTO "END"
Endif


: product
If @producttype = "Windows XP Professional"
goto "XP"
else
goto "w98"
endif


:w98
$Y = "%temp%\start1.bat"
Copy @ldrive + "\start1.bat" "$Y"
If @error =0
Run "%temp%\start1.bat"
Else
shell "%comspec% /c echo copy of start1.bat to @wksta on @date Failed >>
\\mas90\scripts$\stinger.txt
GOTO "end1"
ENDiF

:end1
cookie
exit


:XP
$Y = "%temp%\start.bat"
Copy @ldrive + "\start.bat" "$Y"
If @error =0
Run "%temp%\start.bat"
Else
shell "%comspec% /c echo copy of start.bat to @wksta on @date Failed >>
\\mas90\scripts$\stinger.txt
GOTO "end"
endif

:end
cookie1
exit

Top
#154827 - 2006-01-09 02:38 PM Re: What am I doing wrong
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Don't have 98 to check round here so I'm working from memory, but you could try:
Code:
Run "command.com /C "+%temp%+"\start1.bat"


Top
#154828 - 2006-01-09 03:04 PM Re: What am I doing wrong
Wizard Offline
Hey THIS is FUN
*****

Registered: 2000-12-05
Posts: 264
Loc: Bristol, England
Also try

Code:
shell "%comspec /c %temp%\start1.bat"

_________________________
Wizard
There's no place like 127.0.0.1

vb | kix | batch | html | cfm | js | english

Top
#154829 - 2006-01-09 03:47 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
OK Thanks I will give those a shoot and see what happens. Let you know how it works out. Does the rest of the script look ok?
Top
#154830 - 2006-01-09 04:04 PM Re: What am I doing wrong
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Wiz,
You are missing a % in there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154831 - 2006-01-09 04:44 PM Re: What am I doing wrong
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Quote:

Does the rest of the script look ok?




No, not really as we don't care for the use of GOTO, however if it's working for you and you're not quite at a level of scripting to script without it then that's what matters most. However you should work on learning a bit more then about scripting so that you can run this and even better scripts in the future.

Scripting can be a lot of fun and improve your productivity overall, so keep practicing.

Top
#154832 - 2006-01-09 08:55 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
Ok for some reason It is totally skipping over the 98 section. I have no clue what is going on. Basicly what is happening is if you run the script with debug on it is copying the file. It is then proceed to copy of the start batch file which is for the XP PCs and then trys to run that one. dosnt even look at the w98. And because in 98 you cant do the start/belownormal command it error out.Im totally lost now.
Top
#154833 - 2006-01-09 09:07 PM Re: What am I doing wrong
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The stuff about the goto's is already said so I won't go there.

First thing I see in the code you posted I see this:

Quote:


....
: product
....





This is in the manual:

Quote:


Labels must be unique within a script or user defined function and cannot contain whitespace characters. Note also that you can define labels inside script segments (for example inside a WHILE – LOOP segment), but you cannot jump to such a label from outside the segment.





What happens when the space is removed from the label?
Can't test on a 98 machine here.

[edit]
And you are missing some quotes at the end of the %comspec% stinger thingy lines.
[/edit]


Edited by Mart (2006-01-09 09:09 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#154834 - 2006-01-09 09:24 PM Re: What am I doing wrong
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
clmowers,

Did a little rewrite of the code without the goto's and vars and macro's inside strings.
This is a untested rewrite cause I do not have your setup here.
Give it a go and let us know how it's doing.

Code:

;Opens the stingers.txt file, if it does not exist it is created (see manual on writeline).
Open (1, "\\mas90\scripts$\stinger.txt", 5)

$Y = "%temp%\stng259.exe"
Copy @ldrive + "\stng259.exe" $Y
If @error <> 0
;If it errors write this line to the stinger.txt file.
WriteLine (1, "Error copying stng259.exe to: " + $y)
?
EndIf

;Select the OS and run the appropriate code.
Select
;This is for WinXP.
Case @producttype = "Windows XP Professional"
$Y = "%temp%\start.bat"
Copy @ldrive + "\start.bat" $Y
If @error =0
Run "%temp%\start.bat"
Else
;If it errors write this line to the stinger.txt file.
WriteLine (1, "copy of start.bat to " + @wksta + "on " + @date + "Failed")
EndIf
;This is for Win98
Case @PRODUCTTYPE = "Windows 98"
$Y = "%temp%\start1.bat"
Copy @ldrive + "\start1.bat" $Y
If @error =0
Run "%temp%\start1.bat"
Else
;If it errors write this line to the stinger.txt file.
WriteLine (1, "copy of start1.bat to " + @wksta + "on " + @date + "Failed")

EndIf
EndSelect
;Close the stinger.txt file.
Close (1)



Edited by Mart (2006-01-09 09:24 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#154835 - 2006-01-10 12:32 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
Thanks Mart. I will give both of those a shot and let you know. Just wondering, Mabey it is because I am a newbie at scripting,but whats wrong with the goto? No one seems to like that.
Top
#154836 - 2006-01-10 12:55 PM Re: What am I doing wrong
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Goto's make spaghetti code. It’s really hard to follow the flow of the script and see if and when something is screwed up. It all gets tangled up into one big messy pile. Same goes for gosub.
Using select - case - endselect or if - else - endif make the code much more readable and organised. Sometimes they also make shorter code and we know everybody here like to golf code now and then so these are the preferred commands nowadays.

Lately I forked up some old code of myself (from my early days of using kix) and to my shame I found goto’s in there We all make mistakes don’t worry about it.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#154837 - 2006-01-10 01:11 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
Ok That makes sense.It definitelymade it easy to figure out. I tried the script that you wrote and it works great. Both XP and 98 are up and running with stinger. Now if only I can get the boss to upgrade the 98 machines to xp. Can you write a script for that one. TBut thanks again mart.
Top
#154838 - 2006-01-10 01:15 PM Re: What am I doing wrong
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Happy to help.

Script for xp installation you say?
Sure

Code:

;asumes that x is your cd/dvd drive.
Run "x:\i386\setup.exe"



Edited by Mart (2006-01-10 01:16 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#154839 - 2006-01-10 03:13 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
One more thing, this is now making no sense to me. The script runs great. Im am now trying to copy the log file that stinger creates to my network drive so I can review the log. I tried reversing what I had with the copy and it doesn’t work. I have
the scrip you posted with this

$d = “\\mas90\scripts$\logs”
copy %temp%\stng259.txt $d

Also is there a book or something that would help me learn scripting

Thanks again

Top
#154840 - 2006-01-10 03:49 PM Re: What am I doing wrong
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Start to finish guide to scripting with kixtart by Bob Kelly

Code:

$d = “\\mas90\scripts$\logs\”
copy "%temp%\stng259.txt" $d



Should do the trick.


Edited by Mart (2006-01-10 03:50 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#154841 - 2006-01-10 04:56 PM Re: What am I doing wrong
clmowers Offline
Fresh Scripter

Registered: 2006-01-09
Posts: 13
Ok Thanks and I will check out that Book
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.083 seconds in which 0.039 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