@set @x=0 /*
@echo off
if "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="AMD64" ("%SystemRoot%\SysNative\cmd.exe" /c %0 & goto :eof)

>nul 2>&1 fsutil dirty query %systemdrive%
if errorlevel 1 start "" cscript //nologo /e:jscript "%~f0" &goto :eof

setlocal enableextensions enabledelayedexpansion
echo HASP Emulators for 1C CleanUp Tool v0.08 (C) 2020 by lexapass
set Emulators=emulator NEWHASP haspflt vusbbus vusb multikey64 multikey viubdrv mukeydrv

set /a EmulFound=0
set CCS=HKLM\System\CurrentControlSet
if exist %windir%\SysWOW64 set bits=64
set devcon="devcon%bits%.exe"
for /f "tokens=3" %%l in ('reg query %CCS%\Control\Nls\Language /v Default ^| find /i "Default"') do set lang=%%l

%devcon% rescan >nul
for %%E in (%Emulators%) do (
   if %lang%==0419 (echo Поиск следов %%E ...) else (echo Checking for "%%E" ...)
   set nodump=0
   %devcon% find root\%%E |find /i "root\" >nul
   if not errorlevel 1 (
      set /a EmulFound=+1
      if %lang%==0419 (echo Удаление виртуального устройства %%E...) else (echo Deleting %%E virtual device...)
      %devcon% status root\%%E |find /i "running" >nul
      if not errorlevel 1 (
         set PrefixFound=0
         for /f %%i in ('call %devcon% status root\%%E ^|find /i "root\"') do (
            for /f "tokens=1 delims=[]" %%b in ('call %devcon% status root\%%E ^|find /i /n "%%i"') do (
               set /a Line=%%b+2
               set StatusLine=
               set /a CurLine=1
               for /f "tokens=*" %%c in ('call %devcon% status root\%%E') do (
                  if !Curline! equ !Line! (set StatusLine=%%c) 
                  set /a CurLine+=1))
            echo !StatusLine! |find /i "running" >nul
            if not errorlevel 1 (
               reg query "%CCS%\Enum\%%i" /v "ParentIdPrefix" 2>&1 |find /i "ParentIdPrefix" >nul
               if not errorlevel 1 set PrefixFound=1
               if !PrefixFound!==0 if !nodump!==0 set nodump=1))
         if !PrefixFound!==1 set nodump=0)
      if !nodump!==0 (%devcon% remove root\%%E) else if %lang%==0419 (echo Удаление виртуального устройства %%E без дампа ключа невозможно^^! &echo Установите дамп, перезагрузитесь и повторите удаление.) else (echo Failed to delete %%E virtual device without key dump^^! &echo Install dump, restart PC and repeat deletion.))
   if !nodump!==0 (
      >nul 2>&1 reg query %CCS%\Services\%%E
      if not errorlevel 1 (
         if %lang%==0419 (echo Удаление службы %%E...) else (echo Deleting service %%E...)
         >nul 2>&1 reg delete %CCS%\Services\%%E /f
         set /a EmulFound=+1)
      >nul 2>&1 reg query %CCS%\%%E
      if not errorlevel 1 (
         if %lang%==0419 (echo Удаление дамп %%E...) else (echo Deleting dump %%E...)
         >nul 2>&1 reg delete %CCS%\%%E /f
         set /a EmulFound=+1)
      for %%I in (%windir%\inf\oem*.inf) do (
         set "dev_id="
         for /f "tokens=2 delims=\" %%R in ('find /i "root\%%E" "%%I" ^|find /i "root\"') do if /i "%%R"=="%%E" if not defined dev_id (
            set dev_id=%%R
            if %lang%==0419 (echo Удаление пакета %%~nxI с %%E...) else (echo Deleting package %%~nxI with %%E...)
            %devcon% dp_delete %%~nxI
            set /a EmulFound=+1))
      for %%S in (system32 SysWOW64) do if exist "%windir%\%%S\drivers\%%E.sys" (
         if %lang%==0419 (echo Удаление %%E.sys...) else (echo Deleting %%E.sys...)
         del /f /q %windir%\%%S\drivers\%%E.sys
         set /a EmulFound=+1)))
if %EmulFound% GTR 0 (if %lang%==0419 (echo Перезагрузите компьютер для внесения изменений^^!) else (echo Please restart computer for changes take effect^^!)) else (if %lang%==0419 (echo Эмуляторы не найдены^^!) else (echo No emulators found^^!))
pause
goto :eof

*/
var WSh = new ActiveXObject("WScript.Shell");
var Env = WSh.Environment("PROCESS");
var ShA = new ActiveXObject("Shell.Application");
ShA.ShellExecute(Env("COMSPEC"), '/c ""' + WScript.ScriptFullName + '""', "", "runas", 1);
