Packaged script not working with qwinsta command

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.
Locked
User avatar
clum09
Posts: 114
Joined: Thu Apr 24, 2008 9:11 am

Packaged script not working with qwinsta command

Post by clum09 » Mon Mar 24, 2014 9:33 am

Hello,

I have a VBScript function to query for logon sessions. The script works fine when not packaged with PrimalScript 2012. The script produces the output just fine.

However, when the script was packaged with PrimalScript 2012, the packaged script failed to work. There is no error out put from the packaged script either. It just went silent. It does not matter what Engine type I packaged it with, it just failed to produce the output.

Below is the function.

Code: Select all

strComputer = CreateObject("Wscript.Network").ComputerName

GetLogonSessions strComputer

Function GetLogonSessions(strComputer)
Dim objRegEx, objShell, objExecObject, strSearch, strLine
Dim strUserName, intSession
	Set objRegEx = CreateObject("VBScript.RegExp")
	With objRegEx
		.Global = True
		.IgnoreCase = True
		.Pattern = "\s{2,20}"
	End With
	Set objShell = CreateObject("WScript.Shell")
	Set objExecObject = objShell.Exec("cmd /c qwinsta /server:" _
	& strComputer)
	Do Until objExecObject.StdOut.AtEndOfStream
		strSearch = "" : strUserName = "" : intSession = ""
		strLine = Trim(objExecObject.StdOut.ReadLine)
		'Get disconnected sessions.
		If InStr(strLine,"Disc") > 0 And InStr(strLine,"service") = 0 Then
			strSearch = objRegEx.Replace(strLine,";")
			strUserName = Split(strSearch,";")(0)
			intSession = Split(strSearch,";")(1)
			WScript.Echo strUserName & ";" & intSession
		End If
		'Get active sessions.
		strSearch = "" : strUserName = "" : intSession = ""
		If InStr(strLine,"Active") > 0 And InStr(strLine,"service") = 0 Then
			strSearch = objRegEx.Replace(strLine,";")
			strUserName = Split(strSearch,";")(1)
			intSession = Split(strSearch,";")(2)
			WScript.Echo strUserName & ";" & intSession
		End If
	Loop
'Clean up.
Set objRegEx = Nothing: Set objShell = Nothing
Set objExecObject = Nothing
End Function
Thank you in advance.

User avatar
jvierra
Posts: 11056
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Packaged script not working with qwinsta command

Post by jvierra » Mon Mar 24, 2014 10:02 am

Your exact script works perfectly for me. It outputs to the console so you need to run it from a command prompt.
Here is exactly what I have run after cleaning it up a bit so it is more readable.
VBScript Code
Double-click the code block to select all.
strComputer = CreateObject("Wscript.Network").ComputerName

WScript.Echo "Begin search..."
GetLogonSessions strComputer
WScript.Echo "End search..."

Function GetLogonSessions(strComputer)

    Dim objRegEx, objShell, objExecObject, strSearch, strLine
    Dim strUserName, intSession
    
    Set objRegEx = CreateObject("VBScript.RegExp")
    With objRegEx
      .Global = True
      .IgnoreCase = True
      .Pattern = "\s{2,20}"
    End With
    
    Set objShell = CreateObject("WScript.Shell")
    Set objExecObject = objShell.Exec("cmd /c qwinsta /server:" & strComputer)
    
    Do Until objExecObject.StdOut.AtEndOfStream
    
        strSearch = "" : strUserName = "" : intSession = ""
        strLine = Trim(objExecObject.StdOut.ReadLine)
        WScript.Echo "Processing..:" & strLine
        
        'Get disconnected sessions.
        If InStr(strLine,"Disc") > 0 And InStr(strLine,"service") = 0 Then
            strSearch = objRegEx.Replace(strLine,";")
            strUserName = Split(strSearch,";")(0)
            intSession = Split(strSearch,";")(1)
            WScript.Echo strUserName & ";" & intSession
        End If
        
        'Get active sessions.
        strSearch = "" : strUserName = "" : intSession = ""
        If InStr(strLine,"Active") > 0 And InStr(strLine,"service") = 0 Then
            strSearch = objRegEx.Replace(strLine,";")
            strUserName = Split(strSearch,";")(1)
            intSession = Split(strSearch,";")(2)
            WScript.Echo strUserName & ";" & intSession
        End If
    
    Loop

End Function

User avatar
jvierra
Posts: 11056
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Packaged script not working with qwinsta command

Post by jvierra » Mon Mar 24, 2014 10:05 am

Be sure you have latest version of PrimalScript. If you still have problems then post your question in the product support forum for PrimalScript 2012: http://www.sapien.com/forums/viewforum.php?f=11

User avatar
clum09
Posts: 114
Joined: Thu Apr 24, 2008 9:11 am

Re: Packaged script not working with qwinsta command

Post by clum09 » Mon Mar 24, 2014 11:54 am

jvierra,

I know that the script works fine when it is not packaged.

Did you try to package the script into a .exe file and run the .exe file itself on the command console?

The version of PrimalScript I use is 6.5.164. What version of PrimalScript did you use to package this script?

User avatar
Alexander Riedel
Posts: 6152
Joined: Tue May 29, 2007 4:43 pm

Re: Packaged script not working with qwinsta command

Post by Alexander Riedel » Mon Mar 24, 2014 11:58 am

This is not a product support forum.
If you have questions or issues regarding a product feature please post in the corresponding product forum. This forum
is handled by volunteers to answer scripting questions.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 11056
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Packaged script not working with qwinsta command

Post by jvierra » Mon Mar 24, 2014 12:09 pm

Yes I packaged the script and an it at the command line. I am using 6.5.164 which is the latest as of last Tuesday.

If you still cannot get it to work then post in the Customer Support Forum at the link I posted.

There is no normal reason for this to not work but the product support people may know of issues that I do not know about. I can only verify that the script itself has no issue and that PrimalScript has no obvious problem with the script.

Locked

Who is online

Users browsing this forum: No registered users and 1 guest