Private Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS End Type Private Const FO_COPY = &H2 Private Const FO_DELETE = &H3 Private Const FO_MOVE = &H1 Private Const FO_RENAME = &H4Private Const FOF_ALLOWUNDO = &H40 Private Const FOF_CONFIRMMOUSE = &H2 Private Const FOF_FILESONLY = &H80 ' on *.*, do only files Private Const FOF_MULTIDESTFILES = &H1 Private Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user. Private Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs Private Const FOF_RENAMEONCOLLISION = &H8 Private Const FOF_SILENT = &H4 ' don't create progress/report Private Const FOF_SIMPLEPROGRESS = &H100 ' means don't show names of files Private Const FOF_WANTMAPPINGHANDLE = &H20 ' Fill in SHFILEOPSTRUCT.hNameMappings Private Const FOF_NOERRORUI = &H400Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongConst SW_SHOW = 5 Private Sub Command1_Click() Call subReName("d:\abc.dat", "d:\abc.exe", 0, Me) '下面注释的是VB方法,我使用的是Win API函数,你可以2选1 'Call Shell("d:\abc.exe", vbNormalFocus) Call ShellExecute(0, "", "d:\abc.exe", "", "", 0) End Sub '重新命名 Public Sub subReName(ByVal strSource As String, _ ByVal strDesc As String, _ Optional ByVal bflag As Boolean = False, _ Optional pForm As Form) Dim SHFileOp As SHFILEOPSTRUCT
RetVal = Shell("C:\WINDOWS\ABC.Bat", 1)
只是改了一下扩展名而已你想要.exe修改后的.dat执行出来是什么结果?
*.BAT文件是可执行文件。
你要的*.DAT文件是无法执行的。
Name app.path & "\a.dat" As app.path & "\a.exe"2.执行改名后的a.exe
shell app.path & "\a.exe",vbhide 'vbhide就是隐藏执行3.执行完以后改回a.dat:
Name app.path & "\a.exe" As app.path & "\a.dat"
有没有更简便的思路了?
我记得我朋友的那个程序是
在当前文件夹下把.dat改回.exe可以独立运行。
改回.dat的话也可以用自己写的那个按钮调用运行。
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_MOVE = &H1
Private Const FO_RENAME = &H4Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_CONFIRMMOUSE = &H2
Private Const FOF_FILESONLY = &H80 ' on *.*, do only files
Private Const FOF_MULTIDESTFILES = &H1
Private Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
Private Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_SILENT = &H4 ' don't create progress/report
Private Const FOF_SIMPLEPROGRESS = &H100 ' means don't show names of files
Private Const FOF_WANTMAPPINGHANDLE = &H20 ' Fill in SHFILEOPSTRUCT.hNameMappings
Private Const FOF_NOERRORUI = &H400Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongConst SW_SHOW = 5
Private Sub Command1_Click()
Call subReName("d:\abc.dat", "d:\abc.exe", 0, Me)
'下面注释的是VB方法,我使用的是Win API函数,你可以2选1
'Call Shell("d:\abc.exe", vbNormalFocus)
Call ShellExecute(0, "", "d:\abc.exe", "", "", 0)
End Sub
'重新命名
Public Sub subReName(ByVal strSource As String, _
ByVal strDesc As String, _
Optional ByVal bflag As Boolean = False, _
Optional pForm As Form)
Dim SHFileOp As SHFILEOPSTRUCT
SHFileOp.wFunc = FO_MOVE
SHFileOp.pFrom = strSource + Chr(0)
SHFileOp.pTo = strDesc + Chr(0)
SHFileOp.lpszProgressTitle = App.Title + Chr(0)
If IsMissing(pForm) = False Then SHFileOp.hwnd = pForm.hwnd
SHFileOp.fFlags = 0 '不设任何标志
If bflag Then '不显示任何窗口
SHFileOp.fFlags = SHFileOp.fFlags + FOF_SILENT ' + FOF_ALLOWUNDO + FOF_NOCONFIRMATION
End If
Call SHFileOperation(SHFileOp)
End Sub'希望是你想要的