Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-24-2004, 05:08 AM
zorglups's Avatar
zorglups zorglups is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 61
How to get the "WScript.ScriptFullName"

I can't invoke WScript.ScriptFullName from within a script played with SCRT.

Any idea ?

Pierre.
Reply With Quote
  #2  
Old 11-29-2004, 10:51 PM
zorglups's Avatar
zorglups zorglups is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 61
Object required: 'WScript'

I got ne reply and guess this is because I did not dump enough details.

Here is the code:
# $language = "VBScript"
# $interface = "1.0"

msgbox WScript.ScriptFullName


Here is the error:
Object required: 'WScript'

I found some reason why this isn't OK at http://blogs.msdn.com/ericlippert/ar.../08/53175.aspx but this doesn't help me because I need to get one ay or another the path of the script.

Any idea out there ?
Reply With Quote
  #3  
Old 12-03-2004, 03:12 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 955
One of the limitations of an application hosting ActiveX scripting is the inability to gain access to functions that are not true objects within the script engine itself.

When running a vbscript outside of CRT/SecureCRT (where CScript.exe or WScript.exe are hosting the script code), you can make calls to things like:
WScript.Arguments
WScript.Name
WScript.Path
WScript.Quit
WScript.ScriptFullName
WScript.ScriptName
WScript.Sleep
WScript.StdErr
WScript.StdIn
WScript.StdOut
WScript.Version
...
However, when CRT/SecureCRT is hosting the script (instead of WScript.exe or CScript.exe), the WScript object itself isn't there; and unless you can call "CreateObject" to instantiate objects provided by WScript, they can't be used within a CRT/SecureCRT script.

In the past, we've made things like "Sleep" and "Arguments" available by providing an API within the CRT object that can be used for making these types of calls (e.g. crt.sleep; crt.arguments). We can consider adding something like a crt.ScriptFullName to resolve this problem for you.

There might be another way to accomplish what you need.

Can you provide more information about the script you are writing and the need to know the full path to the script being run?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 11-01-2006 at 10:20 PM.
Reply With Quote
  #4  
Old 12-06-2004, 04:08 AM
zorglups's Avatar
zorglups zorglups is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 61
Jake,

Here in Belgium, we celebrate "Sint Nocolas" who brings presents to good kids.
Your answer is the best present I received this year

Well, indeed I wrote a rather complicated script which will upload the rz or sz tools in uuencode format, talink into account the line speed by doing a kind of flow control. This is really useful when one need to transfer files but doesn't have the rz/sz binaries on the target machine yet.

I provided to my collegues the script in a zip containing the vbs and in a subdirectory the rz/sz binaries for Sun, Linux and HP.

Today people will extract the script anywhere but they then have to edit the vbs and change a constant with their "current path".

I don't like having people editing the script to make it work and would like to have a way (even tricky) to get the path of the running vbs. Once I have it, I can deduce the path of the subdirectory.

As soon as this is done, I would provide to Vandyke my script so they can make it available to other. It took me some weeks of work and would be glad to share it with others.

Thanks for the reply.
Indeed, it would be nice to have a kind of crt.ScriptFullName

Best regards,

Pierre.
Reply With Quote
  #5  
Old 12-06-2004, 05:05 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 955
Pierre,

Quote:
Here in Belgium, we celebrate "Sint Nocolas" who brings presents to good kids.
Your answer is the best present I received this year
This is great feedback.

I certainly would be interested in seeing the script code that you are using to perform the "installation" of rz/sz.
Quote:
Today people will extract the script anywhere but they then have to edit the vbs and change a constant with their "current path".

I don't like having people editing the script to make it work and would like to have a way (even tricky) to get the path of the running vbs. Once I have it, I can deduce the path of the subdirectory.
Have you considered requiring individuals to extract the .zip file to a specific location (e.g. My Documents) so that within your script, you know exactly where the files are located?

Another way of going about it would be to supply two .vbs files, one that is run by the user after extracting the contents of the .zip file. This first .vbs could launch SecureCRT with the /SCRIPT secondFile.vbs /ARG path_to_running_script arguments. Then the second .vbs script code would take advantage of the crt.arguments(0) which would contain the value of WScript.ScriptFullName (sent in from the first .vbs file -- running outside of SecureCRT).

The only "Tricky" way to go about it otherwise that comes to mind is to take advantage of the Recent Script List.ini file that SecureCRT maintains. However, there are a few caveats:
  1. SecureCRT does not update the Recent Script List.ini file until SecureCRT closes. Even performing a crt.screen.SendSpecial "MENU_SAVE_SETTINGS_NOW" does not cause the .ini file to be written out.
  2. Because of (1) above, the script would need to run once, place a "cookie" in the registry (or in a temp file somewhere). Then the user would have to close SecureCRT, start it again, and run the script a second time, at which instance, the script would check to see if the cookie existed, and then would know that it could read the Recent Script List.ini file and reasonably expect to know that the "Script1" entry contained the path to the most recently run script (itself, most likely). Although closing SecureCRT the first time can be done automatically through the script itself with crt.quit, this doesn't make for a nice interface for the user.
  3. It's not completely robust. If a user is running multiple instances of SecureCRT, and one happens to close right after another by chance, there is a possibility that the Recent Script List.ini file would not reflect the script you want in the "Script1" entry.
In spite of these shortcomings, I can send you some example VBScript code to achieve this if you are interested.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #6  
Old 12-09-2004, 10:51 AM
zorglups's Avatar
zorglups zorglups is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 61
Thumbs up

Jake,

Quote:
Originally Posted by jdev
I certainly would be interested in seeing the script code that you are using to perform the "installation" of rz/sz.
I can send it to you (post me a private message). I won't publish it until it has been betatested by my coworker and until I get a way of deducing this FullPath.

Quote:
Originally Posted by jdev
Have you considered requiring individuals to extract the .zip file to a specific location (e.g. My Documents) so that within your script, you know exactly where the files are located?
Whaouw... People around me are people managing live Tru64 or Sun Clusters and are those kind of Guru who don't like when you ask the to create a c:\temp because I can't manage it another way. That's the easiest way for sure but I'm looking for another one.

Quote:
Originally Posted by jdev
Another way of going about it would be to supply two .vbs files, one that is run by the user after extracting the contents of the .zip file. This first .vbs could launch SecureCRT with the /SCRIPT secondFile.vbs /ARG path_to_running_script arguments. Then the second .vbs script code would take advantage of the crt.arguments(0) which would contain the value of WScript.ScriptFullName (sent in from the first .vbs file -- running outside of SecureCRT).
This supposes that the script is always run from the cmd prompt. That's and acceptable thing but this won't cover cases were the people connect throught difficults pathes (modem cnx, several consecutive telnet/ssh cnx). People will usually launch it throught the script menu -or- for those who fall in love for it, they will map it on a key.

Nevertheless, you gave me an idea. I can include in my zip another vbs (install.vbs) that would get the FullPath from wsh and patch the rzszinstall.vbs.

Quote:
Originally Posted by jdev
The only "Tricky" way to go about it otherwise that comes to mind is to take advantage of the Recent Script List.ini file that SecureCRT maintains. However, there are a few caveats:[list=1][*]SecureCRT does not update the Recent Script List.ini file until SecureCRT closes. Even performing a crt.screen.SendSpecial "MENU_SAVE_SETTINGS_NOW" does not cause the .ini file to be written out.

...
Whaouw That is tricky. I thought you would give me a way to get it from the registry or from a system call...
Your way has some constraints that will be 'too heavy' for the end user.

Nevermind, you gave me an idea.
If you can implement the FullPath into a future version of SCRT, that would be nice.

As soon as I have a workable solution, I will publish it.

Thanks.

Pierre.
Reply With Quote
  #7  
Old 12-10-2004, 09:07 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 955
Quote:
Whaouw... People around me are people managing live Tru64 or Sun Clusters and are those kind of Guru who don't like when you ask the to create a c:\temp because I can't manage it another way. That's the easiest way for sure but I'm looking for another one.
The following VBScript code snippet retrieves the path to a user's "My Documents" folder. Does this not help avoid the need to have a "C:\Temp" folder created?
Dim szDocsFolder, g_shell
Set g_shell = CreateObject("WScript.Shell")
szTempFolder = g_shell.SpecialFolders("MyDocuments")
Quote:
Whaouw That is tricky. I thought you would give me a way to get it from the registry or from a system call...
Unfortunately, the fullpath to the script being run [while it is running] is not currently exposed by SecureCRT in any way.

Quote:
If you can implement the FullPath into a future version of SCRT, that would be nice.
I've submitted the request to the product manager. If the decision is made to add this to a future version, we'll let you know.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #8  
Old 12-12-2004, 12:36 PM
zorglups's Avatar
zorglups zorglups is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 61
Thanks Jake.

I think for now, I will manage with an install.vbs script which will create a .ini file used by my script. This is not really something I like but this is the cleanest way so far.

If this feature could be added to the product, I would be very glad.

Thanks for your support anyhow.

Pierre.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 09:29 PM.