sjefferson
(Lurker)
2007-10-29 11:19 PM
kix2exe trouble

I have a script that I am trying to turn into an exe file, which works fine until I try to use /runasuser /runaspassword. I get the following error message:

ERROR: unexpected command!
Script: C:\DOCUME~1\ [...]\ke2~1000842\k2erun.dat
Line: 112

Does anyone have any idea what may be going on here? I haven't used kix2exe before now, and don't know how to go about troubleshooting this issue.

Thanks,
Shawn


Gargoyle
(MM club member)
2007-10-30 02:07 AM
Re: kix2exe trouble

Can you show us the script or at least the section that is having the problem.

sjefferson
(Lurker)
2007-10-30 05:20 PM
Re: kix2exe trouble

That's the trouble I'm having, since I can't actually see what's at line 112 in the script. My original script doesn't even have 100 lines.

Here's the script anyway:


Break On

Dim $Sessions[60,2]
Dim $line
Dim $x
Dim $RadioButtons[60]
Dim $session

; Run qwinsta to enumerate sessions
SHELL "%comspec% /c qwinsta.exe /server:nmmtermserv01 > userlist.txt"

; Parse the session list
$x = 0
IF OPEN (10, "userlist.txt") = 0
$line = READLINE(10)
$line = READLINE(10)
$line = READLINE(10)
$line = READLINE(10)
WHILE @ERROR = 0
$Sessions[$x,0] = RTrim(SubStr($line,20,20))
$Sessions[$x,1] = LTrim(SubStr($line,42,5))
;? "Username:" + $Sessions[x,0] + " Session ID: " + $Sessions[x,1]
$line = ReadLine(10)
$x = $x + 1
LOOP
ENDIF
$nul = CLOSE(10)
DEL "userlist.txt"

$session = 10000

; Display form with KixForms
$Form = CreateObject("Kixtart.Form")
$Form.FontName = "Tahoma"
$Form.FontSize = 10
$Form.FormBorderStyle = 4
$Form.SizeGripStyle = 1
$Form.Size = 600,500
$Form.Text = "Reset GP Terminal Session"
$Form.tag = 0

$GroupBox = $Form.Controls.Add("GroupBox")
$GroupBox.Top = 10
$GroupBox.Left = 10
$GroupBox.Height = $Form.Height - 110
$GroupBox.Width = $Form.Width - 20

$y = 10
For $x = 0 To 59
If $Sessions[$x,0] <> ""
$RadioButtons[$x] = $GroupBox.Controls.Add("RadioButton")
$RadioButtons[$x].Top = $y + (($x mod 15) * $RadioButtons[x].Height)
$RadioButtons[$x].Left = 10 + (120 * ($x / 15))
$RadioButtons[$x].Name = $Sessions[$x,0]
$RadioButtons[$x].Text = $Sessions[$x,0]
$RadioButtons[$x].Width = 120
$RadioButtons[$x].OnClick = "$$session = $Sessions[$x,1]"
EndIf
Next

$Button = $Form.ToolButton
$Button.Top = $Form.ClientHeight - $Button.Height - 10
$Button.Left = $Form.ClientWidth - $Button.Width - 10
$Button.Text = "Reset"
$Button.Icon = 37
$Button.OnClick = "$$form.tag=1"
$Button.Anchor = 2+8


$Form.Center
$Form.Show
While $Form.Visible and $form.tag = "0"
$= Execute($Form.DoEvents)
Loop

if $form.tag = "1"
RUN "%comspec% /c RESET SESSION $session /server:nmmtermserv01"
else

endif

Exit 0


sjefferson
(Lurker)
2007-10-30 05:30 PM
Re: kix2exe trouble

Hmmm, looking at this a little more and I think it has something to do with the unregistering of the kixforms (?)

Mart
(KiX Supporter)
2007-10-30 07:58 PM
Re: kix2exe trouble

I did not look at the code in details but not having kixforms registered might be it.

Depending on for what kixforms you wrote the script each workstation you want to run this script on should have either the kixform.classic dll or the kixform.net dll registered.


Richard H.Administrator
(KiX Supporter)
2007-10-31 09:12 AM
Re: kix2exe trouble

I use something like the following to register KiXforms. If the object cannot be created the UDF attempts to use a local copy to register it.

Useful for deploying one-off tools to tech support staff - if they get an error they know that they just need to re-run the script with a privileged account.


$System=initKixForms()
If @ERROR
$=MessageBox("Sorry, you must install KiXForms to use this application. If you run the application as a power user it will automatically install KiXforms","Cannot start KiXForms",0,48)
Exit 0
EndIf


Function initKixForms(Optional $iMode) ; {{{
Dim $sDLL $sDLL="kixforms.dll"
Dim $sResource $sResource=@SCRIPTDIR
Dim $sTarget $sTarget=%SYSTEMROOT%+"\system32\"+$sDLL

$iMode=Val($iMode)

$initKixForms=CreateObject("Kixtart.System")
If @ERROR
Select
Case $iMode=1
Case "Default"
"Attempting KixForms install..."+@CRLF
COPY $sResource+"\"+$sDLL $sTarget
If @ERROR
"Can't copy file - requires elevated privilege"+@CRLF
Else
Shell 'regsvr32 /s "'+$sTarget+'"'
If @ERROR
"Can't register file - requires elevated privilege"+@CRLF
Else
$initKixForms=CreateObject("Kixtart.System")
EndIf
EndIf
EndSelect
EndIf

Exit @ERROR

EndFunction ; }}}
; vim600:ai sw=4 ts=4 fdc=4 fdm=marker



sjefferson
(Lurker)
2007-10-31 05:55 PM
Re: kix2exe trouble

Hi,

That seems to have solved my problem! Although, I found that I have to have kixforms.dll registered on the machine BEFOREHAND, even though the user credentials I'm using to run the script (with /runasuser) should have admin rights to the local workstation. Anyway, thanks everyone for your help!

Shawn


Mart
(KiX Supporter)
2007-10-31 07:07 PM
Re: kix2exe trouble

You can register the kixforms dll (classic and .net) with a start up script or deploy them with a GPO.

NTDOCAdministrator
(KiX Master)
2007-10-31 10:08 PM
Re: kix2exe trouble

 Originally Posted By: Mart
You can register the kixforms dll (classic and .net) with a start up script or deploy them with a GPO.


It would need to be either a GPO or something like RunNas or the user would need Admin rights. You can quasi reg the classic with Power User rights but to properly do it you should have Admin rights.

If the user has rights or you're using RunNas you can actually add checking and installing code at the beginning of your code and not run the rest until it is installed and it should work as I recall (have not done anything like that type of testing though in many years)


Mart
(KiX Supporter)
2007-11-01 12:16 AM
Re: kix2exe trouble

I have to disagree with you Doc.

Registering the classic dll with a start-up script works just fine. Ok it a BATch start-up script but that doesn't matter. Did this for many years until several months ago I implemented a KF.NET based logon script and you should use regasm instead of regsvr32. But I just took the easy way out and made a GPO that deploys the KF.NET MSI. Works just fine, no problems whatsoever. No need for power user or admin rights. Start-up scripts runs on the local system account so it should have local admin rights. If it is part of the logon script then some kind of elevated rights are needed indeed.


NTDOCAdministrator
(KiX Master)
2007-11-01 02:10 AM
Re: kix2exe trouble

Don't think we're in disagreement. I just left out the StartUp script which as you say is essentially the same, but in both cases it has Admin rights.

I was attempting to point out that installing it with only normal user or Power User would either fail or partially fail.


Witto
(MM club member)
2007-11-01 08:50 AM
Re: kix2exe trouble

And (computer) Startup Scripts are part of a GPO, so I presume that you both agree \:D

Mart
(KiX Supporter)
2007-11-01 09:11 AM
Re: kix2exe trouble

Ahhh, ok. Sorry Doc. I misunderstood.