Jump to content

Passing variable to batch file


Recommended Posts

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

  • Moderators

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

"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

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

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]

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

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

App: Au3toCmd              UDF: _SingleScript()                             

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