我在我的 VB.Net 应用程序中使用此代码
Protected Sub btnBHNas_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBHNasBackup.Click
'System.Diagnostics.Process.Start("batch\backupbhnas.bat")
Using writer As StreamWriter = New StreamWriter("C:\backupbhnas.bat", True)
writer.WriteLine("@echo off")
writer.WriteLine(" echo ""Specify username""")
writer.WriteLine("set /p Name=")
writer.WriteLine("net use k: ""\\backups\back-ups""")
writer.WriteLine("mkdir k:\%name%")
writer.WriteLine("set drive=K:\%name%")
writer.WriteLine("set backupcmd=xcopy /s /c /d /e /h /i /r /y")
writer.WriteLine("echo ### Backing up My Documents...")
writer.WriteLine("%backupcmd% ""C:\Documents and Settings\%name%\My Documents"" ""%drive%\My Documents""")
writer.WriteLine("echo ### Backing up Favorites...")
writer.WriteLine("%backupcmd% ""C:\Documents and Settings\%name%\Favorites"" ""%drive%\Favorites""")
writer.WriteLine("echo ### Backing up Desktop...")
writer.WriteLine("%backupcmd% ""C:\Documents and Settings\%name%\desktop"" ""%drive%\desktop""")
writer.WriteLine("net use k: /delete")
writer.WriteLine("echo Backup Complete!")
writer.WriteLine("pause")
End Using
Dim myFile As String
Dim myDir As String = "C:\"
For Each myFile In Directory.GetFiles(myDir, "backupbhnas.bat")
File.Delete(myFile)
Next
End Sub
它有效。但是,当我在 ASP.Net 的按钮中使用它时,它什么也不做。我错过了什么吗?