[VB]GUI Easy Sysprep 1.1 源代码[3 RunOnce.exe 源代码]

RunOnce.exe 源代码
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Const PROCESS_QUERY_INformATION = &H400
Private Const STILL_ACTIVE = &H103
Dim pidNotepad As Long
Dim hProcess As Long
Dim WinDir As String, SystemDrive As String

Private Sub Form_Load()
Dim CDOpen As String
Dim ExeName(3) As String, Hide(3) As String, KillIt(3) As String
Dim ServOpt As String, ServOptPath As String
Dim temp As String
Dim Path As String, Exe As String
Dim i As Integer, j As Integer
Me.Visible = False
SystemDrive = Environ("systemdrive")
WinDir = Environ("windir")
AllUsersProFile = Environ("ALLUSERSPROFILE")
'读取参数
If Dir(WinDir & "config.esp") <> "" Then
Open WinDir & "config.esp" For Input As #1
Line Input #1, CDOpen
For i = 2 To 18
   Line Input #1, temp
Next
For i = 1 To 3
   Line Input #1, ExeName(i)
   Line Input #1, Hide(i)
   Line Input #1, KillIt(i)
Next
Line Input #1, ServOpt
Line Input #1, ServOptPath
Close #1
'弹出光盘
If CDOpen = "True" And Dir(WinDir & "system32CDOpen2.exe") <> "" Then
   Shell WinDir & "system32CDOpen2.exe"
End If
'运行外接程序
For i = 1 To 3
   If ExeName(i) <> "" And Dir(ExeName(i)) <> "" And _
   (LCase(Right(ExeName(i), 3)) = "exe" Or LCase(Right(ExeName(i), 3)) = "bat" Or LCase(Right(ExeName(i), 3)) = "cmd") Then
     If Hide(i) = "True" Then
     pidNotepad = Shell(ExeName(i), vbHide)
     Else
     pidNotepad = Shell(ExeName(i), vbNormalFocus)
     End If
     hProcess = OpenProcess(PROCESS_QUERY_INformATION, False, pidNotepad)
     Do
       GetExitCodeProcess hProcess, lngExitCode
       DoEvents
     Loop While lngExitCode = STILL_ACTIVE
     If KillIt(i) = "True" Then
     Kill ExeName(i)
     End If
   End If
Next
End If
'彻底关闭系统还原
If Dir(WinDir & "temphy.vbs") <> "" Then
Shell "rundll32.exe url.dll,FileProtocolHandler " & WinDir & "temphy.vbs", 1
End If
'清除多余的SATA驱动服务
If Dir(WinDir & "tempclean.exe") <> "" Then
pidNotepad = Shell(WinDir & "tempclean.exe /q /w /d", vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INformATION, False, pidNotepad)
Do
     GetExitCodeProcess hProcess, lngExitCode
     DoEvents
Loop While lngExitCode = STILL_ACTIVE
End If
'清理临时文件
If Dir(WinDir & "temphy.vbs") <> "" Then Kill WinDir & "temphy.vbs"
If Dir(WinDir & "tempclean.exe") <> "" Then Kill WinDir & "tempclean.exe"
If Dir(WinDir & "config.esp") <> "" Then Kill WinDir & "config.esp"
If Dir(WinDir & "REG_Optimize.reg") <> "" Then Kill WinDir & "REG_Optimize.reg"
'If ServOptPath <> WinDir & "Serv_Optimize.exe" And Dir(ServOptPath) <> "" Then Kill WinDir & "Serv_Optimize.exe"
If Dir(WinDir & "AllUsrRun.exe") <> "" Then Kill WinDir & "AllUsrRun.exe"
'运行服务优化调整程序
If ServOpt = "True" And ServOptPath <> "" And Dir(ServOptPath) <> "" Then
For i = Len(ServOptPath) To 1 Step -1
   If Mid(ServOptPath, i, 1) = "" Then
     j = i
     Exit For
   End If
Next
Path = Mid(ServOptPath, 1, j)
'Exe = Mid(ServOptPath, j + 1, Len(ServOptPath))
Exe = "XP服务优化调整"
If Dir(WinDir & "system32SHORTCUT.EXE") <> "" Then
   Shell WinDir & "system32SHORTCUT.EXE -f -t " & Chr(34) & ServOptPath & Chr(34) & " -n " & Chr(34) & AllUsersProFile & "「开始」菜单程序" & Exe & Chr(34) & " -d " & Chr(34) & Path & Chr(34), vbHide
End If
Shell ServOptPath, vbNormalFocus
Else
Kill WinDir & "Serv_Optimize.exe"
End If
Call KillMe
End Sub

Private Sub KillMe()
Dim FullAppName As String
FullAppName = App.Path & "" & App.ExeName & ".exe"
Open "esp_del.bat" For Output As #1
Print #1, "@ECHO OFF"
Print #1, ":START"
Print #1, "IF NOT EXIST " & Chr(34) & FullAppName & Chr(34) & " GOTO FILENOTFOUND"
Print #1, "DEL " & Chr(34) & FullAppName & Chr(34)
Print #1, "GOTO START"
Print #1, ":FILENOTFOUND"
Print #1, "DEL esp_del.bat"
Print #1, "CLS"
Print #1, "EXIT"
Close #1
Shell "esp_del.bat", vbHide
End
End Sub

版权声明:
作者:xiaoniba
链接:https://blog.xiaoniba.com/2007/05/31/vbgui-easy-sysprep-11-%e6%ba%90%e4%bb%a3%e7%a0%813-runonceexe-%e6%ba%90%e4%bb%a3%e7%a0%81/
来源:小泥吧的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>