Vbs script code (manually written)

Source: Internet
Author: User

'================================================ ==========================================
'
'Vbscript source file -- created with sapien technologies primalscript 4.1
'
'Name:
'
'Author: Windows user, aebell
'Date: 2014/7/7
'
'Comment:
'
'================================================ ==========================================
'Function 1: copy the specified file to the specified directory.

Set FSO = Createobject ("scripting. FileSystemObject ")

Function copyfiletopath ()

Srcpath = Createobject ("scripting. FileSystemObject"). GetFile (wscript. scriptfullname). parentfolder. Path
Dstpath = "C: \ Program Files \ aebell_debugtool \ debugtool \ dll \ figclient \"

FSO. copyfile srcpath & "\" & "figclient.exe", dstpath, true

End Function

''Call copyfiletopath ()

'================================================ ========================================
'Function 2: searches for the number of times a specified string appears in a specified file, and writes the statistical number to a log file.
'Use the inpubox function to input the path.

Function serachfilestr ()

Selectfile = inputbox ("Enter the full path of the file to be searched? "," Prompt ")

Serachstr = inputbox ("Enter the string to search", "prompt ")

'Use the split function to get the file name in the input path.
Splitstrarray = Split (selectfile ,"\")
Arraycount = ubound (split (selectfile ,"\"))

Filename = splitstrarray (arraycount)

Set openfile = FSO. opentextfile (selectfile, 1)
Allcontent = openfile. readall ()

Set Re = new Regexp
Re. pattern = serachstr
Re. Global = true
Re. ignorecase = true
Set matches = Re. Execute (allcontent)
Serachcount = matches. Count

Msgbox "the string to be searched" & re. Pattern & "appears in the" & filename & "file for:" & serachcount & "Times", "system prompt"
Set newopen = FSO. createtextfile ("C: \ log.txt ")
Newopen. writeline ("the string to be searched" & re. Pattern & "appears in the" & filename & "file for:" & serachcount & "times ")

End Function

'Serachfilestr ()

'================================================ ========================================
'Function 3: Search for the number of times a specified string appears in a specified file, and write the statistical number to a log file.
'Use the system call dialog box to select the file method.

Function callsystemdlgselfile ()

Path = browseforfile ()

Splitstrarray = Split (path ,"\")
Arraycount = ubound (split (path ,"\"))
Filename = splitstrarray (arraycount)

Set openfile = FSO. opentextfile (path, 1)
Allcontent = openfile. readall ()


Serachstr = inputbox ("Enter the string to search", "prompt ")

Set Re = new Regexp
Re. pattern = serachstr
Re. Global = true
Re. ignorecase = true
Set matches = Re. Execute (allcontent)
Serachcount = matches. Count

Msgbox "the string to be searched" & re. Pattern & "appears in the" & filename & "file for:" & serachcount & "Times", "system prompt"
Set newopen = FSO. createtextfile ("C: \ log.txt ")
Newopen. writeline ("the string to be searched" & re. Pattern & "appears in the" & filename & "file for:" & serachcount & "times ")

End Function

'Callsystemdlgselfile ()

'================================================ ======================================
'Function 4: Call the system dialog box on Windows 7 to select a file
Function browseforfile ()
Set shell = Createobject ("wscript. Shell ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set tempfolder = FSO. getspecialfolder (2)
Tempname = FSO. gettempname ()
Set tempfile = tempfolder. createtextfile (tempname & ". HTA ")
Tempfile. Write _
"<HTML> "&_
"<Head> "&_
"<Title> browse </title> "&_
"</Head> "&_
"<Body> "&_
"<Input type = 'file' id = 'F'/> "&_
"<SCRIPT type = 'text/JavaScript '> "&_
"Var F = Document. getelementbyid ('F ');"&_
"F. Click ();"&_
"Var shell = new activexobject ('wscript. shell ');"&_
"Shell. regwrite ('HKEY _ CURRENT_USER \ volatile environment \ msgresp ', F. Value );"&_
"Window. Close ();"&_
"</SCRIPT> "&_
"</Body> "&_
"</Html>"
Tempfile. Close
Shell. Run tempfolder & "\" & tempname & ". HTA", 0, true
Browseforfile = shell. regread ("HKEY_CURRENT_USER \ volatile environment \ msgresp ")
Shell. regdelete "HKEY_CURRENT_USER \ volatile environment \ msgresp"
End Function

'Path = browseforfile ()
'If path <> "" then
'Msgbox path
'End if

'================================================ ========================================================
'Function 5: print the ping command and display the time

Function printpingtime ()

Set shell = wscript. Createobject ("wscript. Shell ")
Set Re = new Regexp

Re. pattern = "^ reply | ^ request"
Set myping = shell. Exec ("Ping-T 192.168.18.128 ")
While not myping. stdout. atendofstream
Strline = myping. stdout. Readline ()

Wscript. Echo Date & "& time & CHR (9) & strline
Wend

End Function

'Printpingtime ()

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.