Friday, 25. July 2008, 10:39:58
WINDOWS, VBSCript
代码如下:
Dim Shell, FSO, objRootFolder
Set Shell = WScript.CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = FSO.getFolder(Shell.BrowseForFolder(0, "请选择文件夹。注意:所选文件夹以下的 Thumbs.db 文件将被全部删除!", &h11))
If deleteFilesByName(objRootFolder, "Thumbs.db") Then
MsgBox RootDir + "以下的所有 Thumbs.db 文件已被删除!"
Else
MsgBox "发生错误!"
End If
'根据文件名删除文件的递归函数
Function deleteFilesByName(objRootFolder, strName)
If (objRootFolder is Nothing) Then
deleteFilesByName = False
Exit Function
End If
Dim objFolder, objFile
For Each objFile in objRootFolder.files
If objFile.Name = strName Then
objFile.Delete True
End if
Next
For Each objFolder In objRootFolder.SubFolders
deleteFilesByName objFolder, strName
Next
deleteFilesByName = true
End Function
Tuesday, 29. January 2008, 01:33:00
程序, Programming, 代码, PHP
...
看到
どう書く?org 上面新出的题:
指定コマンドを別プロセスで起動 (根据指定命令启动别的进程)
要求同时取得被启动进程的PID、标准输出、返回值。
可能过于简单,回答的人寥寥。我比较喜欢这些看起来简单的任务,于是提供了两个答案。
Windows 下的 VBScript 代码:
Dim WSH, ExecObj
Set WSH = CreateObject("WScript.Shell")
Set ExecObj = WSH.Exec("hostname")
WScript.Echo "pid:" & ExecObj.processID
WScript.Echo "stdout: " & ExecObj.StdOut.ReadAll
WScript.Echo "exit: " & ExecObj.exitCode
WScript.Quit(ExecObj.exitCode)
Set ExecObj = Nothing
Set WSH = Nothing
Linux/Unix 下的 PHP 代码:
<?
exec("hostname; echo $$", $output, $return_cd);
$pid = array_pop($output);
echo "pid: $pid\n";
echo "\noutput: ".join("\n", $output)."\n";
echo "\nreturn code: $return_cd\n";
?>
如果您需要其他语言的答案,到
这儿找就是了。(虽然是日文,相信都能看得懂代码)
Thursday, 2. February 2006, 11:38:16
VBSCript, Mail, COM
1. IIS SMTP + CDONTS.NewMailSub SendMailCDONTS(aTo, Subject, TextBody, aFrom)
Const CdoBodyFormatText = 1
Const CdoBodyFormatHTML = 0
Const CdoMailFormatMime = 0
Const CdoMailFormatText = 1
Dim Message 'As New cdonts.NewMail
'Create CDO message object
Set Message = CreateObject("CDONTS.NewMail")
With Message
'Set email adress, subject And body
.To = aTo
.Subject = Subject
.Body = TextBody
'set mail And body format
.MailFormat = CdoMailFormatText
.BodyFormat = CdoBodyFormatText
'Set sender address If specified.
If Len(aFrom) > 0 Then .From = aFrom
'Send the message
.Send
End With
End Sub
2. IIS SMTP + CDO.MessageSub SendMailCDO(aTo, Subject, TextBody, aFrom)
Const cdoOutlookExvbsss = 2
Const cdoIIS = 1
Dim Message 'As New CDO.Message
'Create CDO message object
Set Message = CreateObject("CDO.Message")
With Message
'Load IIS configuration
.Configuration.Load cdoIIS
'Set email adress, subject And body
.To = aTo
.Subject = Subject
.TextBody = TextBody
'Set sender address If specified.
If Len(aFrom) > 0 Then .From = aFrom
'Send the message
.Send
End With
End Sub
Sub SendMailCDOCacheConf(aTo, Subject, TextBody, aFrom)
'cached configuration
Dim Conf ' As New CDO.Configuration
If IsEmpty(Conf) Then
Const cdoOutlookExvbsss = 2
Const cdoIIS = 1
Set Conf = CreateObject("CDO.Configuration")
Conf.Load cdoIIS
End If
Dim Message 'As New CDO.Message
'Create CDO message object
Set Message = CreateObject("CDO.Message")
With Message
'Set cached configuration
Set .Configuration = Conf
'Set email adress, subject And body
.To = aTo
.Subject = Subject
.TextBody = TextBody
'Set sender address If specified.
If Len(aFrom) > 0 Then .From = aFrom
'Send the message
.Send
End With
End Sub
3. 远程 SMTP + CDO.Message修改以上列出函数 SendMailCDOCacheConf 的代码,如下
Sub SendMailCDOCacheConf(aTo, Subject, TextBody, aFrom)
'cached configuration
Dim Conf 'As New CDO.Configuration
If IsEmpty(Conf) Then
Const cdoSendUsingPort = 2
Set Conf = CreateObject("CDO.Configuration")
With Conf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server"
.Update
End With
End If
Dim Message 'As New CDO.Message
'Create CDO message object
Set Message = CreateObject("CDO.Message")
With Message
'Set cached configuration
Set .Configuration = Conf
'Set email adress, subject And body
.To = aTo
.Subject = Subject
.TextBody = TextBody
'Set sender address If specified.
If Len(aFrom) > 0 Then .From = aFrom
'Send the message
.Send
End With
End Sub
4. OutlookSub SendMailOutlook(aTo, Subject, TextBody, aFrom)
'Create an Outlook object
Dim Outlook 'As New Outlook.Application
Set Outlook = CreateObject("Outlook.Application")
'Create e new message
Dim Message 'As Outlook.MailItem
Set Message = Outlook.CreateItem(olMailItem)
With Message
'You can display the message To debug And see state
'.Display
.Subject = Subject
.Body = TextBody
'Set destination email address
.Recipients.Add (aTo)
'Set sender address If specified.
Const olOriginator = 0
If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator
'Send the message
.Send
End With
End Sub