Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created May 5, 2015 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Iristyle/e5ae9b638a6324e66909 to your computer and use it in GitHub Desktop.
Save Iristyle/e5ae9b638a6324e66909 to your computer and use it in GitHub Desktop.
Run cmd.exe / powershell.exe in an interactive service
cinst rktools.2003
cd 'C:\Program Files (x86)\Windows Resource Kits\Tools'
$serviceName = 'Interactive SYSTEM cmd'
.\instsrv.exe $serviceName 'C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe'
sc.exe config $serviceName depend= UI0Detect start= demand
$servicePath = "HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName"
$serviceParams = New-Item $servicePath -Name Parameters
New-ItemProperty -Path $serviceParams.PSPath -PropertyType String -Name 'AppDirectory' -Value 'c:\windows\system32' -Force
New-ItemProperty -Path $serviceParams.PSPath -PropertyType String -Name 'Application' -Value 'c:\windows\system32\cmd.exe' -Force
$serviceConfig = Get-Item $servicePath
#set 9th bit, from http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
$newType = $serviceConfig.GetValue('Type') -bor 0x100
Set-ItemProperty -Path $serviceConfig.PSPath -Name Type -Value $newType
cinst rktools.2003
cd 'C:\Program Files (x86)\Windows Resource Kits\Tools'
$serviceName = 'Interactive SYSTEM Powershell'
.\instsrv.exe $serviceName 'C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe'
# sc.exe config $serviceName depend= UI0Detect start= demand
sc.exe config $serviceName start= demand
$servicePath = "HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName"
$serviceParams = New-Item $servicePath -Name Parameters
New-ItemProperty -Path $serviceParams.PSPath -PropertyType String -Name 'AppDirectory' -Value 'c:\windows\system32\WindowsPowershell\v1.0' -Force
New-ItemProperty -Path $serviceParams.PSPath -PropertyType String -Name 'Application' -Value 'c:\windows\system32\WindowsPowershell\v1.0\powershell.exe' -Force
$serviceConfig = Get-Item $servicePath
#set 9th bit, from http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
$newType = $serviceConfig.GetValue('Type') -bor 0x100
Set-ItemProperty -Path $serviceConfig.PSPath -Name Type -Value $newType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment