Page 1 of 1 1
Topic Options
#205925 - 2012-10-08 03:58 AM Pull a registry value into an environment variable
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
I'm trying to read a registry value, and place it into an environment variable. (I have had absolutely zero luck even reading the value).

Once I get that, I'd like to try and find a way to fire a wm_changenotify message (probably through .net?). I'm a decent vbscripter, and a pretty good winbatch scripter.. I'm picking kix32 back up now..

Any help would be appreciate it..

Top
#205926 - 2012-10-08 06:04 AM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2080
Loc: Tulsa, OK
Which registry key? You would want to use the ReadValue() function to read the value, you can then use one of the Set commands to set the environment variable.
Top
#205927 - 2012-10-08 06:09 AM Re: Pull a registry value into an environment variable [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2080
Loc: Tulsa, OK
Here is a short example...
 Code:
$value = ReadValue("HKCU\Volatile Environment","HOMEDRIVE")

Set "NewEnvVarName = "+$value

Top
#205934 - 2012-10-08 02:19 PM Re: Pull a registry value into an environment variable [Re: ShaneEP]
Glenn Barnas Administrator Online   content
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4289
Loc: New Jersey
Just be aware that you can't pass an environment var back to the program that called the Kix script..

You can set a variable in:
  • the LOCAL environment that will be visible to any child process started by SHELL or RUN (SETL Command);
  • the SYSTEM environment that will be visible to any new process started by any user (SETM Comand);
  • the USER environment that will be visible to any new process started by the current user. (SET command). This will send a notify command to the environment and be updated by applications that support it.
If you want to pass a value back, you'll need to output the value or write it to a file that can be read by the parent process. The variable you set will not be visible to the currently running Kix script either.

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

Top
#205936 - 2012-10-08 03:42 PM Re: Pull a registry value into an environment variable [Re: Glenn Barnas]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
I'm trying to pull the CLIENTNAME information out of HKLM\Software\Citrix\ICA\Session.
So, my commands I'm trying to use are:

DIM $ClientName
$CLIENTNAME = READVALUE("HKLM\Software\Citrix\ICA\Session", "ClientName")

As a test, I tried to just write it to another part of the registry...

WriteValue("HKCU\Software\Test", "KixTest", $CLIENTNAME, "REG_SZ")

The value gets created properly, but the actual data in the value isn't written. If I manually set $CLIENTNAME before the WriteValue, then it works properly.

The flip side of this, is I wanted to get a "permanent" environment variable set with this data for subsequent processes. I know it will not be visible in the current environment, so my hope was to find a way to write it to the registry (to create a system level environment variable - {easy}) a fire off a wm_changenotify system message in order to force windows to revaluate the environment {hard}.

My preference is to stick with Kix, because this is going to be a pre-flight execution script for Desktop Authority.

Thanks :-)

Top
#205937 - 2012-10-08 04:18 PM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
Glenn Barnas Administrator Online   content
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4289
Loc: New Jersey
Have you verified that $ClientName contains data after the registry read? (Display to screen)
Display the @SERROR value after the WriteValue - what do you get?

The SetM() command will create a machine (System) for all users.

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

Top
#205938 - 2012-10-08 04:32 PM Re: Pull a registry value into an environment variable [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Are you sure that reg value exists? It does not on the version of Citrix I use. Also, teh enviro var %CLIENTNAME% is set by the client on my system.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#205941 - 2012-10-08 05:42 PM Re: Pull a registry value into an environment variable [Re: Les]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
This is for XenDesktop. By default, it does not set ClientName.. you have to use the SessionStateMonitor for that, and I need that information *before* SSM runs.

I *know* the key/value contains data - I have triple checked it with regedt32.exe. I'm not really sure how to display it to the screen.. I have tried calling it directly, using MessageBox (the box comes up with my text, but not the variable information for $CLIENTNAME). I've tried using the debug mode..

I'm hoping that setm will work as I hope.. but until I get some good data to put into it I can't be sure that I'm doing any of this correctly.

(again, thanks for the help.. :-)

Top
#205942 - 2012-10-08 05:43 PM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4450
Loc: USA
Here is a function that never fully got tested. If it works for you and or your situation, might you follow up in the other thread.

Clientname() -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=204608#Post204608

Top
#205945 - 2012-10-08 06:02 PM Re: Pull a registry value into an environment variable [Re: Allen]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
I looked at the function, and it won't work for XD. For XA it works (at least in Win2k8 or Win2k8R2) because the sessionID is part of %temp% (i.e. if my session ID is 23, then my temp variable really points to %userprofile%\appdata\local\temp\23).

In XD, this is not valid. :-\ The CLIENTNAME is absolutely in the registry for XD (It is for XA also, but it is also predicated on sessionID (hklm\software\citrix\ica\session\\clientname.

I'll login from another machine, and I can post some screenshots.

Again, I really appreciate the help.. I have been racking my brains for 3 days on this.

Top
#205946 - 2012-10-08 06:03 PM Re: Pull a registry value into an environment variable [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2080
Loc: Tulsa, OK
Putting this line should display what you read from the registry.
 Code:
$null = messagebox($CLIENTNAME,"",0)

Top
#205947 - 2012-10-08 06:42 PM Re: Pull a registry value into an environment variable [Re: ShaneEP]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
That is what I thought ShaneEP.. I tried it and got nothing, and I tried it again after this morning and got nothing.

Attachments
IcaSessionData.png (127 downloads)
Description:



Top
#205948 - 2012-10-08 06:53 PM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4450
Loc: USA
Just a thought... is this a 64bit OS?

At the top of the script, try...
 Code:
$RC=setoption("WOW64AlternateRegView","On")

Top
#205958 - 2012-10-09 03:52 AM Re: Pull a registry value into an environment variable [Re: Allen]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
It is a 64bit that I'm developing and testing on. I'll try it and post the results.. if it is it, then I will feel like an idiot :-D

Thanks!

Top
#205959 - 2012-10-09 04:04 AM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
David_Figueroa Offline
Fresh Scripter

Registered: 2012-10-06
Posts: 7
Loc: Houston, TX
That was definitely part of it. I am now getting a registry value when I read.. It never even occurred to me to look for an option to do that. :-)

My issue during testing now is I can't seem to write that value to HKCU (this is just a test.. )

I can't thank everyone enough :-)

Top
#205964 - 2012-10-09 03:07 PM Re: Pull a registry value into an environment variable [Re: David_Figueroa]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2080
Loc: Tulsa, OK
I tried it on my 64 bit Win7 laptop. The following reads and writes the registry value once I added Allen's suggestion. Can you check the error code after you try the write?

 Code:
$nul = setoption("WOW64AlternateRegView","On")

$CLIENTNAME = READVALUE("HKLM\Software\Citrix\ICA\Session", "ClientName") 

$nul = WriteValue("HKCU\Software\Test", "KixTest", $CLIENTNAME, "REG_SZ")

$nul = MessageBox("Error Number: "+@Error+@CRLF+"Error Text: "+@SError,"status",0)

Top
#205966 - 2012-10-09 04:33 PM Re: Pull a registry value into an environment variable [Re: ShaneEP]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4450
Loc: USA
David, would you mind trying the clientname() udf again? I added your reg setting to it, and it would be good to know if it at least works for your environment.

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=205965#Post205965

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
3 registered (fergieman101, Glenn Barnas, Mart) and 183 anonymous users online.
Newest Members
emnipetro, Hirze, thequeen, ameliaryan, shalomsalami
17641 Registered Users

Generated in 0.038 seconds in which 0.01 seconds were spent on a total of 14 queries. Zlib compression enabled.

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