Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need an .exe file that will simply execute a .bat file on CD 2

Status
Not open for further replies.

itdamon

MIS
Mar 18, 2002
69
US
I'm trying to create an autorun CD, but the autorun.inf will only take .exe parameters. I just need a simple program to run setup.bat Any ideas on how to do this? So on my CD I would have 3 files:

autorun.inf (this executes runbatchfile.exe)
runbatchfile.exe (this is where I need help)
setup.bat

Thanks
-Damon (network admin/wannabe VB programmer)
 
Damon,

Why not use a VB exe to run the batch file - or am I missing the point here?!

You could use the VB Shell function - this executes something and returns control immediately back to the VB exe, or another function I've used called ShellWait which executes something (in your case the batch file) and waits for it to finish before returning control to the VB app.
 
Shell "C:\fred.bat"


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
It's difficult to write a VB-based Autorun program, as VB needs it's runtime files (VBRUN600.DLL, etc). Granted, recent copies of Windows come with those support files, but older versions of Windows do not.

So, to write an Autorun program that will work on all 32-bit versions of Windows, you will need to write it in C or C++.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
You guys are the bomb!

You fixed my problem in one line of code!

Shell "a:\setup.bat"

Saved it as an .EXE and now I've got a custom installation CD which can easily be modified via a batch file. (granted my users have to 1st put in the floppy, and 2nd put in my autorun CD, but it's extremely flexible!

Thanks again
-Damon
 
Simon,

Now you've got me curious. My CD runs great with the help of you and John, but I'd like to use the ShellWait function you mentioned to display msg=msgbox("Complete", vbOKOnly, "File Copy Complete")

VB 6.0 gives me a Sub or Function not defined error when using ShellWait...I guess this function needs to be defined?

-Damon

 
johnwm,

Just read your FAQ. Thanks again for your expert help.

-Damon
 
You're welcome Damon!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm

after reading a fantastic book called C++ for VB programmers, i now understand your signature!

as a side-benefit, i should also be able to write my own DLLs and COMs ...
 
[smile]
Go for it gusset!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Damon,

Here is the code for ShellWait - which is actually called ExecCmd... My memory just gets worse! I copied it from a book and have often used it. I think I've put everything here...

Private Type PROCESS_INFORMATION ' For ExecCmd
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

' For ExecCmd
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

' For ExecCmd
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

' For ExecCmd
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long

' For ExecCmd
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Public Sub ExecCmd(cmdline$)
' ExecCmd
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
xlret = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
xlret = WaitForSingleObject(proc.hProcess, INFINITE)
xlret = CloseHandle(proc.hProcess)
'

End Sub

inside Command button or menu option

ExecCmd "Notepad " & xgsAppPath & "\QApplog.TXT" ' Wait for notepad before continuing!


 
Damon,

I'm glad you got your problem solved, but your first statement:
...but the autorun.inf will only take .exe parameters.
is simply not true.

I regularly use an autorun.inf on CD-ROM with these contents (and it does work):
Code:
[autorun]
open=dobackup.bat
icon=backup.ico
You must have been doing something else wrong.

FWIW and good luck,
harebrain
 
Harebrain,

I honestly didn't try that! I guess I was trying to hammer in a tack with a sledge hammer!? I do like the shell wait function, but my code isn't working right anyways...I'll probably try simonkue's example:

Here's my code, the shell wait funtion isn't working right, I get a "File Copy Complete" popping up in the background while files are still copying :) (still solves my user problems though...even with the bugs)

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long





Private Sub Command1_Click()
Dim fsO As Object
Dim S As String
Dim DosProg
DosProg = "a:\setup.bat"
Set fsO = CreateObject("Scripting.filesystemObject")
Do While True
On Error Resume Next
' Check for the presence of setup.bat on the floppy
S = Dir$("A:\setup.bat", vbDirectory)
If Err.Number = 52 Then
Err.Clear
If MsgBox("Put a floppy disk in the A: drive or Click Cancel", vbOKCancel) = vbCancel Then GoTo ErrEnd
Else
Exit Do
End If
Loop
If S <> &quot;&quot; Then
Call ShellAndWait(DosProg, vbMaximizedFocus)
msg = MsgBox(&quot;File Copy Complete&quot;, vbOKOnly, &quot;Complete&quot;)

If msg = 1 Then
End
End If
Else
GoTo ErrEnd
End If
ErrEnd:
Set fsO = Nothing

End
End Sub




Private Sub ShellAndWait(ByVal program_name As String, _
ByVal window_style As VbAppWinStyle)
Dim process_id As Long
Dim process_handle As Long
Dim msg As Integer


' Start the program.
On Error GoTo ShellError
process_id = Shell(program_name, window_style)
On Error GoTo 0

' Hide.
Me.Visible = False
DoEvents

' Wait for the program to finish.
' Get the process handle.
process_handle = OpenProcess(synchronize, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE
CloseHandle process_handle
End If

' Reappear.
'Me.Visible = True
Exit Sub

ShellError:
MsgBox &quot;Error starting task &quot; & _
txtProgram.Text & vbCrLf & _
Err.Description, vbOKOnly Or vbExclamation, _
&quot;Error&quot;
End Sub



 
OK disregard that last post, I combined simonkue's ExecCmd code, with my &quot;check for floppy&quot; code, compiled it...and I think I'm done! Everything works!

I'm shipping out 1 floppy with the batch instructions and the autorun CD out to our users, and I'm using it to copy company forms to My Docs, and placing a shorcut to them on the desktop. (you can't believe how hard it was walking my users through this manually over the phone!...uhhh, do I left click or right click on D: ???)

Here's the final code: (thanks everyone!)

Private Type PROCESS_INFORMATION ' For ExecCmd
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

' For ExecCmd
Private Declare Function WaitForSingleObject Lib &quot;kernel32&quot; (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

' For ExecCmd
Private Declare Function CreateProcessA Lib &quot;kernel32&quot; (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

' For ExecCmd
Private Declare Function CloseHandle Lib &quot;kernel32&quot; (ByVal _
hObject As Long) As Long

' For ExecCmd
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Public Sub ExecCmd(cmdline$)
' ExecCmd
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
xlret = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
xlret = WaitForSingleObject(proc.hProcess, INFINITE)
xlret = CloseHandle(proc.hProcess)
'

End Sub

'Just one simple button on a form

Private Sub Command1_Click()
Dim fsO As Object
Dim S As String
Dim DosProg
DosProg = &quot;a:\setup.bat&quot;
Set fsO = CreateObject(&quot;Scripting.filesystemObject&quot;)
Do While True
On Error Resume Next
' Check for the presence of setup.bat on the floppy
S = Dir$(&quot;A:\setup.bat&quot;, vbDirectory)
If Err.Number = 52 Then
Err.Clear
If MsgBox(&quot;Put a floppy disk in the A: drive or Click Cancel&quot;, vbOKCancel) = vbCancel Then GoTo ErrEnd
Else
Exit Do
End If
Loop
If S <> &quot;&quot; Then
ExecCmd &quot;a:\setup.bat&quot;
'Call ShellAndWait(DosProg, vbMaximizedFocus)
msg = MsgBox(&quot;File Copy Complete&quot;, vbOKOnly, &quot;Complete&quot;)

If msg = 1 Then
End
End If
Else
GoTo ErrEnd
End If
ErrEnd:
Set fsO = Nothing

End
End Sub

'and then add this to a new module, make .EXE and be happy!

Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Global Const NORMAL_PRIORITY_CLASS = &H20&
Global Const INFINITE = -1&
Declare Function CloseHandle Lib &quot;kernel32&quot; (hObject As Long) As Boolean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top