#124227 - 2004-07-30 11:52 PM
Am I missing something here?
|
Anonymous
Anonymous
Unregistered
|
I am trying to pipe the results from this Terminal Server command to a variable I can use in my Kix script.
Code:
$Myarray = Split("%SystemRoot%\Profiles\operez","\") $x = UBOUND($MyArray) $UserName = $MyArray[$x] Shell '%comspec% /c tsprof /q /domain:frost_bank $UserName' >$file ? "Results from $file"
Am I doing it wrong?
|
|
Top
|
|
|
|
#124228 - 2004-07-31 12:41 AM
Re: Am I missing something here?
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You cannot pipe the results of a SHELL command to a variable. If you want this functionality, the popular choice seems to be using WshPipe().
|
|
Top
|
|
|
|
#124230 - 2004-07-31 02:24 AM
Re: Am I missing something here?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Thanks Les and Chris. I will give it a try.
|
|
Top
|
|
|
|
#124231 - 2004-08-02 06:42 PM
Re: Am I missing something here?
|
Anonymous
Anonymous
Unregistered
|
Les, I couldn't get your code to work. But, I used the WshPipe() UDF that Chris suggested and got the results I was looking for.
Thanks again both of you.
|
|
Top
|
|
|
|
#124233 - 2004-08-02 11:01 PM
Re: Am I missing something here?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Les, thanks for the clarification. I’m not good enough (yet) to have figured that out, which leads to my next question. If the User ID is no longer a valid ID I am getting the following error message: “Failed getting User Configuration, Error = 2 (0x2)”. How can I trap this error, since the error is from the command prompt and not a Kixtart error? I was using:
Code:
If @ERROR = 0 Do something Else Report an error EndIf
And I never get a message about an error, even though when I manually check some User IDs are no longer valid.
|
|
Top
|
|
|
|
#124235 - 2004-08-03 05:10 AM
Re: Am I missing something here?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Chris, thanks again. That did the trick. If the command doesn't complete successfully, it returns an error code of 1. If it completes successfully it returns an error code of 0. Thanks.
|
|
Top
|
|
|
|
#124236 - 2004-08-03 04:42 PM
Re: Am I missing something here?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
I know that after you look at what I am doing you might be asking yourself, why? Well at least it’s turning out to be a good exercise in trying to learn Kixtart.
I am in a Citrix environment and we went from mandatory profiles to roaming profiles. I’ve noticed that there were several SIDs in the registry that were referring to the mandatory profiles. I also noticed that there were several SIDs that didn’t point to the correct location of the roaming profile and others that referred to the location of the local profile as %SystemRoot%\Profiles\UserID (NT 4.0 Terminal Server) and others that referred to it as %UserProfile%\UserID. And, other SIDs that were for UserID.000 or UserID.001. I thought I would cleanup the ProfileList key in the registry by deleting reference to the old mandatory profiles and invalid UserIDs and standardize the entries for the roaming and local profile locations.
What was I thinking?
My problem is that the script deletes some of the mandatory profiles, but not all of them. If I run the script again it will delete some more entries, but again not all of them. I have to run the script 3-4 times before it will delete all the keys referring to the mandatory profiles. Why won’t it do it all in one shot? Also, for users that no longer exist the script deletes some of these keys and for others it enters the “tsprof” error message in the roaming profile location. Then for some if the registry key does not have the “CentralProfile” value the WriteValue does not create the value. Does WriteValue only work if the value already exists?
Well here’s the code:
Code:
If RedirectOutput("H:\CleanProfileList.log") = 0 EndIf
? "== @Time == @Date =====================================================" $vIndex = 0 $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $aLocalUsers = "All Users","Administrator","Default User" $sTSProfError = "Failed getting User Configuration, Error = 2 (0x2)"
:Loop1 $sKeyValue = EnumKey("$sRegKey", $vIndex) If @ERROR = 0 $vCentralProfile = ReadValue("$sRegKey\$sKeyValue", "CentralProfile") ? "*............................................................*" If @ERROR = 0 If LEFT($vCentralProfile, 11) = "C:\PROFILES" ? " CentralProfile is equal to old mandatory profile" ? " Deleting SID: $sKeyValue" $vRC = DelKey("$sRegKey\$sKeyValue") If $vRC = 0 ? " .. SID Key $sKeyValue deleted .... " EndIf Else $vProfileImagePath = ReadValue("$sRegKey\$sKeyValue", "ProfileImagePath") If @ERROR = 0 ? " Current Local Profile Path: $vProfileImagePath" $aUserID = Split("$vProfileImagePath","\") $vX = UBOUND($aUserID) $sUserID = $aUserID[$vX] ? " User ID is: $UserID" $vX = ASCAN($aLocalUsers, $sUserID) If Not (1+$vX) ; $vX <> 0 $aTSProfCmd = WshPipe("tsprof /q /domain:MyCompany $UserID",1) If @ERROR = 0 $sTSProfResults = $aTSProfCmd[0] $aStripFirst = Split($sTSProfResults,"{") $vX = UBOUND($aStripFirst) $sProfilePath = $aStripFirst[$vX] $aStripLast = Split($sProfilePath,"}") $sTSProfilePath = $aStripLast[0] If $sTSProfilePath <> $sTSProfError $vRC = WriteValue("$sRegKey\$sKeyValue", "CentralProfile", "$sTSProfilePath", "REG_SZ") If @ERROR = 0 ? " Set Terminal Server Profile Path to: $sTSProfilePath" Endif $vRC = WriteValue("$sRegKey\$sKeyValue", "ProfileImagePath", _ "%%SystemRoot%%\Profiles\$sUserID", "REG_EXPAND_SZ") If @ERROR = 0 ? " Set Local Profile Path to: %%SystemRoot%%\Profiles\$UserID" Endif Else $vRC = DelKey("$sRegKey\$sKeyValue") If $vRC = 0 ? " .. Not in domain, deleting SID: $sKeyValue" Endif EndIf EndIf Else ? " ..User ID $sUserID, is a Local ID and is being by passed" EndIf EndIf EndIf EndIf $vIndex = $vIndex + 1 goto Loop1 EndIf
Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $oExec, $Output $oExec = CreateObject("WScript.Shell").Exec($ShellCMD) If Not VarType($oExec) = 9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf $Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll If Not $NoEcho $Output EndIf $WshPipe = Split(Join(Split($Output,CHR(13)),''),CHR(10)) Exit($oExec.ExitCode) EndFunction
|
|
Top
|
|
|
|
#124239 - 2004-08-03 05:31 PM
Re: Am I missing something here?
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Les, you forget I’m like the blind leading the blind.
So, how would I go about deleting registry keys in a loop with an enumerated index, so as not to skew the index? Would deleting 1 from $vIndex each time I delete a key work?
And, why shouldn’t I use GOTO (not that I’m married to it and can’t change) just wondering? Should I use DO – UNTIL or WHILE – LOOP? Just trying to learn the correct way of doing things.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|