0

我在我的 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 的按钮中使用它时,它什么也不做。我错过了什么吗?

4

1 回答 1

0

如果您需要在 C 驱动器中写入文件,您的应用程序可能需要管理权限(在 Vista 及更高版本下)。检查您的例外情况,它将帮助您找到确切的问题。

Try

    //code 

Catch ex As Exception

   // check exception if any

End Try
于 2012-04-19T16:15:43.283 回答