我正在使用 Visual Basic 编写一个程序,它将启动一个执行一些操作的批处理文件。我需要的是将参数从 Visual Basic 传递到我的批处理文件。
这是我迄今为止在 Visual Basic 中所掌握的内容:
If M.Msg = WM_DEVICECHANGE Then
Select Case M.WParam
Case DBT_DEVICEARRIVAL
Dim DevType As Integer = Runtime.InteropServices.Marshal.ReadInt32(M.LParam, 4)
If DevType = DBT_DEVTYP_VOLUME Then
Dim Vol As New DEV_BROADCAST_VOLUME
Vol = Runtime.InteropServices.Marshal.PtrToStructure(M.LParam, GetType(DEV_BROADCAST_VOLUME))
If Vol.Dbcv_Flags = 0 Then
For i As Integer = 0 To 20
If Math.Pow(2, i) = Vol.Dbcv_Unitmask Then
Dim Usb As String = Chr(65 + i) + ":\"
MsgBox("New device found!" & vbNewLine & vbNewLine & "The drive letter is: " & Usb.ToString & vbNewLine & "Start backup?")
Dim DosRun As Process = New Process
Dim strArgs As String
strArgs = Usb.ToString
DosRun.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
DosRun.StartInfo.FileName = "C:\Users\info\Desktop\Backup.bat"
DosRun.StartInfo.Arguments = Usb
DosRun.Start()
Exit For
End If
Next
End If
End If
这是我的批处理文件的一部分:
xcopy %Usb% %ziel% /E /V /W /I /F /H /D /Y /EXCLUDE:C:\Users\info\Desktop\Exclude.txt
我需要将参数 Usb 传递给批处理文件。谁能帮我吗?
最佳答案
在批处理文件中,通过输入 %
和参数编号来捕获参数。 %1
是第一个参数,%2
是第二个参数,依此类推。
只需将 %Usb%
更改为 %1
即可捕获第一个参数。
xcopy %1 %ziel% /E /V /W /I /F /H /D /Y /EXCLUDE:C:\Users\info\Desktop\Exclude.txt
关于vb.net - 在批处理文件中使用 Visual Basic 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36554355/