Sign in to follow this  
Followers 0
carfra

How to use OS variables

6 posts in this topic

Hi everybody,

I'm a new user on the forum.

I have a problem, I have a batch file with these content:

Set TS=%SESSIONNAME:~,3%

If Not %TS%!==RDP! If Not %TS%!==ICA! set TS=

This batch file detect if the current sesion is a RDP o ICA session, I need to implement this funcionality on a AutoIT script,

Anybody can help me ¿?

Regards,

Frank

Share this post


Link to post
Share on other sites



Hi everybody,

I'm a new user on the forum.

I have a problem, I have a batch file with these content:

Set TS=%SESSIONNAME:~,3%

If Not %TS%!==RDP! If Not %TS%!==ICA! set TS=

This batch file detect if the current sesion is a RDP o ICA session, I need to implement this funcionality on a AutoIT script,

Anybody can help me ¿?

Regards,

Frank

Reading the manual. Not only will it make you smarter, it will make you look smarter.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

More info about it,

My objective is detect when the script is running on a Windows 2000 Server or Windows 2000 Worskstation.

The @OSVersion macro detect as WIN_2000 when I run it from a Windows 2000 Workstation and Windows 2000 Server.

Regards,

Frank

Share this post


Link to post
Share on other sites

Here is one way you could go about it, there are probably more efficient methods, but I'll leave that for someone else to show you...

Not tested, but it should work

#include <Constants.au3>

; get the output of the set command as a string
$s_return = _CMDreturn("set")

; split the string into an array
$a_env = StringSplit($s_return, @CR)

; loop through the array
For $x = 1 To $a_env[0]
    $line = $a_env[$x]
    ; remove a starting @LF if it is there
    If StringMid($line, 1, 1) = @LF Then StringTrimLeft($line, 1)
    
    ; if the line starts with TS= then pop up a msgbox sohowing the rest of the value
    If StringMid($line, 1, 3) = "TS=" Then
        StringTrimLeft($line, 3)
        MsgBox(0, "Type of connection", $line)
    EndIf
Next


Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string
    $cmdreturn = ""
    $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDIN_CHILD)
    While 1 ; loop through the return from the command until there is no more
        $line = StdoutRead($stream)
        If @error Then ExitLoop
        $cmdreturn &= $line
    WEnd
    Return $cmdreturn
EndFunc   ;==>_CMDreturn

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

I found the solution on the documentation....

the line is:

$var = StringLeft(EnvGet("SESSIONNAME"),3)

Share this post


Link to post
Share on other sites

I found the solution on the documentation....

the line is:

$var = StringLeft(EnvGet("SESSIONNAME"),3)

Can also pull it from the registry:

The following is modified from dplaut's post @ http://www.autoitscript.com/forum/index.ph...st&p=636082

MsgBox(0,"",_IsRemoteSession())

Func _IsRemoteSession()
  Local $bRemoteSession = 0
  Local $strSessionName = RegRead("HKEY_Current_User\Volatile Environment", "SessionName")
  If StringInStr($strSessionName, "RDP")  OR StringInStr($strSessionName, "ICA") Then
;ConsoleWrite("RemoteSession" & @CRLF & $strSessionName & @CRLF)
    $bRemoteSession = 1
  Else
;ConsoleWrite("Regular Session" & @CRLF & $strSessionName & @CRLF)
  EndIf

  Return $bRemoteSession

EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0