MSFN Forum: Help me to redirect to a file any errors from my batch. - MSFN Forum

Jump to content


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Help me to redirect to a file any errors from my batch. Rate Topic: -----

#1 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 04 March 2006 - 04:00 PM

Hi all. I have a batch file which runs from GuiRunOnce during the first logon. This script is long and makes many things (installations, copy, delete etc), so I want to redirect to a log file any error messages (eg from a failed copy or delete command), because I need the output for troubleshooting purposes. Now I am trying to note down any errors I see, but I haven't the time needed (as the script is being executed quickly) and I don't want to add any pause or sleep commands in it. I read a lot in the net about redirection (stderr stream) but strangely nothing works for me! Whatever I type in the run box (eg C:\a_script_with_errors.cmd 2>Errors.log), either ALL the output will go to the screen or to the log file. What I want is to be able to see my echo messages (and other commands, eg "1 file copied") on the screen and only any erros to be logged. Is this possible under Windows XP? Which is the correct syntax I should use under GuiRunOnce section in Winnt.sif? Now I have written "%systemdrive%\Installations.cmd 2>> C:\Error.log" (without quotes) but I think that it won't work. Of course, the ideal would be to have all the output (with errors) both on my screen and in a log file, but I think that this is impossible with common dos commands. But maybe a specific utility can make it...
Irrelevant: Is it possible to disable the press F6 and F2 messages from my unattended CD? I have all the necessary drivers and I would like to reduce the text mode portion by 10 seconds. Thank you.


#2 User is offline   jbm 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 635
  • Joined: 16-September 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 04 March 2006 - 04:08 PM

I believe "mybat.cmd 2>errors.txt" is what you want.

#3 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 04 March 2006 - 05:00 PM

Have you thought about using a VBS script that checks things and makes the reports.
Example This Checks For C:\Test.txt then copies it top D:\Test.txt
This script reports if it was successful or not successfull.

Quote

Const OverwriteExisting = TRUE
  Dim Fso,Act,Report_Log,Ts
  Set Fso = CreateObject("Scripting.FileSystemObject")
  Set Act = CreateObject("Wscript.Shell")
   Report_Log = Act.ExpandEnvironmentStrings("%Systemdrive%\Report_UaInstall.log")
 '''' OPEN THE REPORT_UAINSTALL.LOG
  Set Ts = Fso.CreateTextFile(Report_Log) 
	 Ts.WriteLine Now() & Space(5) & Act.ExpandEnvironmentStrings("%Username%") & vbCrLf & "Preparing To Copy C:\Test.txt To D:\"
  If Fso.FileExists("C:\Test.txt") Then
	 Fso.CopyFile "C:\Test.txt" , "D:\" , OverwriteExisting
	 Ts.WriteLine "Confirm Copy Completed"
 Else
   Ts.WriteLine "Copy File Error" & vbTab & "C:\Test.txt" & vbTab  & "Was Not Found"
 End If 
Ts.Close

If you want help with the vbs script post the cmd script and I will try and do it so they both work together.

#4 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 04 March 2006 - 06:02 PM

Hi again. Thanks for your answers. The "mybat.cmd 2>errors.txt" doesn't work, at least from the Run command box. So I think that it will not work during the first logon. What it does is to create the errors.txt file which is empty though and display on the screen both the output (in my case an echo message) and the error (in my test.cmd the error is "The system cannot find the file specified"). But I want the error messages to be (only or even better also) in the file. As I said, I have searched the net and tried many different combinations with >>, 2> or 2>&1, but none of them work. I believe that maybe the ability to redirect only the stderr is not supported in Windows XP.
As for the .vbs, I am a new scripter and I don't know this language. So I prefer to keep things simple and use some standard commands and methods. The only .vbs I have made is for closing some windows which opens at the end of some silent installations (AppActivate, SendKeys etc). But if you want to explain me the logic of your method it is welcome.

#5 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 04 March 2006 - 06:19 PM

Ok I found a Cmd Script I made a while ago it output the error you will have to edit to match your needs
Just run this with out editing and on your desktop look for this file R1TestLog.txt
I just prefer using VBS is all.

Quote

echo off && Cls && Mode 69,3 && Color 5e
:: REMOVE THE :: IF YOU ARE INSTALLING FROM A CD OR DVD DRIVE
::for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\SETUP.exe set CDROM=%%i
set P2=Ping -n 2 127.0.0.1
set P3=Ping -n 3 127.0.0.1
set P4=Ping -n 4 127.0.0.1
::REMOVE THE :: IF YOU ARE INSTALLING FROM A CD OR DVD DRIVE
::set TEST=%cdrom%\Apps
:: ADD :: IF TO THE BELOW LINE IF YOU ARE INSTALLING FROM CD OR DVD DRIVE
set TEST=%Systemdrive%\Apps
set TEST1=%TEST%\Cleanup.cmd
set TEST2=%TEST%\ACEMCP591\ACEMCP591PRO.EXE
set TEST3=%TEST%\Alcohol\AlcoholInstall.cmd
set TEST4=%TEST%\Flash\FlsPlyr7Install.cmd
set TEST5=%TEST%\Winamp\WinAmpInstall.cmd
set Name1=Cleanup.cmd
set Name2=AcePro591Install.cmd
set Name3=AlcoholInstall.cmd
set Name4=FlsPlyr7Install.cmd
set Name5=WinAmpInstall.cmd
set TESTLOG="%UserProfile%\DESKTOP\R1TestLog.txt"
::Set M=Missing-^>
Set Proc=Processing..
Set Line=:------------------------------------------------------------------:
for /f "Tokens=*" %%i in ('time /t') do set TIMET=%%i
for /f "Tokens=*" %%i in ('date /t') do set DATET=%%i
for /f "Tokens=*" %%i in ('ver') do set V=%%i
TITLE START CHECK 1
cls && Color f1
%P3%>nul | Echo Preparing Test Your RunOnceEx.cmd


::::::::::::::::CHECK FOR FILE 001 IN YOUR RUNONCE
TITLE CHECK %TEST1%
CLS && COLOR F9
:CHECK1
If Exist %TEST1% Echo %Proc% %Name1% && %P3%>nul && Goto :Next1B

If Not Exist %TEST1% %Proc% %Name1% && %P3%>nul && Goto :Missing1

:Missing1
TITLE Missing %Name1%
CLS && COLOR FC
::If Exist %TESTLOG% Del /s /q %TESTLOG%
echo.
echo %Line% > %TESTLOG%
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name1% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo -^> This File : %Name1% Is Missing...!!! && %P3%>nul && goto :Next1a
goto EOF

:Next1a
TITLE Failed %Name1%
CLS && COLOR 2F
echo.
Echo -^> %Name1% Failed Preparing Check %Name2% && %P3%>nul && GOTO :CHECK2
goto EOF

:Next1b
TITLE Passed %Name1%
CLS && COLOR 3F
::If Exist %TESTLOG% Del /s /q %TESTLOG%
echo.
echo %Line% > %TESTLOG%
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name1% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name1% Has Passed....!! && %P3%>nul && GOTO :CHECK2
goto EOF
::::::::::::::::CHECK FOR FILE 001 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 002 IN YOUR RUNONCE
:CHECK2
TITLE CHECK %TEST2%
CLS && COLOR 4F

if Exist %TEST2% echo %Proc% %Name2% && %P3%>nul && Goto Next2

If not Exist %TEST2% Echo %Proc% %Name2% && %P3%>nul && Goto Missing2

:Next2
TITLE Passed %Name2%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name2% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name2% Has Passed....!! && %P3%>nul && goto :CHECK3
goto EOF

:Missing2
TITLE Missing %Name2%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name2% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo -^> This File : %Name2% Is Missing...!!! && %P2%>nul && goto :Next2a
goto EOF

:Next2a
TITLE Failed %Name2%
CLS && COLOR 2F
echo.
Echo -^> %Name2% Failed Preparing Check %Name3% && %P3%>nul && GOTO :CHECK3
goto EOF

::::::::::::::::CHECK FOR FILE 002 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 003 IN YOUR RUNONCE
:CHECK3
TITLE CHECK %TEST3%
CLS && COLOR 5F

if Exist %TEST3% echo %Proc% %Name3% && %P3%>nul && Goto :Next3

If not Exist %TEST3% Echo %Proc% %Name3% && %P3%>nul && Goto :Missing3

:Next3
TITLE Passed %Name3%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name3% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name3% Has Passed....!! && %P3%>nul && goto :CHECK4
goto EOF

:Missing3
TITLE Missing %Name3%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name3% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name3% Is Missing...!!! && %P3%>nul && goto :Next3a
goto EOF

:Next3a
TITLE Failed %Name3%
CLS && COLOR 2F
echo.
Echo -^> %Name3% Failed Preparing Check %Name4% && %P3%>nul && GOTO :CHECK4
goto EOF

::::::::::::::::CHECK FOR FILE 003 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 004 IN YOUR RUNONCE
:CHECK4
TITLE CHECK %TEST4%
CLS && COLOR 5F

if Exist %TEST4% echo %Proc% %Name4% && %P3%>nul && Goto Next4

If not Exist %TEST4% Echo %Proc% %Name4% && %P3%>nul && Goto Missing4

:Next4
TITLE Passed %Name4%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name4% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name4% Has Passed....!! && %P3%>nul && goto CHECK5
goto EOF

:Missing4
TITLE Missing %Name4%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name4% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name4% Is Missing!!!! && %P3%>nul && goto :Next4a
goto EOF

:Next4a
TITLE Failed %Name4%
CLS && COLOR 2F
echo.
Echo -^> %Name4% Failed Preparing Check %Name5% && %P3%>nul && GOTO :CHECK5
goto EOF

::::::::::::::::CHECK FOR FILE 004 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 005 IN YOUR RUNONCE
:CHECK5
TITLE CHECK %TEST5%
CLS && COLOR 5F

if Exist %TEST5% echo %Proc% %Name5% && %P3%>nul && Goto Next5

If not Exist %TEST5% Echo %Proc% %Name5% && %P3%>nul && Goto Missing5

:Next5
TITLE Passed %Name5%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name5% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name5% Has Passed....!! && %P3%>nul && goto quit
goto EOF

:Missing5
TITLE Missing %Name5%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name5% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name5% Is Missing!!!! && %P3%>nul && goto :Next5a
goto EOF

:Next5a
TITLE Failed %Name4%
CLS && COLOR 2F
echo.
Echo -^> %Name4% Failed Preparing Check %Name5% && %P3%>nul && GOTO :quit
goto EOF

::::::::::::::::CHECK FOR FILE 005 IN YOUR RUNONCE

:quit
TITLE Gsm Good Bye!
CLS && COLOR F1
echo.

Echo Gsm RunOnceEx Test Completed && %P4%>nul
exit

The logic is I could make a far smaller script then the above.

VBS Script of the same cmd file

Quote

Dim Act, ChkCmd, Dtop, Fso, Line,Report_R1, SD, strChkCmd, Ts
   Set Act = CreateObject("Wscript.Shell")
   Set Fso = CreateObject("Scripting.FileSystemObject")
   SD = Act.ExpandEnvironmentStrings("%Systemdrive%\Apps")
   Dtop = Act.SpecialFolders("Desktop")
   Report_R1 = Dtop & "\R1_Instal.log"
   Line = Chr(171) & " ---------------------------------- " & Chr(187)
   Set Ts = Fso.OpenTextFile(Report_R1,2,True)
	ChkCmd =  Array(SD & "\ACEMCP591\ACEMCP591PRO.EXE",SD & "\Alcohol\AlcoholInstall.cmd",_
	SD & "\Cleanup.cmd",SD & "\Flash\FlsPlyr7Install.cmd",SD & "\Winamp\WinAmpInstall.cmd")
	
   For Each strChkCmd In ChkCmd 
   If Fso.FileExists(strChkCmd)Then
   Act.Popup "Confirm File" & vbCrLf & strChkCmd,3,"Confirm", 0 + 32
   Ts.WriteLine "Confirm This File Was There" & vbCrLf & strChkCmd & vbCrLf & "Install Started At : " & Now() & vbCrLf & Line
   '''' UNCOMMENT THE BELOW LINE TO MAKE ACTIVE
   '' Act.Run(strChkCmd),1,True 
   Else 
	Act.Popup "Error Missing File" & vbCrLf & strChkCmd,3,"Missing", 0 + 32
	Ts.WriteLine "Cannot find This File" & vbCrLf & strChkCmd & vbCrLf &  "Error Time And Date : " & Now() & vbCrLf & Line
	End If 
   Next 
   
   Ts.Close
   Act.Run(Chr(34) & Report_R1 & Chr(34)),1,False

This post has been edited by gunsmokingman: 04 March 2006 - 06:43 PM


#6 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,436
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 05 March 2006 - 09:55 AM

Just for the record:

Quote

somebat.cmd > mylog.txt
Will REPLACE the contents of mylog.txt with the output of the command somebat.cmd, i.e. if the somebat.cmd has multiple output and the last one is an empty line, the resulting mylog.txt will be EMPTY.

Quote

somebat.cmd >> mylog.txt

Will APPEND to the contents of mylog.txt the output of the command somebat.cmd, i.e. if the somebat.cmd has multiple output and the last one is an empty line, the resulting mylog.txt will be a log of all outputs + an empty line.

What you need to log is "standard output", NOT "standard error":
http://www.robvander...edirection.html

jaclaz

This post has been edited by jaclaz: 06 March 2008 - 12:31 PM


#7 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 06 March 2006 - 02:02 AM

Hi all. Thank you for your support. Here is my feedback after a real format: I am using the line "%systemdrive%\Installations.cmd 2>%systemdrive%\Errors.log" (quotes are necessary) under [GuiRunOnce] section of Winnt.sif and I have the result I want. During the first logon, I can see the real-time output of Installations.cmd in the command prompt, except from any errors that are being logged to the Errors.log. Indeed, after the load of the shell, I can see this file in my C:\ (systemdrive) which does have the error messages only. Jaclaz, if I use your commands, I will redirect the standard output so I won't be able to see the progress of my installations. I want only the errors from my batch to be logged in the Errors.log file for troubleshooting purposes.
What is really strange is this: When I was making some tests from the run box with the command "test.cmd 2>Errors.log", I was using a copy command in it to copy a non-existent file. Despite the 2> operator, the created error "The system cannot find the file specified" was displaying to the command prompt window and not to the destination file (errors.log), which was empty. When I decided to add more errors in my test.cmd ("ech Hi all" and "del C:\yo.rm"), I ascertained that these error messages was not being displayed in the prompt but in the errors.log ('ech' is not recognized as an internal or external command, operable program or batch file. Could Not Find C:\yo.rm). So I understood that my syntax was correct, the file was being created and it was recording the errors normally, except from the error with the copy command. This screw-up made me to post here and now I know that Jbm's reply was correct. As I said, during the first logon at my real windows setup, the command worked great and redirected the standard error stream to the Errors.log file. Under those circumstances, the error message "The system cannot find the file specified" is normally being logged in my log file. I can't understand why it's not the same from the run box.

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 06 March 2006 - 02:44 AM

The output about not finding the file isn't stderr, therefore it is not redirected as such.

I can copy what the guy below me has written without error, however since he hasn't written anything yet, I am not given the opportunity to do so, it is not my copying that therefore has an error.

As the message stated, it cannot find the file, it is the finding which is the problem not the copying. This leads me to an obvious response, fix your coding to prevent these eventualities first.
IF EXIST "E:\To Be Copied\A File.ext" COPY "E:\To Be Copied\A File.ext" "G:\Somewhere Else"2>NUL
<Edit>
I have used NUL, whereas you would obviously use your chosen file, and possibly, depending upon your requirements, append, (>>).
</Edit>

This post has been edited by Yzöwl: 06 March 2006 - 08:59 AM


#9 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,436
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 06 March 2006 - 07:14 AM

Yzöwl said:

The output about not finding the file isn't stderr, therefore it is not redirected as such.

Yes, that's what I meant.....

...just an idea, but you could use a TEE external command:
http://www.robvanderwoude.com/tee.html

http://www.kilowatts...om/PoofPage.htm

http://gnuwin32.sour...s/coreutils.htm

jaclaz

#10 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 06 March 2006 - 06:51 PM

Hi all. Jaclaz, I think that this tee command is very useful, but I can't get it worked. As I said, the best solution would be to copy everything both in the screen and in a log file. Can you please help me with the syntax? Give me a real example if you can. I am using this simple .cmd but no log file creation. I get the "file not found" error, after the dir results and if I create myself an empty mylog.log file, it keeps to be empty after the batch execution. Keep in mind that I am a new scripter. I have installed the GNUwin32 package and copied the tee.exe into system32. The description of the command didn't help me.
@echo off
dir F:\ ¦ tee -a C:\mylog.log
sleep 5
EXIT

Yzowl, I understood that when the system cannot find a file to copy (or whatever), it's not a stderr but a stdout. That's why when I run my test.cmd from run box I see this message in the command prompt and not in the log. But why during the execution of my script (GuiRunOnce) these messages were being logged in my errors.log? I had 3 lines with the error "The system cannot find the file specified". Also, what I gain if I use the "if exist" command? I tried it and find out that the message "The system cannot find the file specified" is not displayed anywhere. The good point whould be to have a log entry: "The file E:\To Be Copied\A File.ext doesn't exist". So I would know that I have to put that file there. If I use this method, I won't even know about any errors. Here is my test.cmd:
@echo off
Echo ready for the step one.
if exist "C:\yo.rm" COPY "C:\yo.rm" "F:\" 2>errors.log
sleep 5
EXIT

#11 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 06 March 2006 - 07:17 PM

VBS script are better at error catching then cmd scripts.

#12 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 08 March 2006 - 01:03 AM

Hi. Gunsmokingman, can you help me with this script? It is just for closing the "Found new hardware" wizard during Alcohol 120% installation. I want to run Alcohol195.exe from my CD (from the same folder as .vbs) like all the other applications. But if I use the WshShell.Run ("Alcohol195.exe"), it pops-up an error in line 2 (during the first logon from GuiRunOnce) saying that the system cannot find the file. Now I put the exe in my systemdrive (using $OEM$) and I use the following syntax.

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("%systemdrive%\Alcohol195.exe")
WScript.Sleep 8000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys " "
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
WScript.Quit

The strange is that if I use the WshShell.Run ("Alcohol195.exe") command from the HDD (both .exe and .vbs in C:\), it starts the installation normally. Can you help me? Maybe this is the correct syntax: WshShell.Run (".\Alcohol195.exe")? Is there any way to convert the following code to .vbs, so I can use the %cdrom% variable in the .vbs and give a full path? Thanks.

set tagfile=\WIN51
for %%i in (c d e f g h) do if exist "%%i:%tagfile%" set cdrom=%%i:

#13 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 08 March 2006 - 03:58 AM

What this script does
Checks to see if if CD or DVD drive
Checks to see if the CD or DVD has something in it
Then it checks for this file
"CD_DVD_DRIVE:\Apps\Alcohol120\setup.msi"
Then it start the install
If it cannot find the file then it waits for you to place the correct Disk in the drive. It will loop 6 times for a total of 60 seconds. Then it self closes. This script can be ran from any where on the local computer.
Save as InstallAlcohol120.vbs
To edit this vbs script
":\Apps\Alcohol120\setup.msi" change this color text to what you need
this change the file it looks for.
" /qb /norestart" and change this to what you need

Quote

Dim Act, Cmd1, Fso, Drv, strDrive,CT : CT = 0
Set Act = CreateObject("Wscript.shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Cmd1 = ":\Apps\Alcohol120\setup.msi"
Alcohol120
Function Alcohol120
Do
CT = CT + 1
Set Drv = Fso.Drives
For Each strDrive In Drv
If strDrive.DriveType = 4 Then
If strDrive.IsReady = True Then
If Fso.FileExists(strDrive.DriveLetter & Cmd1) Then
Act.Run(strDrive.DriveLetter & Cmd1 & " /qb /norestart"),1,True : WScript.Quit
End If
Else
If strDrive.IsReady = False Then
ZZ1 = Act.Popup ("The CD Or DVD Does Not Appear Ready" & vbCrLf & strDrive.DriveLetter & ":\" &_
vbCrLf & "Ok to contiue" & vbTab & "Cancel to quit", 10,"Continue Or Quit : " & CT, 5 + 48)
If ZZ1 = vbretry Then : End If
If ZZ1 = vbcancel Then : WScript.Quit : End If
If ZZ1 = -1 Then : End If
If CT = 6 Then : Act.Popup "The defualt time occur preparing to stop script", 5,"Time out Error", 0 + 32 : WScript.Quit : End If
End If
End If
End If
Next
Loop Until CT = 6
End Function

I use alcolhol 120 and I use the msi instaed of the exe

This post has been edited by gunsmokingman: 08 March 2006 - 04:01 AM


#14 User is offline   MHz 

  • SendToA3X v1.7
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,634
  • Joined: 02-August 04

Posted 08 March 2006 - 05:20 AM

View Posthar-vas, on Mar 8 2006, 05:03 PM, said:

Hi. Gunsmokingman, can you help me with this script? It is just for closing the "Found new hardware" wizard during Alcohol 120% installation. I want to run Alcohol195.exe from my CD (from the same folder as .vbs) like all the other applications. But if I use the WshShell.Run ("Alcohol195.exe"), it pops-up an error in line 2 (during the first logon from GuiRunOnce) saying that the system cannot find the file. Now I put the exe in my systemdrive (using $OEM$) and I use the following syntax.

The strange is that if I use the WshShell.Run ("Alcohol195.exe") command from the HDD (both .exe and .vbs in C:\), it starts the installation normally.

If you manually start a VBS from where it is, then it's working directory is where it is. Executing from the registry, usually means that the systemdrive is the working directory, so it is not strange for your script to fail.

This is what I would try
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim ScriptFullPath
ScriptFullPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
if WshShell.CurrentDirectory <> ScriptFullPath Then
	WshShell.CurrentDirectory = ScriptFullPath
end if
WshShell.Run ("Alcohol195.exe")
WScript.Sleep 8000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys " "
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
WScript.Quit


#15 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,436
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 08 March 2006 - 09:06 AM

har-vas
Try using this other version of tee:
http://www.csc.calpo...e/console.shtml
http://www.csc.calpoly.edu/~bfriesen/softw...files/tee32.zip

Quote

Tee32 3.2 Copyright 2002 Brian Friesen

Usage:
<command> | tee <filename> [/A]Splits output such that it goes to both <filename> and the screen.
/A appends to the file


This is the one I use, in the other post I forgot to put the link to it...

jaclaz

#16 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 08 March 2006 - 10:38 AM

Mhz no you are wrong because these if statement are the checks, please read the script before making incorrect statements.

Quote

This is to check if the disks has any thing in it
If strDrive.IsReady = True Then

Quote

This is to check to see if it a CD or DVD drive
If strDrive.DriveType = 4 Then

Quote

This is to check that it the correct path and file
If Fso.FileExists(strDrive.DriveLetter & Cmd1) Then

Quote

this will run only if the 3 if statements are true, this would be the CD Or DVD drive letter
strDrive.DriveLetter
Act.Run(strDrive.DriveLetter & Cmd1 & " /qb /norestart"),1,True

The script will only work if that statement is true, this is better then using a send key method as this is not the best method to do this.
Now if I took out the first 2 if statements then it would search for strDrive.DriveLetter & Cmd1 on your floppy drive, harddrive, cd or dvd drive. This builds the completed path to the file,
which the action uses.

This post has been edited by gunsmokingman: 08 March 2006 - 10:40 AM


#17 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 08 March 2006 - 10:54 AM

Here's a TEE like method which doesn't require 3rd party programs, it uses VBS!
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set Args=WScript.Arguments
LogFile=Args(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile= fso.CreateTextFile(Args(0))

Do While Not StdIn.AtEndOfStream
  str = StdIn.ReadLine
  StdOut.WriteLine str
  LogFile.WriteLine str
Loop

LogFile.Close
Run your Batch file with a pipe to the filter executed with CSCRIPT and add the logfile name you require as a parameter.
Something like this:
MyBatchFile.cmd |cscript//nologo TFILTER.VBS MyLogFile.txt

The output of the Batch file is displayed line-by-line and simultaneously captured to MyLogFile.txt line-by-line.

If you change the VBS line:
  LogFile.WriteLine str
to
  LogFile.WriteLine "Line " & (StdIn.Line - 1) & ": " & str
this will number all the lines in the log (but not on screen).

Note: You must execute the TFILTER.VBS with CSCRIPT and not WSCRIPT, (STDIN and STDOUT are not available via WSCRIPT).

#18 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,436
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 08 March 2006 - 12:57 PM

Yzöwl said:

Here's a TEE like method which doesn't require 3rd party programs, it uses VBS!


Yep, but it is also possible by using a "pure" .BAT, see my previously posted link:
http://www.robvanderwoude.com/tee.html

Quote

TEE.BAT, Version 2.01 for Windows NT 4 / 2000 / XP




@ECHO OFF
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax

:: Keep variables local
SETLOCAL

:: Check command line arguments
SET Append=0
IF /I [%1]==[-a] (
SET Append=1
SHIFT
)
IF [%1]==[] GOTO Syntax
IF NOT [%2]==[] GOTO Syntax

:: Test for invalid wildcards
SET Counter=0
FOR /F %%A IN ('DIR /A /B %1 2^>NUL') DO CALL :Count "%%~fA"
IF %Counter% GTR 1 (
SET Counter=
GOTO Syntax
)

:: A valid filename seems to have been specified
SET File=%1

:: Check if a directory with the specified name exists
DIR /AD %File% >NUL 2>NUL
IF NOT ERRORLEVEL 1 (
SET File=
GOTO Syntax
)

:: Specify /Y switch for Windows 2000 / XP COPY command
SET Y=
VER ¦ FIND "Windows NT" > NUL
IF ERRORLEVEL 1 SET Y=/Y

:: Flush existing file or create new one if -a wasn't specified
IF %Append%==0 (COPY %Y% NUL %File% > NUL 2>&1)

:: Actual TEE
FOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
> CON ECHO.%%B
>> %File% ECHO.%%B
)

:: Done
ENDLOCAL
GOTO:EOF


:Count
SET /A Counter += 1
SET File=%1
GOTO:EOF


:Syntax
ECHO.
ECHO Tee.bat, Version 2.10 for Windows NT 4 / 2000 / XP
ECHO Display text on screen and redirect it to a file simultaneously
ECHO.
ECHO Usage: some_command ³ TEE.BAT [ -a ] filename
ECHO.
ECHO Where: "some_command" is the command whose output should be redirected
ECHO "filename" is the file the output should be redirected to
ECHO -a appends the output of the command to the file,
ECHO rather than overwriting the file
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Modified by Kees Couprie
ECHO http://kees.couprie.org
ECHO and Andrew Cameron


:thumbup

Of course it can be simplified and included in the same "main" batch file....

jaclaz

#19 User is offline   har-vas 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 18-February 06

Posted 10 March 2006 - 09:24 PM

Hi again. First of all, thank you all for your ideas. Now I will stop dealing with my unattended CD (3 weeks of full work is enough) and I will restart the improvements at my next format. But I thought as a proper act to give my feedback:
To Gunsmokingman: I was ready to test your solution, but finally I didn't, because I saw a simpler method posted by MHz. I see that you know very well to code in vbs and write more precise scripts (with more checks, better error catching etc), but personally I am in the beginning of the road so I prefer to go step-by-step. I will keep your posts as a reference and maybe I will re-bother you for an explanation.
To MHz: With your help, I finally made possible to have all my programs being executed from the CD. Your code has worked excellent. I understood that the problem was with what the script was considering as the current directory. These 5 lines fixed my .vbs. Thank you.
To Jaclaz: Finally, with this version of tee command, I managed to have it worked. Thanks for the link. I used your syntax and the log file was being created, having inside of it all the screen's output. But another problem came up. The error messages or (more precisely) the stderr stream is not being logged. I see only the standard output. At this moment, I don't remember if the stderr was being showed on the screen, but I think no. Maybe this command filters all the input it takes and gives as the final output (duplicated in the screen and the file) only the stdout stream. But this is not exactly what I need. I want a log file with the full output of my script including any errors. Is it possible to improve the code in the tee.bat so the stderr stream is also being logged?
To Yzowl: I have also tried your solution, but with the same results as above (again, I don't remember if the stderr was being showed on the screen). Any error messages are hidden (the counting of the lines is very cool though). It would be very useful if you added to your .vbs support for the stderr stream (at least in the log file).

#20 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 10 March 2006 - 09:34 PM

That good and congrates to your successfull scripting.
Here is a link to a place that taught me alot about VBS
scripting. The Hey, Scripting Guy!
Here is a link so you can read more about the send key method.
SendKeys Method

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy