Skip to content

Instantly share code, notes, and snippets.

@jamesperrin
Created February 14, 2022 15:51
Show Gist options
  • Save jamesperrin/13986ce682dfffed5314f9a0b5b245c8 to your computer and use it in GitHub Desktop.
Save jamesperrin/13986ce682dfffed5314f9a0b5b245c8 to your computer and use it in GitHub Desktop.
::*********************************************************************************
::
:: Title: RunAs Smartcard User Script
::
:: Purpose: This script runs a selected program as a Smartcard User
::
:: Note: The Windows service "Secondary Logon" needs to running for script to work.
::
:: To run service:
::
:: Option 1
:: 1. As an Administrator, go to Start Menu > Windows Administrative Tools > Services
:: 2. Scroll down to "Secondary Logon" service
:: 3. Right click on service and select "Properties".
:: 4. Change "Starup Type" to "Automatic".
:: 5. Click "Apply" button.
:: 6. Click "Start" button.
::
:: Option 2
:: 1. As an Administrator, open a PowerShell terminal
:: 2. Execute command: Set-Service -Name seclogon -StartupType Automatic
:: 3. Execute command: Set-Service -Name seclogon -Status Running -PassThru
::
:: Author: James Perrin, @jamesperrin
::
::*********************************************************************************
@ECHO OFF
CLS
ECHO:
ECHO: ====================================================
ECHO:
ECHO: RunAs Smartcard User Script
ECHO:
ECHO: This script runs a selected program as a Smartcard User
ECHO:
ECHO: Note: The Windows service "Secondary Logon" needs to running for to script run.
ECHO:
:action_menu
ECHO:
ECHO: ====================================================
ECHO:
ECHO: 1: Edge Browser
ECHO: 2: Chrome Browser
ECHO: 3: PowerShell
ECHO: 9: Run custom program
ECHO:
ECHO: 0: EXIT
ECHO:
SET /P action=Please choose a task?
IF /I "%action%" EQU "1" GOTO :edge_browser
IF /I "%action%" EQU "2" GOTO :chrome_browser
IF /I "%action%" EQU "3" GOTO :powershell
IF /I "%action%" EQU "9" GOTO :custom_run_menu
IF /I "%action%" EQU "0" GOTO :exit_process
GOTO :action_menu
:exit_process
ECHO:
ECHO Exiting process...
ECHO:
PAUSE
EXIT
:edge_browser
CLS
ECHO:
runas /smartcard "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
GOTO :exit_process
:chrome_browser
CLS
ECHO:
runas /smartcard "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
GOTO :exit_process
:powershell
CLS
ECHO:
runas /smartcard "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
GOTO :exit_process
:custom_run_menu
CLS
ECHO:
ECHO: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ECHO: Run a custom program
ECHO:
ECHO: Example: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
ECHO:
SET /P RunProgram=Enter full path to program to run?
IF "%RunProgram%"=="" (
GOTO :custom_run_menu
) ELSE (
runas /smartcard "%RunProgram%"
GOTO :exit_process
)
GOTO :custom_run_menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment