#185456 - 2008-02-19 02:26 AM
Passing variables between kix sessions
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Hello all,
I'm trying to figure out a way to pass a string between scripts, which is called using the RUN, due to being run as an administrator with CPAU.exe. The required string is located in Script 'A', which calls CPAU.exe to run Script 'B' which requires the variable.
Because it is called like:
;-------------------------- RUN "%comspec% /c " + $netlogon_path + "CPAU.exe -dec -file " + $netlogon_path + "audit.job -lwop" ;--------------------------
It effectivly goes Script 'A' --> Command prompt --> CPAU.exe --> Script 'B', i've pretty much ruled out doing it by Error codes etc. Should i do it by setting a local or global variable? Or by writing the variable to a txt file on the local PC which is read by script 'B'? Do it using a registry key?
Because it's a logon script, it's run by limited user accounts.
Oh and for info on CPAU.exe (http://www.joeware.net/freetools/tools/cpau/index.htm)
Thanks in advance
Luke
Edited by lukeod (2008-02-19 02:27 AM)
|
Top
|
|
|
|
#185460 - 2008-02-19 03:38 AM
Re: Passing variables between kix sessions
[Re: Shawn]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Okay Registry sounds good. I'm clueless on the in's and outs of the registry. What path does a limited user have access to?
Thanks for the reply
Luke
|
Top
|
|
|
|
#185461 - 2008-02-19 03:39 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Yes, the whole idea of going via CPAU.exe was to pass Local Administrator credentials not in plain text (as the script is readable by anyone with access to NETLOGON)
Probably not 'best practice' to swap credentials during logon script, but hey, it works.
Edited by lukeod (2008-02-19 03:40 AM)
|
Top
|
|
|
|
#185464 - 2008-02-19 05:07 AM
Re: Passing variables between kix sessions
[Re: Shawn]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
I'll give it a crack now. Thanks for the feedback
|
Top
|
|
|
|
#185465 - 2008-02-19 05:38 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
What is the best way to go about the file way?
All users have read/write to c:\temp\
What is the best way of creating the ini file using Kix? Had a look through the UDF's and the builtin commands and am not sure how to:
A) Create a file B) Write a .ini style entry to the created file C) Call said value and store it as a variable on script 'B'.
I'll continue to look through the Manual/UDF's/Forums for any clues.
Thanks
Luke
|
Top
|
|
|
|
#185466 - 2008-02-19 06:30 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Okay, got "C)" done:
My INI file: ;************ [vars] nasip = 10.128.32.70 ;************
In Script "b":
$nasip = ReadProfileString("c:\temp\variables.ini", "vars", "nasip")
Now for A) and B)... (above worked with a .ini file i manually created and pasted under c:\temp)
|
Top
|
|
|
|
#185467 - 2008-02-19 07:15 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
To create a file you can always do
Open (1,"my_ini_file.ini",5) Close (1)
As for writing the line you would use WriteProfileString()
WRITEPROFILESTRING Action
Copies a string to an initialization file.
Syntax
WRITEPROFILESTRING ("file name", "section", "key", "string")
Parameters
File name
String identifying the initialization file. If this parameter does not include a full path, Windows searches for the file in the Windows directory.
Section
String containing the name of the section of the initialization file where string is copied. If the section does not exist, it is created. The section name is not case-sensitive, and can contain any combination of uppercase and lowercase letters.
Key
String containing the name of the key to associate with string. If the key does not exist in the specified section, it is created. If this parameter is empty, the entire section, including all entries within the section, is deleted.
String
String to write to the file. If this parameter is empty, the key identified by key is deleted.
Note
On Windows 9x, use of the tab character (\t) is not supported as part of this parameter.
Remarks
This function is provided for compatibility with 16-bit Windows-based applications. Win32-based applications store initialization information in the registry.
Returns
0 Profile string written Error code Function failed
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
#185468 - 2008-02-19 07:28 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Yay, got it working!
Code on Script 'A':
If not exist("c:\temp\variables.ini") WRITEPROFILESTRING("c:\temp\var2.ini", "vars", "nasip", "10.128.32.70") ENDIF
Code on Scipt 'B'
$inipath = 'c:\temp\variables.ini' IF exist($inipath) $nasip = ReadProfileString($inipath, "vars", "nasip") ELSE ?"INI file at path: " $inipath " does not exist." ENDIF
It looks like WRITEPROFILESTRING creates the INI if it dosnt exist by default, i might use this method as it cuts down on 2 lines.
Thank you both muchly for the help!
Luke
Edited by lukeod (2008-02-19 07:29 AM)
|
Top
|
|
|
|
#185492 - 2008-02-20 01:43 AM
Re: Passing variables between kix sessions
[Re: Shawn]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
The script is a temporary means of pushing out a WPA/PSK/TKIP SSID to a few thousand laptops at 27 different sites on independant domains, using microsofts network setup wizard etc. The setup is dodgy as hell but its the only possible way i could find of doing so untill we have a central active directory to do it via Certificates / Radius.
C:\Temp exists on *most* computers, and permissions set via group policy enable users to create folders under C:\ with 'modify' permissions to any folder they create (mostly for storing .PST files too big for their Home directories). They cannot put files under root C: or do anything to c:\Windows though so it aint so bad.
%temp% - that's not a bad idea and i'll have to have a look at it.
as for the '?' - havn't been using from habbit from other languages, infact i've barley ever programmed at all before, my experience in programming consists of a semester of VB.NET at highschool, i'm attempting to teach myself how to script. I've just redone the generic logon script for each site, i might post up a copy at some stage to see what you guys think before i roll it out to the schools. It's much better than the previos ones - which had a seperate COMPUTERINGROUP and MAPPRINTER UDF for each printer : \ .
|
Top
|
|
|
|
#185493 - 2008-02-20 02:04 AM
Re: Passing variables between kix sessions
[Re: lukeod]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
Where would be the best place to post my (sanitised) logon script for any suggestions? Create a new thread under 'Basic Scripting'?
THanks
Luke
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|