只要辅助登录服务(seclogon
)正在运行,下面的代码块就允许批处理文件和VBScript文件的组合来自动执行任务。批处理文件使用相对路径引用将文件放置在任何路径中,该路径至少允许当前和选定用户帐户具有读取权限。两个文件应位于同一路径中。ShellExecute
与动词一起使用runasuser
会使Windows出现提示,允许用户从主机允许的任何登录方法中进行选择。
可以将该过程添加到用户启动过程中,以便一旦登录到计算机系统中就可以进行。
批处理文件: {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
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
'
' ----------------------------------------------------------------------