Page 1 of 1 1
Topic Options
#185456 - 2008-02-19 02:26 AM Passing variables between kix sessions
lukeod Offline
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
#185458 - 2008-02-19 03:26 AM Re: Passing variables between kix sessions [Re: lukeod]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I see where your coming from. audit.job is a tokenized (obfuscated) CPAU that calls some other kix script with credentials ?

Anyways, I would use the local var approach, it should work:

SETL "MYVAR=String to pass"

RUN "%COMSPEC% /C ..."

Then in your script B, ...

? "MyVar = " + "%MYVAR%"

-Shawn

Top
#185459 - 2008-02-19 03:34 AM Re: Passing variables between kix sessions [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, i dont know ... guess it would depend on whether that var got inherited somehow into that new session (you might need that -profile switch but still, would be surprised if that worked).

Registry or file might be your only hope. Registry seems little more cleaner to me i don't know. Your call.

-Shawn

Top
#185460 - 2008-02-19 03:38 AM Re: Passing variables between kix sessions [Re: Shawn]
lukeod Offline
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 Offline
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
#185462 - 2008-02-19 03:45 AM Re: Passing variables between kix sessions [Re: lukeod]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Now I'm thinking registry is probably not an option either. Assuming the user doesn't have write access to HKLM, and that the user's HKCU is either a) the wrong one or b) not there ...

Sounds like FILE is the only way to go ... I would use a quick INI file in a temp folder or maybe somewhere in ALLUSERS ?

Top
#185463 - 2008-02-19 04:00 AM Re: Passing variables between kix sessions [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok, was just doing some tests ...

1) Passing an environment variable no workie

2) Accessing HKCU from a process started with alternate credentials no workie.

Hey - had to try it eh ? You give any of this a shot ?

Top
#185464 - 2008-02-19 05:07 AM Re: Passing variables between kix sessions [Re: Shawn]
lukeod Offline
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 Offline
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 Offline
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 Offline
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()

 Quote:

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 Offline
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
#185473 - 2008-02-19 01:03 PM Re: Passing variables between kix sessions [Re: lukeod]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You don't need to create an ini file before you can use it - the WriteProfileString() will create the file if it is not present.

C:\Temp does not exist unless you created it, especially on newer environments. It might be safer to do
 Code:
WRITEPROFILESTRING("%TEMP%\var2.ini", "vars", "nasip", "10.128.32.70")

In script A - don't even bother checking if it exists..
 Code:
$nasip = ReadProfileString($inipath, "vars", "nasip")
If @ERROR or Not $NasIp
  'Error: '
  If @ERROR
    @SERROR ?
    Exit @ERROR
  Else
   'Data is not valid' ?
   Exit 87
  EndIf
EndIf

Also - minor - the "?" is a substitute for @CRLF, which generally comes at the END of an output line, and not a shortcut for a PRINT statement, as in early BASIC languages. This will come to bite you when you start creating more complex output structures.

Why are you using an IP address? Hard-coding IPs is not a good idea!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185474 - 2008-02-19 02:42 PM Re: Passing variables between kix sessions [Re: Glenn Barnas]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
lukeod, like Glenn mentioned, do your systems have a pre-existing c:\temp that everyone can write to ?
Top
#185492 - 2008-02-20 01:43 AM Re: Passing variables between kix sessions [Re: Shawn]
lukeod Offline
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 Offline
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
#185494 - 2008-02-20 02:11 AM Re: Passing variables between kix sessions [Re: lukeod]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, Basic Scripting should work.
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
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.072 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org