Gazzalad
(Fresh Scripter)
2006-08-31 04:39 PM
Kix to run Sequential code.. Guidance..

I am coding a script that must run in a given order, ie instal a piece of software, stop a service then make some changes to the registry and then start the next install.

As a result I want to wait until one task has finished before starting the next task.
Heres an example which I want to use to remove any old versions of ultravnc and replace with a new version:

Shell '%comspec% /c net stop "vnc server"'
$ = DelTree ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\winvnc")
$ = DelTree ("HKEY_LOCAL_MACHINE\SOFTWARE\ORL")
$ = DelTree ("HKEY_LOCAL_MACHINE\SOFTWARE\ULTRAVNC")
Run $path + 'UltraVNC\ultravnc.exe'
Shell '%comspec% /c net stop "vnc server"'
$ = DelTree ("HKEY_LOCAL_MACHINE\SOFTWARE\ORL")
$ = DelTree ("HKEY_LOCAL_MACHINE\SOFTWARE\ULTRAVNC")
$serverloc=$path+'UltraVNC\UVNC XP Clients Part 1.reg'
$ClientLoc= $windir +'\tempy\'
Copy $serverloc $ClientLoc
$serverloc=$path+'UltraVNC\UVNC XP Clients Part 2.reg'
Copy $serverloc $ClientLoc
$serverloc=$path+'UltraVNC\video driver\'
$ClientLoc= $windir +'\tempy\video driver'
Copy $serverloc $ClientLoc
$ClientLoc= "c:\program files\ultravnc\"
$serverloc=$path+'UltraVNC\rc4.key'
Copy $serverloc $ClientLoc
$serverloc=$path+'UltraVNC\MSRC4Plugin.dsm'
Copy $serverloc $ClientLoc
Shell '%comspec% /c regedit /s "c:\tempy\UVNC XP Clients Part 1.reg"'
Shell '%comspec% /c regedit /s "c:\tempy\UVNC XP Clients Part 2.reg"'
Shell '%comspec% /c "c:\tempy\video driver\setupdrv install"'
Shell '%comspec% /c net start "vnc server"'
$ = WriteValue ($hklms, "UltraVNC", $NewVer, "REG_SZ")

But I have found that the code runs straight through, ie writes the final registry entry before the software is fully installed etc.

Is there a command I can use to wait until the previous task has finished before proceeding with the next line of code?

I have tried searching the forum but am not having any luck.

Many Thanks

G


Witto
(MM club member)
2006-08-31 04:46 PM
Re: Kix to run Sequential code.. Guidance..

Change "Run" in "Shell"
[Edit]
Or would that be to easy at second view...
[/Edit]


Witto
(MM club member)
2006-08-31 04:56 PM
Re: Kix to run Sequential code.. Guidance..

Found something here
http://www.kixscripts.com/scriptlibrary/view.asp?id=166
and maybe STRCM can be of use to you. Installs on the fly when you need it. Also uninstalls after use (I think there are several antispyware programs who think of VNC as a threat)


Gazzalad
(Fresh Scripter)
2006-08-31 04:56 PM
Re: Kix to run Sequential code.. Guidance..

Sorry for appearing stupid here, but I am not exactly sure what you mean..

Do you mean to use the shell command in place of the run command or vice versa?

G


eriqjaffe
(Hey THIS is FUN)
2006-08-31 04:59 PM
Re: Kix to run Sequential code.. Guidance..

Yes. RUN will spawn an external process and continue the script, SHELL will spawn the process and wait for it to end before continuing. Personally, I almost never use RUN statements, since I'm usually only running external commands because they're needed to do things that KiXtart can't do by itself (or, at least, not without jumping through too many hoops).

Witto
(MM club member)
2006-08-31 05:03 PM
Re: Kix to run Sequential code.. Guidance..

I saw one RUN in your code
Code:

Run $path + 'UltraVNC\ultravnc.exe'


Must this program start and should the script not wait before it terminates?

I would like to recommend STRCM.


Gazzalad
(Fresh Scripter)
2006-08-31 05:15 PM
Re: Kix to run Sequential code.. Guidance..

Appreciate the help guys and the STRCM tool.

However this is just one part of the code. There lots of other instrallations going on that I need to run sequentially..

Will try the shell option..

G


private_meta
(Getting the hang of it)
2006-08-31 05:21 PM
Re: Kix to run Sequential code.. Guidance..

If you have the Setup Zipped into an Exe-File it can happen that the SHELL-Command sees the Application done once the unzipper is done unpacking. Maybe you could use some shell-bashed unzipper, in case you need to install more stuff... you might not need this info, but just in case it could be helpful

Richard H.Administrator
(KiX Supporter)
2006-08-31 05:37 PM
Re: Kix to run Sequential code.. Guidance..

Generally a command that you execute using "shell" will cause the script to pause until it the command has completed.

However, some programs release the console when they start or after they have unpacked the files and started the install part. This means that they appear to have completed, so the script continues.

There are a couple of ways to wait for the command to complete:
  1. Execute it using the DOS "start /wait" built-in. This sometimes works.
  2. Installer programs often have a "sms" flag or similar, which forces them to keep hold of the console.
  3. The most complex and least reliable option is to spawn the install process then read the running process table and wait for it to exit.


Hopefully one of these will work for you.


Gazzalad
(Fresh Scripter)
2006-08-31 06:54 PM
Re: Kix to run Sequential code.. Guidance..

The shell command is working perfectly for the applications I have to install. Many thanks guys..

Not wishing to push my luck but can anyone help me with this bit of code:

Shell '%comspec% /c regedit /s "c:\tempy\UVNC XP Clients Part 1.reg"'

I get an error saying UNC paths are not supported. Is there a way around this?

Cheers

G


LonkeroAdministrator
(KiX Master Guru)
2006-08-31 07:24 PM
Re: Kix to run Sequential code.. Guidance..

yep.
use this:
Shell 'regedit /s "c:\tempy\UVNC XP Clients Part 1.reg"'


Gazzalad
(Fresh Scripter)
2006-08-31 07:37 PM
Re: Kix to run Sequential code.. Guidance..

Fantastic.

Many thanks guys it looking like its working now!

G


Witto
(MM club member)
2006-08-31 09:30 PM
Re: Kix to run Sequential code.. Guidance..

Jooel, I would think that %comspec% is giving the message that UNC paths are not supported, but the regedit thing should work afterwards, shouldn't it?

LonkeroAdministrator
(KiX Master Guru)
2006-08-31 09:48 PM
Re: Kix to run Sequential code.. Guidance..

I think not.
as comspec errors, it doesn't execute the command.


NTDOCAdministrator
(KiX Master)
2006-08-31 11:09 PM
Re: Kix to run Sequential code.. Guidance..

That is not his error I don't think. It is probably there from other code in his script, or he is calling the script from a batch file.

BATCH files do not properly support UNC paths.


This works:
Shell '%comspec% /c regedit /s "c:\tempy\UVNC XP Clients Part 1.reg"'

and this works:
Shell 'regedit /s "c:\tempy\UVNC XP Clients Part 1.reg"'

But why call %comspec% if you don't need to.

He needs to look elsewhere in his code for the UNC error message as it is not being created by this process.


Witto
(MM club member)
2006-08-31 11:20 PM
Re: Kix to run Sequential code.. Guidance..

I knew I had seen the message somewhere. It was with BATCH files and UNC paths. Thanks Doc for refreshing my memory. I have used for a while batch files that I called from a path like "\\server\share$\InstallPackxxx\install.cmd" I got that "error" message but it was never a problem to the rest of the commands.

NTDOCAdministrator
(KiX Master)
2006-08-31 11:54 PM
Re: Kix to run Sequential code.. Guidance..

Well it depends on what commands were in the batch.

But yes, I think that is where the error is coming from.


Les
(KiX Master)
2006-09-01 12:20 AM
Re: Kix to run Sequential code.. Guidance..

AFAIK that error is just cosmetic and does not stop processing. I agree with DOC. In and of itself, SHELLing to comspec should not spawn that error, only if a BATch script is involved.