Tigerweld

batch file won't run

22 posts in this topic

#1 ·  Posted

My batch file runs fine, but when I try running it from AutoIt it fails to write to the registry.

ShellExecuteWait( "c:\scripts\TellerInsight.bat", "", "c:\scripts")
Local $ipAddress = RegRead("HKCU\SOFTWARE\M&I Data Services\TellerInsight\DEFAULT\DS", "ClientIP")
MsgBox(1, "client ip", "client ip is: " & $ipAddress)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Why not just use:

RunWait(@Comspec & ' /c "C:\Scripts\TellInsight.bat"', '', @SW_HIDE)

Even better why not just write your batch commands into the script, can you post the contents?

Share this post


Link to post
Share on other sites

#3 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted

I tried

RunWait(@Comspec & ' /c "C:\Scripts\TellInsight.bat"', '', @SW_HIDE)

but got the same result,

Share this post


Link to post
Share on other sites

#5 ·  Posted

@Jos - you're right, but thought maybe taking out the file associations out of the equation might help.

@Tigerweld - have you tried Jos suggestion of adding #RequireAdmin at the top of the script?

Share this post


Link to post
Share on other sites

#6 ·  Posted

Tried #RequreAdmin and got same result.

Share this post


Link to post
Share on other sites

#7 ·  Posted

Are you able to post your batch?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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%

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#12 ·  Posted

that doesn't work either.

Share this post


Link to post
Share on other sites

#14 ·  Posted

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. :>

Share this post


Link to post
Share on other sites

#15 ·  Posted

Just the simple line of

RunWait(@Comspec & ' /c "C:\Scripts\TellInsight.bat"', '')

will not run the batch file.  I see the batch file open and close and it appears there may be a problem, but I can't read it quick enough.  It closes too quick.  Is there another way to run a batch file?

Share this post


Link to post
Share on other sites

#17 ·  Posted

Put a "pause" in your batch file

Share this post


Link to post
Share on other sites

#18 ·  Posted

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%

 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

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

Over and out

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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