Om jag vill köra ett program med dos-prompten och välja att den ska ta j när det frågas om j eller n. Hur gör jag då? <code>DoS med Vb?
Jag vet hur man starat program med shell men inte hur jag skickar med vad den ska trycka. Ska jag använda snedkey eller?
Med Mycket Vänliga Hälsningar // R-musSv: DoS med Vb?
Option Explicit
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, ByVal lpBuffer As String, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Const STD_OUTPUT_HANDLE = -11&
Private hConsole As Long
Private Sub Command1_Click()
Dim app_name As String
Dim txt As String
Dim num_written As Long
app_name = App.Path
If Right$(app_name, 1) <> "\" Then app_name = app_name & "\"
app_name = app_name & "test.bat"
txt = "Ready to run" & vbCrLf
WriteConsole hConsole, txt, Len(txt), num_written, vbNullString
Shell app_name
End Sub
Private Sub Form_Load()
Dim txt As String
Dim num_written As Long
If AllocConsole() Then
hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
If hConsole = 0 Then MsgBox "Couldn't allocate STDOUT"
' Present a warning.
txt = "******************************************" & vbCrLf & _
"* Warning: Do not close this window! *" & vbCrLf & _
"* Close the VB program's window instead. *" & vbCrLf & _
"******************************************" & vbCrLf
WriteConsole hConsole, txt, Len(txt), num_written, vbNullString
' Make this form visible and on top.
Me.Show
SetFocus
Else
MsgBox "Couldn't allocate console"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
CloseHandle hConsole
FreeConsole
End Sub
</code>