Packaged script not working with qwinsta command

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 3 weeks 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.
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.
VBScript Code
Double-click the code block to 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
Thak you in advance.
User avatar
Alexander Riedel
Posts: 8489
Last visit: Thu Apr 18, 2024 1:15 pm
Answers: 20
Been upvoted: 37 times

Re: Packaged script not working with qwinsta command

Post by Alexander Riedel »

First step would be to determine what engine you use.
You say you tried them all, but pick the one you WANT to use use and stick with that. Oh and let us know.

Secondly I see nothing about OS and platform. If the tool is 64 bit only and you package 32 bit it won't work.

This statement "cmd /c qwinsta /server:" is dangerous as it assumes that cmd.exe and qwinsta.exe are in PATH. Better to use fully qualified path names. Specially if you run that from a logon script.

Subsitute qwinsta with something mundane that always works, like
dir and see if you get output.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 10 years and 3 weeks 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.