我的应用程序有一个用VBScript编写的卸载脚本。该脚本将删除所有注册表,并应卸载sql server并删除在安装过程中创建的数据库。我想备份数据库而不是删除它。
因此,我编写了一个函数来用VBS重命名mdf和ldf文件,但是此方法出现了权限被拒绝的错误。
package TestPackage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.channels.IllegalBlockingModeException;
public class TestSocketListener {
public static void main(String[] args) {
System.out.println("INIT SOCKET");
int port = 3000;
while(true) {
try {
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(5000);
System.out.println("Waiting for client on port " +
serverSocket.getLocalPort() + "...");
Socket server = serverSocket.accept();
System.out.println("Just connected to " + server.getRemoteSocketAddress());
// you want to know how much bytes to read
InputStream inputstream = server.getInputStream();
int buflen = inputstream.available();
DataInputStream DataInStream = new DataInputStream(inputstream);
byte[] rawstring = new byte[buflen];
DataInStream.read(rawstring, 0, buflen);
String str = new String(rawstring);
System.out.println(str);
DataOutputStream DataOutStream = new DataOutputStream(server.getOutputStream());
DataOutStream.writeUTF("Thank you for connecting to " + server.getLocalSocketAddress()
+ "\nGoodbye!");
server.close();
System.out.println(("SERVER CLOSED"));
} catch(SocketTimeoutException st) {
System.out.println("Socket timed out!");
} catch(SocketException s) {
//System.out.println("Socket Error!!");
//s.getMessage();
} catch (IOException e) {
//System.out.println("IO Error!");
}
}
}
}
Dim file
DBfile = "C:\Program Files\Microsoft SQL
Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\DB.mdf"
Sub backupDBFiles(file)
Dim filesys
Set filesys = WScript.CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(file) Then
filesys.MoveFile file, file & "backup"
End If
End Sub
backupDBFiles(DBfile)
方法适用于任何其他文件,因此我认为该方法理想上应重命名mdf文件,但会给我一个权限被拒绝的错误。有办法解决此错误吗?