A vbs script that converts Bat to a VBS file.

Source: Internet
Author: User

The following code is slightly modified. The original structure is that the script is executed synchronously with the released bat and the bat is deleted after the bat execution is completed. It is intended that no temporary files are left. Later, I thought about the poor universality. For example, if the bat file released for execution is a monitoring type of resident processes, VBS will wait endlessly and cannot exit, so it should be changed to asynchronous execution, the script automatically exits after calling bat. The idea of adding auto-deletion at the end of restoring the integrity of the original file is also dispelled. The compressed package is not updated yet. Copy codeThe Code is as follows: 'bat2vbs. vbs by baomaboy
Dim WshSHell, FSO
On Error Resume Next
Set WshSHell = WScript. CreateObject ("WScript. Shell ")
Set FSO = CreateObject ("Scripting. FileSystemObject ")
Set WinVer = WshSHell. Environment ("Process ")
Set Args = WScript. Arguments
CloseTime = 5
FileName = WScript. ScriptName
FileFullName = WScript. ScriptFullName
FilePath = FSO. GetParentFolderName (FileFullName)
InsPath = FSO. GetSpecialFolder (1)
InsFullName = FSO. BuildPath (InsPath, FileName)
LnkPathNT = WshSHell. SpecialFolders (2)
LnkPath9X = WshSHell. SpecialFolders (14)
LnkPathAll = WshSHell. SpecialFolders ("SendTo ")
OtherFileName = "Manage_New.txt"
OtherFilePath = FSO. GetSpecialFolder (2)
TemFileName = "No title"
TemFilePath = FSO. GetSpecialFolder (2)
Copyright = "Linglong technology"
QQ = "QQ: 25926183"
Email = "Email: fty1995@163.com"
Role Le = "Bat2Vbs by baomaboy"
InsAnswer = "Bat2Vbs by baomaby"
RegPath1 = "HKEY_CLASSES_ROOT \ batfile \ shell \ BatToVbs \"
RegValue1 = "BAT to VBS script file"
RegForm1 = "REG_SZ"
RegPath2 = "HKEY_CLASSES_ROOT \ batfile \ shell \ BatToVbs \ command \"
RegValue2 = "wscript.exe" & chr (34) & InsFullName & chr (34) & "& chr (34) &" % L "& chr (34)
RegForm2 = "REG_SZ"
IF FileFullName <> InsFullName then
IntAnswer = MsgBox ("[Yes] add" + InsAnswer + "to the right-click menu," & Chr (10) & Chr (10) & "[No] Delete" + InsAnswer + "from the context menu. ", VbQuestion + vbYesNoCancel," Install-"+ InsTitle +"-"+ Copyright)
If intAnswer = vbYes Then
WshSHell. RegWrite RegPath1, RegValue1, RegForm1
WshSHell. RegWrite RegPath2, RegValue2, RegForm2
FSO. GetFile (FileFullName). Copy (InsFullName)
WshSHell. popup _
"Add a script file:" + chr (10) + InsFullName + chr (10) + chr (10) + _
"Add registry key:" + chr (10) + chr (34) + RegPath1 + chr (34) + chr (10) + _
This window will be closed automatically after chr (10) & CloseTime & "seconds! "+ Chr (10) + chr (10) + _
Chr (10) & "Copyright (C)" + Copyright + "" & QQ & "" + Email _
, CloseTime, "installed successfully-" + InsTitle + "-" + Copyright, 0 + 64
End if
If intAnswer = vbNo Then
WshSHell. RegDelete RegPath2
WshSHell. RegDelete RegPath1
FSO. DeleteFile InsFullName
WshSHell. popup _
"Delete script file:" + chr (10) + InsFullName + chr (10) + chr (10) + _
"Delete registry key:" + chr (10) + chr (34) + RegPath1 + chr (34) + chr (10) + _
This window will be closed automatically after chr (10) & CloseTime & "seconds! "+ Chr (10) + chr (10) + _
Chr (10) & "Copyright (C)" + Copyright + "" & QQ & "" + Email _
, CloseTime, "uninstalled successfully-" + InsTitle + "-" + Copyright, 0 + 64
End if
If intAnswer = vbCancel Then
End if
ELSE
If Args. count = 0 then wscript. quit
Set ReadFile = FSO. OpenTextFile (Args (0), 1)
ReadAllText = ReadFile. ReadAll
ReadFile. Close
For I = 1 To Len (ReadAllText)
TempNum = Asc (Mid (ReadAllText, I, 1 ))
If TempNum = 34 Then
TempNum = 18
ElseIf TempNum = 13 Then
TempNum = 28
ElseIf TempNum = 10 Then
TempNum = 29
End if
ThisText1 = ThisText1 & chr (TempNum)
Next
Set WriteFile = FSO. OpenTextFile (Args (0) & ". VBS", 2, True)
WriteFile. writeLine ("On Error Resume Next: Dim WshSHell, FSO, Bat2Vbs: Set WshSHell = WScript. createObject ("" WScript. shell ""): Set FSO = CreateObject ("" Scripting. fileSystemObject ""): Bat2Vbs = "" & ThisText1 &"""")
WriteFile. writeLine ("Execute (" "For I = 1 To Len (Bat2Vbs)" "& vbCrLf &" "TempNum = Asc (Mid (Bat2Vbs, I, 1 )) "" & vbCrLf & "" If TempNum = 28 Then "" & vbCrLf & "" TempNum = 13 "" & vbCrLf & "" ElseIf TempNum = 29 Then "" & vbCrLf &" "TempNum = 10" "& vbCrLf &" "elseif TempNum = 18 Then" "& vbCrLf &" "TempNum = 34" "& vbCrLf &" End If "" & vbCrLf & "" ThisText2 = ThisText2 & chr (TempNum) "" & vbCrLf & "" Next "")")
WriteFile. writeLine ("Set BatFile = FSO. openTextFile (FSO. buildPath (FSO. getSpecialFolder (2), "" Temp. bat ""), 2, True): BatFile. writeLine (ThisText2): BatFile. close: WshSHell. run "" % Comspec %/C "" & FSO. buildPath (FSO. getSpecialFolder (2), "" Temp. bat ""), 1, false ")
WriteFile. Close
End if
Set WshSHell = Nothing
Set FSO = Nothing
Set Args = Nothing
WScript. Quit (0)

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.