Tigerweld Posted January 6, 2017 Share Posted January 6, 2017 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) Link to comment Share on other sites More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 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? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 6, 2017 Developers Share Posted January 6, 2017 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 More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 I tried RunWait(@Comspec & ' /c "C:\Scripts\TellInsight.bat"', '', @SW_HIDE) but got the same result, Link to comment Share on other sites More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 @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? Link to comment Share on other sites More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 Tried #RequreAdmin and got same result. Link to comment Share on other sites More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 Are you able to post your batch? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 6, 2017 Developers Share Posted January 6, 2017 (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 January 6, 2017 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 More sharing options...
BrewManNH Posted January 6, 2017 Share Posted January 6, 2017 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 GudeHow 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 More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 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 More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 (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 January 6, 2017 by Subz Link to comment Share on other sites More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 that doesn't work either. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 6, 2017 Developers Share Posted January 6, 2017 Have you read all replies or should I simply stop replying? 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 More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 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 More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 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? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 6, 2017 Developers Share Posted January 6, 2017 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 More sharing options...
Subz Posted January 6, 2017 Share Posted January 6, 2017 Put a "pause" in your batch file Link to comment Share on other sites More sharing options...
Tigerweld Posted January 6, 2017 Author Share Posted January 6, 2017 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 More sharing options...
spudw2k Posted January 6, 2017 Share Posted January 6, 2017 (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 January 6, 2017 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Developers Jos Posted January 6, 2017 Developers Share Posted January 6, 2017 (edited) I give up! reread my posts for the correct hint to get your problem solved. Over and out Edited January 6, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now