Selama layanan Log Sekunder ( seclogon
) berjalan, blok kode berikut mengizinkan kombinasi file Batch dan VBScript untuk mengotomatiskan tugas. file batch menggunakan referensi jalur relatif untuk memungkinkan file menjadi tempat ke jalur apa pun yang memungkinkan setidaknya membaca izin oleh akun pengguna saat ini dan yang dipilih. Kedua file harus berada di jalur yang sama. Penggunaan ShellExecute
dengan kata kerja runasuser
menyebabkan Windows memunculkan prompt untuk memungkinkan pengguna memilih dari metode logon apa pun yang diizinkan oleh komputer host.
Proses ini dapat ditambahkan ke proses startup pengguna sehingga terjadi setelah login ke sistem komputer.
File kumpulan: {RunAsUser}{CMD}.cmd
@Echo Off
If "%~1" NEQ "/CALLBACK" Goto :label_Process_Run_As_User
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Start the process once running as designated user
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cd C:\
start "" %~dp0cmd.lnk
Goto :EOF
:label_Process_Run_As_User
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Section below verifies if Secondary Login is available
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Query [Secondary Logon]
sc query seclogon 1> nul 2> nul || (
Goto :label_Missing_Secondary_Login
)
REM Check to see if [Secondary Logon] service is not disabled
sc qc seclogon | Find /i "START_TYPE" | Find /i "DISABLED" 1> nul 2> nul && (
Set flg.SecLog.Enabled=F
) || (
Set flg.SecLog.Enabled=T
)
REM Check to see if [Secondary Logon] service is Running
sc queryex seclogon | Find /i "STATE" | Find /i "RUNNING" 1> nul 2> nul && (
Set flg.SecLog.Running=T
) || (
Set flg.SecLog.Running=F
)
REM Determine if action should work
If /i "%flg.SecLog.Enabled%:%flg.SecLog.Running%" EQU "F:F" Goto :label_Secondary_Login_Unavailable
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Section below starts the RunAsUser process
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM System configuration was validateed and RunAsUser will commence
Set "str.SELF=%~0"
WSCRIPT /E:VBSCRIPT "%~dp0RunAsUser.txt"
Goto :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Section below provides written notices to user for error conditions
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:label_Secondary_Login_Unavailable
Echo.
Echo Unable to utilize the Secondary Logon system service because it is disabled.
Echo.
pause
Goto :EOF
:label_Missing_Secondary_Login
Echo.
Echo Unable to find the Secondary Logon system service
Echo.
pause
Goto :EOF
File VBScript: RunAsUser.txt
'-------------------------------------------
'
' Launch Process RunAsUser
CreateObject("Shell.Application").ShellExecute CreateObject("WScript.Shell").Environment("PROCESS")("str.SELF"), "/CALLBACK", "", "runasuser", 1
'
' Display a message box to pause script
msgbox "Enter username or select Certificate for account" & vbCrLf & "On the windows dialog that will popup." & vbCrLf & vbCrLf & "Click OK once process opens", vbokonly
'
' Quit the script
On Error Resume Next
Window.Close ' HTA Must be Closed Through the Window Object
Err.Clear
Wscript.Quit ' VBS Must be Closed Through the Wscript Object
Err.Clear
On Error Goto 0
'
' ----------------------------------------------------------------------