Sign in to follow this  
Followers 0
PeanutJoe

Passing variable to batch file

7 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

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