Batch file to ask for session ID in tsdiscon? - session

Pardon my very broad question here guys. I don't ever really do much coding (at all) and was hoping you guys could help me out. Basically what I would like to do is have an end user run a script that asks them what Session ID they would like to disconnect. This will be used in conjunction with the "tsdiscon" command.
So the script would open > Ask for session ID > disconnect that session ID.
Seems pretty simple but like I said, I never do any of this. Thank you guys for any help!

It's not very robust, but try this:
sidkill.bat
#echo off
cls
set /p sid=Enter Session ID:
echo Disconnecting session %sid%
tsdiscon %sid%

Related

How to generate log in service now when a browser is closed?

I need to generate logs in service now whenever the browser is closed or the session is expired. I tried using global business rule but couldnt achieve it. It will be greatfull if i can if i get an idea to achieve this.
Thanks in advance.
I assume you already know how to generate a log and such in ServiceNow, and the problem you're having, is how to run code when the user closed their browser.
The best solution would probably be to create an onload client script which sets onbeforeunload to a function that triggers a log.
More on that here: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
For the second part of your question, user sessions are tracked in a "user sessions" table. If you want to also log when theirs expires, you can do so with a business rule on that table.
You can use
GlideAjax to call from your client script to a server side script include.
Look at GSLog
Try this one
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA");

How to edit Parse.com users with Javascript

All I want to do is set a boolean that all the users have to false using a Javascript tool. I'm getting "Error 206: ParseUserCannotBeAlteredWithoutSessionError" when I try to do so. The user I log in as for the tool has an "Administrator" role that has read/write CLP for the User table.
In this blog (http://blog.parse.com/learn/engineering/parse-security-iii-are-you-on-the-list/) they briefly mention the Master Key, but never explain how to use it. This: https://www.parse.com/questions/masterkey-in-nodejs didn't work either, the script wouldn't even run.
Can someone please tell me how to use the master key in JS like Parse probably should somewhere in their documentation?
You can set the master key while initializing the Parse. You can do this,
Parse.initialize( applicationId, javaScriptKey, masterKey)
more information can be found here.
Hope this helps.

Get currently logged on user on Windows

Example: I am logged in as user TestUser. From this user I am going to run a command line as an administrator named AdminUser.
Is it possible from this command line to determine the name of the currently logged in TestUser?
I already have scheduled task which is always running as AdminUser, but in its action (batch file), I need to name of the currently logged in user.
Any ideas?
As far as I know this is not really possible.
Depending on how much you know about the environment of the users, the following might be a workaround however:
The command
qwinsta
will give you a list of sessions for the computer. Within these sessions one will be the active one, so if this program is used in an interactive session only this will basically contain the "logged in user" as you described it (it is far more complicated really, there could be many users logged on but only one can be active and I just hope you know enough about the usage scenario of your program to make use of that). You could parse the output and work with that username.
Of course this is a dirty hack and it assumes that during the run time of your task there is no chance that users change.
Also though I chose the qwinsta.exe because it is a very basic approach that needs no API calls or something I am still not sure if the CMD has sufficient parsing capabilities to get the necessary information for you.
%username% variable contains.. well, the user name.
echo/%username%
EDIT
As you said, because you are in a scheduled task, you can get the user name from Windows Registry
#echo off
for /f "tokens=3" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\1 /v LoggedOnUserName') do (
set "user=%%a")
set "user=%user:.\=%"
echo/%user%
Now %user% variable contains the logged user name.
Here is a quick way to make this happen using a batch file would be this command:
for /F "tokens=1,2" %%i in ('qwinsta /server:%COMPUTERNAME% ^| findstr "console"') do set tempVar=%%j
echo %tempVar% will show whatever user is actually logged in. Not the user who launched the batch file.

Starting new background GUI login session or loginwindow on OS X, CGSCreateLoginSessionWithDataAndVisibility function

I'm writting remote login app and I want to include the possibility to start new GUI session for different user. Goal is similar to what is done on Screen Sharing.app when user (different than already logged in) is connected - he can create new desktop without messing with session currently displayed. Is there an API for this? Maybe could You give me some useful links? I can't find anything to point me to the right direction so far.
Edit:
I am already able to connect to running "background" GUI sessions. Now I want to have a possibility to create session for user which is not logged in yet.
Edit: Spawning loginwindow under WindowServer process will also do the trick. When only one user is logged in, loginwindow process is terminated. Additionally - maybe there's a possibility to prevent loginwindow termination?
Edit:
I've tracked down function from private API which executes new loginwindow process under WindowServer and it works OK. Function is called CGSCreateLoginSessionWithDataAndVisibility, the problem is - this is private function I don't know what parameters it takes. Now I call it like this:
CGSSessionID outSession = 1;
CGSCreateLoginSessionWithDataAndVisibility(&outSession, NULL, false);
Does anyone know what arguments are used in CGSCreateLoginSessionWithDataAndVisibility or is there another way to achieve what I want?
Short of reverse engineering fast user switching and some hackage, I'm not too sure this could be accomplished. AFAIK there are not any public APIs other than some notifications and session states that can be observed for when the user switches users. Some info here on how to observe those notifications (you can do it through Cocoa or Carbon) and how to fetch the current sessions information.
Hope this helps, sorry for not being more helpful!

Is it possible to kill one or all session in server side

My question is in the title,
I would like to kill a session in server side using session id or other...
Thanks for your responses
Session.Abandon maybe?
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon.aspx
HttpSessionState is fully documented here:
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.aspx
Edit - Oh I see, you want to kill some OTHER session, from another separate session? I'm don't think that's possible from the MVC/webapp side of things.
Maybe an IIS extension?

Resources