Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-24-2012, 07:38 PM
thehawk thehawk is offline
Registered User
 
Join Date: Oct 2012
Posts: 7
How to tag users that run a script?

Hello

We're looking at the possibility of using SecureCRT to configure routers using the scripting funnctionality that's available.

We have used it in the past and we've ran into some issues/limitations.

Before we invest time/money into this again I wanted to know if there is a way to identify the user that will be running the script for logging purposes.

For example, we need to have 5 different people running these scripts from a shared location.

I need the script to identify the user that is running the script. I don't want to have users "type" in their name or an ID (because it introduces an additional element of manual error). The script should know which user is running the script. An option could be to create a drop down selection box (if possible).

Also, I don't want to have to create sepatate scripts for each user as that would increase the number of scripts that would have to be maintained.

Any suggestions/comments are welcome.
Adrian
Reply With Quote
  #2  
Old 10-25-2012, 08:07 AM
thehawk thehawk is offline
Registered User
 
Join Date: Oct 2012
Posts: 7
How to tag users that run a script?

Hello,

Is there a way to create a MSGBOX that has a drop-down with items to select from it?

Background: we're looking to get about 4 or 5 people to run a securecrt script from a shared directory on the LAN (at various times during the day). we need to be able to identify who's running the script so that we may log that action. We've tried the prompt method but it's prone to manual errors. Is there a more efficient way of identifying the user running the script without them typing in their name/id in a message window?

creating individual scripts for each user that has their ID embeded in the code may not be the best idea since you now have to maintain multiple scripts for multiple users.
Any comments/suggestions are appreciated even if the suggestion is that SecureCRT would not be the best platform for this.

PS. The scripts would be sending commands to routers once it connects to them.

Thanks
Adrian
Reply With Quote
  #3  
Old 10-25-2012, 08:53 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Adrian,

Thanks for the question. SecureCRT does not include a method for creating a message box that has a dropdown selection menu.

If you are using VBScript to write your script you could use the IE object and HTML to create and interact with your own form.

Does this sound like it might be an option?

While the SecureCRT scripting API does not offer a native method for obtaining the Windows user context, you could use the options available to you in your scripting language of choice to determine what user is logged onto the machine when the script is run. I would suggest checking the documentation for the language you are using for your script to determine what options are available.

What language are you using to write your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 10-25-2012 at 02:28 PM.
Reply With Quote
  #4  
Old 10-25-2012, 10:20 AM
thehawk thehawk is offline
Registered User
 
Join Date: Oct 2012
Posts: 7
we are testing with Perl (ActivePerl).

One other option that was thought of is to grab the hostname of the PC (which is distinct) and do a check against that. It may be as simple as running the command "hostname" at a cmd prompt in windows but through the secureCRT Script... how we get that info I will need to investigate.

Have you seen this done in the past?
Reply With Quote
  #5  
Old 10-25-2012, 02:25 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Adrian,

Thanks for the update. A quick internet search says that the following should work for Perl, but I have not tested it:
Code:
win32api.GetUserName()
For those interested in other languages, here are a couple of VBScript examples that are known to work:
Code:
Set objNetwork = CreateObject("wscript.network")
MsgBox objNetwork.UserName & "@" & objNetwork.UserDomain
Code:
Set objShell = CreateObject("wscript.shell")
set objEnv = objShell.Environment("PROCESS")
MsgBox objEnv("USERNAME") & "@" & objEnv("USERDOMAIN")
Here is a Python example that works as well:
Code:
import getpass
crt.Dialog.MessageBox(getpass.getuser())
We will post to this thread if we add the ability to make custom dialogs in a future SecureCRT release.

If you would like to be notified directly, please complete and submit the form at the following location:
Submit Feature Request
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #6  
Old 10-27-2012, 10:06 AM
thehawk thehawk is offline
Registered User
 
Join Date: Oct 2012
Posts: 7
Hello,
Thank you for your suggestions. I managed to get it working by running a few simple commands.

Below is a sample script that I used in SecureCRT (using perl). I hope someone else can use this too.

++++++++++++++++++++++++++++++++++++++++
# $language = "PerlScript"
# $interface = "1.0"

use Win32;

# Get active Username on Windows
$MyUsername = Win32::LoginName();
$crt->Dialog->MessageBox($MyUsername);

# Get the Computer name
$MyComputerName = Win32::NodeName();
$crt->Dialog->MessageBox($MyComputerName);

# Get the Windows Domain/ or Workgroup Name
$MyDomainName = Win32::DomainName();
$crt->Dialog->MessageBox($MyDomainName);
++++++++++++++++++++++++++++++++++++++++

Thank you.
Reply With Quote
  #7  
Old 10-29-2012, 08:10 AM
CBradley CBradley is offline
Registered User
 
Join Date: Jul 2012
Posts: 5
If its not too late, another option is to use the arguments field available in the newer versions of SecureCRT6.6+. This would allow your people to pass in their username everytime they call the script.
Reply With Quote
  #8  
Old 10-29-2012, 11:56 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Thanks for posting your solutions Adrian and CBradley.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

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 03:42 AM.