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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 4 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Packaged script not working with qwinsta command

Post by clum09 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Packaged script not working with qwinsta command

Post by jvierra »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Packaged script not working with qwinsta command

Post by jvierra »

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: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: Packaged script not working with qwinsta command

Post by clum09 »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Packaged script not working with qwinsta command

Post by Alexander Riedel »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Packaged script not working with qwinsta command

Post by jvierra »

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.
This topic is 10 years and 4 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked