Jump to content

batch file won't run


Recommended Posts

  • Developers
17 minutes ago, Subz said:

Why not just use:

Should be the same ...right?

Maybe the batchfile requires Admin level execution when updating the registry? 
Add #RequireAdmin to the top of the script and try again.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Think this is an x86/x64 issue...  Try running the script with autoit_x64.exe
It is likely updating  or you are reading the "wrong" hive in the registry. 

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 minutes ago, Tigerweld said:

Tried #RequreAdmin and got same result.

What errors do you see when you run it?

Oh wait, you won't see any errors because you're hiding the console window and closing it immediately.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

batch code is

SETLOCAL
SET MY_SESSION_ID =unknown
SET CLIENTIP =unknown
REM retrieve session id of logged on user
FOR /f "tokens=3-4" %%a IN ('query session %username%') DO @if "%%b"=="Active" SET MY_SESSION_ID=%%a
REM using session id lets retrieve the ip of the client
FOR /f "tokens=2*" %%a IN ('Reg Query HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\Ica\Session\%MY_SESSION_ID%\Connection /v ClientAddress') DO SET "CLIENTIP=%%~b"

REM write ip address back to registry so AutoIt script can read it for continuation
REG ADD "HKCU\Software\M&I Data Services\TellerInsight\DEFAULT\DS" /f /v ClientIP /t REG_SZ /d %CLIENTIP%

exit /B %EXIT_CODE%

 

Link to comment
Share on other sites

What about:

Opt('ExpandVarStrings', 1)

Global $x = 1, $sREG_SESSION = 'HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\Ica\Session', $sKEY_SESSION
While 1
    $sKEY_SESSION = RegEnumKey($sREG_SESSION, $x)
        If @error Then ExitLoop
    ;~ Compare UserName with logged on user
    If RegRead('$sREG_SESSION$\$sKEY_SESSION$\Connection', 'UserName') = @UserName Then
        If RegRead('$sREG_SESSION$\$sKEY_SESSION$\Connection', 'SessionState') = 2 Then
            RegWrite('HKCU\Software\M&I Data Services\TellerInsight\DEFAULT\DS', 'ClientIP', 'REG_SZ', RegRead('$sREG_SESSION$\$sKEY_SESSION$\Connection', 'ClientAddress'))
            ExitLoop
        EndIf
    EndIf
    $x += 1
WEnd
Global $ipAddress = RegRead("HKCU\SOFTWARE\M&I Data Services\TellerInsight\DEFAULT\DS", "ClientIP")
MsgBox(1, "client ip", "client ip is: " & $ipAddress)

Session State Info

        ;~  SessionState(0) = "Unknown"
        ;~  SessionState(1) = "Connected"
        ;~  SessionState(2) = "Active"
        ;~  SessionState(3) = "Connecting"
        ;~  SessionState(4) = "Shadowing"
        ;~  SessionState(5) = "Disconnected"
        ;~  SessionState(6) = "Idle"
        ;~  SessionState(7) = "Listening"
        ;~  SessionState(8) = "Resetting"
        ;~  SessionState(9) = "Down"
        ;~  SessionState(10) = "Init"

Edited by Subz
Link to comment
Share on other sites

Actually Jos is correct, when I posted, I copy and pasted your registry path, $sREG_SESSION should have been:

$sREG_SESSION = 'HKLM64\SOFTWARE\Citrix\Ica\Session'

This worked for me on our Dev Citrix Server Host.

Sorry pulled an all nighter so brain is a bit frazzled. :>

Link to comment
Share on other sites

  • Developers

Ok ..  last try: 

change /c to /k to leave the cmd window open and see any potential error.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

C:\scripts>ECHO OFF
ERROR: The system was unable to find the specified registry key or value.
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

C:\scripts>

I assume the error is because of the HKLM read.

ECHO OFF
REM Retrieve Logged on User's Session ID
REM and from this get the ip address assoc with this session ID
REM set ip in a reg value for autoit to read
REM 
REM 

SETLOCAL
SET MY_SESSION_ID =unknown
SET CLIENTIP =unknown
REM retrieve session id of logged on user
FOR /f "tokens=3-4" %%a IN ('query session %username%') DO @if "%%b"=="Active" SET MY_SESSION_ID=%%a
REM using session id lets retrieve the ip of the client
FOR /f "tokens=2*" %%a IN ('Reg Query HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\Ica\Session\%MY_SESSION_ID%\Connection /v ClientAddress') DO SET "CLIENTIP=%%~b"

REM write ip address back to registry so AutoIt script can read it for continuation
REG ADD "HKCU\Software\M&I Data Services\TellerInsight\DEFAULT\DS" /f /v ClientIP /t REG_SZ /d %CLIENTIP%

exit /B %EXIT_CODE%

 

Link to comment
Share on other sites

You could also bypass the batch file and use the method I shared to get the session ID, then just use the native REG* AutoIt functions for the registry work.

Spoiler
#include <AutoItConstants.au3>

Local $iSessionID = _GetSessionID()
If not $iSessionID Then
    Msgbox(0,"Failed to determine Session ID","Session ID not found",5)
    Exit
EndIf

msgbox(0,"SessionID",$iSessionID)

Func _GetSessionID()
    Local $sCMD = 'for /f "tokens=3,4" %a in (''c:\windows\system32\query.exe session %username%'') do @if "%b"=="Active" echo %a'

    Local $iPID = Run(@ComSpec & " /c " & $sCMD, @ScriptDir, @SW_HIDE, $STDERR_MERGED)
    While ProcessExists($iPID)
        Sleep(100)
    WEnd
    Local $iMY_SESSION_ID = Number(StdoutRead($iPID))
    Return $iMY_SESSION_ID
EndFunc

 

 

Edited by spudw2k
Link to comment
Share on other sites

  • Developers

I give up! reread my posts for the correct hint to get your problem solved.

Over and out

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...