PeanutJoe Posted January 25, 2012 Share Posted January 25, 2012 Hello, I have a domain login script (batch file) that calls an autoit script that basically just uses the macro @OSversion to determine what the operating system is running the script. The script is below. I'm just using autoit to pass the OS (ex: Win_7) by writing the OS to a text file and then having the batch file open the text file to read the OS. Is there another way to pass this information to my batch file other than using a temporary file? I tried using an environment variable (envset) from autoit to pass to the batch file but that doesn't work. Local $file = @TempDir & "\Win_Ver.txt" FileDelete ($file) FileOpen ($file) FileWrite ($file, @OSVersion) FileClose ($file) Exit My solution works but I'm looking to see if there's another way to pass the OS to my batch file without that info to a temp file. Thanks, Mike Link to comment Share on other sites More sharing options...
PeanutJoe Posted January 25, 2012 Author Share Posted January 25, 2012 This is the command I'm using in my batch file to read the contents of the temp file to a variable set /p OS_VER=<%temp%win_ver.txt Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 25, 2012 Moderators Share Posted January 25, 2012 (edited) Hi, PeanutJoe. How large is your batch file? Perhaps you can use the AutoIT script to create the batch file altogether. This would create and run a simply batch file: $file = FileOpen("C:Testing.txt", 9) FileWriteLine($file, "@echo off") FileWriteLine($file, "") FileWriteLine($file, "SET /P ANSWER=Do you want to continue (Y/N)?") FileWriteLine($file, "echo You chose: %ANSWER%") FileWriteLine($file, "if /i {%ANSWER%}=={y} (goto :yes)") FileWriteLine($file, "if /i {%ANSWER%}=={yes} (goto :yes)") FileWriteLine($file, "goto :no") FileWriteLine($file, ":yes") FileWriteLine($file, "echo You pressed yes!") FileWriteLine($file, "pause") FileWriteLine($file, "exit /b 0") FileWriteLine($file, ":no") FileWriteLine($file, "echo You pressed no!") FileWriteLine($file, "pause") FileWriteLine($file, "exit /b 1") FileWriteLine($file, "") FileWriteLine($file, "pause") FileClose($file) FileMove("C:Testing.txt", "C:Testing.bat", 1) ShellExecute("C:Testing.bat", "") Edited January 25, 2012 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
blindwig Posted January 26, 2012 Share Posted January 26, 2012 Use this AutoIt Script: #AutoIt3Wrapper_Change2CUI=y ConsoleWrite(@OSVersion & @CRLF) Compile it to an EXE, for example OSVER.EXE And then put this line in your batch to read the output: FOR /f %%A in ('OSVER.EXE') do SET OSVER=%%A My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Syed23 Posted January 26, 2012 Share Posted January 26, 2012 (edited) Hi PeanutJoe, Welcome to Autoit forum! The code below is what you are looking for ?#include"File.au3" $File = FileOpen(@DesktopDir&"Test.bat",1) FileWriteLine($File,"set /p OS_VER="&@OSVersion) FileClose($File) MsgBox(0,"Success","Created the batch file") Edited January 26, 2012 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font] Link to comment Share on other sites More sharing options...
PeanutJoe Posted January 29, 2012 Author Share Posted January 29, 2012 Use this AutoIt Script: #AutoIt3Wrapper_Change2CUI=y ConsoleWrite(@OSVersion & @CRLF) Compile it to an EXE, for example OSVER.EXE And then put this line in your batch to read the output: FOR /f %%A in ('OSVER.EXE') do SET OSVER=%%A In think the above will do the trick. I didn't want to use Auotit entirely since I have other admins that could possibly edit the script. Thanks guys! M Link to comment Share on other sites More sharing options...
Exit Posted January 29, 2012 Share Posted January 29, 2012 Why not using native BAT: @echo off for %%i in (6.1 6.0 5.2 5.1 5.0) do (ver | findstr "%%i" >nul && set _OSversion=%%i) echo Your OS version is %_OSversion% echo Info: echo 6.1 = Win 7 echo 6.0 = Vista echo 5.2 = Win 2003 echo 5.1 = Win XP echo 5.0 = Win 2000 App: Au3toCmd UDF: _SingleScript() 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