Page 1 of 1

How to debug this bat file

Posted: 04 Mar 2024 14:22
by Docfxit
I have a bat file that I can't find why it has a syntax error.

This is the console output in Windows 10. I can't find what is causing the last line.

Code: Select all


C:\Dnload\9xAddons\VNC_Install>chcp 65001 1>nul

C:\Dnload\9xAddons\VNC_Install>Rem  The following code will make sure this is running as Administrator

C:\Dnload\9xAddons\VNC_Install>setlocal EnableDelayedExpansion

C:\Dnload\9xAddons\VNC_Install>set "params="

C:\Dnload\9xAddons\VNC_Install>cd /d "C:\Dnload\9xAddons\VNC_Install\"   && (if exist "C:\Users\Gary\AppData\Local\Temp\getadmin.vbs" del "C:\Users\Gary\AppData\Local\Temp\getadmin.vbs" )  && fsutil dirty query C:   1>nul 2>nul  || (echo Set UAC = CreateObject("Shell.Application") : UAC.ShellExecute "cmd.exe", "/k cd ""C:\Dnload\9xAddons\VNC_IN~1\"" && C:\Dnload\9xAddons\VNC_IN~1\VNCULT~1.BAT ", "", "runas", 1   1>>"C:\Users\Gary\AppData\Local\Temp\getadmin.vbs"  && "C:\Users\Gary\AppData\Local\Temp\getadmin.vbs"   && Exit /b )

C:\Dnload\9xAddons\VNC_Install>C:\Windows\system32\reg.exe query "HKU\S-1-5-19"   1>nul 2>nul  || (echo.   & echo  ERROR: This Batch file MUST be run in an ELEVATED cmd prompt [ Administrator ]   & echo.   & echo         Right-click the Batch file and click <Run as Administrator>.   & echo.   & echo >Press ANY key to EXIT . . .   & pause   1>nul  & Exit  )

C:\Dnload\9xAddons\VNC_Install>Rem  The Above code will make sure this is running as Administrator

C:\Dnload\9xAddons\VNC_Install>Rem  This will install UltraVNC on a PC remotely.

C:\Dnload\9xAddons\VNC_Install>Rem

C:\Dnload\9xAddons\VNC_Install>Rem  Disclaimer:  Use at your own risk.  I have tested this on my PC running Windows 10.

C:\Dnload\9xAddons\VNC_Install>Rem

C:\Dnload\9xAddons\VNC_Install>Rem  To run:  Copy this file to the remote PC

C:\Dnload\9xAddons\VNC_Install>Rem           Run this Batch file on the remote PC

C:\Dnload\9xAddons\VNC_Install>Rem           Wait for it to complete.  This could take a couple minutes.

C:\Dnload\9xAddons\VNC_Install>Rem           View remote PC with the new VNC viewer.

C:\Dnload\9xAddons\VNC_Install>Rem

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  If the VNC service is not running you will get an error.

C:\Dnload\9xAddons\VNC_Install>Rem                         You should ignore it.

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  This does produce a screen that says

C:\Dnload\9xAddons\VNC_Install>Rem                         "Warning:  This machine has no default password set"

C:\Dnload\9xAddons\VNC_Install>Rem                         You should ignore it.

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  This will re-boot.  When it comes up the password and all the settings will

C:\Dnload\9xAddons\VNC_Install>Rem                               be good to go if you followed the instructions below.

C:\Dnload\9xAddons\VNC_Install>Rem  Required Files:  The following files must be in the same folder.

C:\Dnload\9xAddons\VNC_Install>Rem           VNC UltraVNC_1436_X64_Setup.exe

C:\Dnload\9xAddons\VNC_Install>Rem           VNCsaveinf.inf

C:\Dnload\9xAddons\VNC_Install>Rem           VNCsetup.reg

C:\Dnload\9xAddons\VNC_Install>Rem           SecureVNCPlugin64.dsm   (ver. 1.1.8)  Until ver. 1.2.1 is fixed

C:\Dnload\9xAddons\VNC_Install>Rem           rc4.key

C:\Dnload\9xAddons\VNC_Install>Rem              I put all files on a PC on the local LAN. This bat file will download all files to the PC this bat file is run from.

C:\Dnload\9xAddons\VNC_Install>Rem    Thanks to extremesanity on the ULtraVNC forum for some of these instructions.

C:\Dnload\9xAddons\VNC_Install>Rem           I wanted to put all instructions in one place.

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  You can get VNC UltraVNC_1436_X64_Setup.exe at:

C:\Dnload\9xAddons\VNC_Install>Rem                  https://uvnc.com/downloads/ultravnc.html

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  You can get VNCsaveinf.inf & VNCsetup.reg by running the following:

C:\Dnload\9xAddons\VNC_Install>Rem           1. Run on a local PC the exe with the command "VNC UltraVNC_1436_X64_Setup.exe /saveinf=c:\VNCsaveinf.inf"

C:\Dnload\9xAddons\VNC_Install>Rem                  This will save the main config file to a path of your choosing.

C:\Dnload\9xAddons\VNC_Install>Rem           2. Go through the setup changing config settings to how you want it installed (language, program path, etc).

C:\Dnload\9xAddons\VNC_Install>Rem              Make sure to make the following selections

C:\Dnload\9xAddons\VNC_Install>Rem                  UltraVNC Server

C:\Dnload\9xAddons\VNC_Install>Rem                  Mirror Driver

C:\Dnload\9xAddons\VNC_Install>Rem                  DSM Encryption Plugin

C:\Dnload\9xAddons\VNC_Install>Rem              and on the additional tasks page select Register UltraVNC as service

C:\Dnload\9xAddons\VNC_Install>Rem              DO NOT select Start or restart UltraVNC Service

C:\Dnload\9xAddons\VNC_Install>Rem              select Configure MS-Logon II (If you want it)

C:\Dnload\9xAddons\VNC_Install>Rem              DO NOT select Configure Admin Properties

C:\Dnload\9xAddons\VNC_Install>Rem              DO NOT select Clean old VNC registry keys

C:\Dnload\9xAddons\VNC_Install>Rem              Don't worry about the ACL settings, we will change those in a bit

C:\Dnload\9xAddons\VNC_Install>Rem           3. When it's finished go to the start menu and click on UltraVNC > UltraVNC Server

C:\Dnload\9xAddons\VNC_Install>Rem              Click on the show default settings.

C:\Dnload\9xAddons\VNC_Install>Rem              Make all the changes you want applied across all computers here.

C:\Dnload\9xAddons\VNC_Install>Rem                  The password, MS Logon groups, and misc settings need to be set.

C:\Dnload\9xAddons\VNC_Install>Rem           4. If you don't have the file rc4.key from a previous install create one by:

C:\Dnload\9xAddons\VNC_Install>Rem              Putting a check mark into the box DSM Plugin.

C:\Dnload\9xAddons\VNC_Install>Rem              Select the plugin.

C:\Dnload\9xAddons\VNC_Install>Rem              Select Config.

C:\Dnload\9xAddons\VNC_Install>Rem              Select 128 bit

C:\Dnload\9xAddons\VNC_Install>Rem              Select Gen Key

C:\Dnload\9xAddons\VNC_Install>Rem           5. If you want to use MS-Logon II:

C:\Dnload\9xAddons\VNC_Install>Rem                  In DOS in c:\programs\ultravnc

C:\Dnload\9xAddons\VNC_Install>Rem                  Type in MSLogonACL.exe /e c:\someaclconfigfile.acl - this will create your ACL file

C:\Dnload\9xAddons\VNC_Install>Rem                  close DOS

C:\Dnload\9xAddons\VNC_Install>Rem              Note:  I have not included this in the install bat file.  I have not used it yet.

C:\Dnload\9xAddons\VNC_Install>Rem                     Someone else might be able to comment on how to use it.

C:\Dnload\9xAddons\VNC_Install>Rem           6. Start > run > regedit

C:\Dnload\9xAddons\VNC_Install>Rem                  Export the hkey_local_machine > software > ORL key to reg file VNCsetup.reg

C:\Dnload\9xAddons\VNC_Install>Rem           7. Edit the VNCsaveinf.inf file you created in steps 1 & 2 above,

C:\Dnload\9xAddons\VNC_Install>Rem                  and put this in for the acl and reg paths

C:\Dnload\9xAddons\VNC_Install>Rem                       AclFile=c:\PathToThisFolder\someaclfile.txt

C:\Dnload\9xAddons\VNC_Install>Rem                       PropertiesFile=c:\PathToThisFolder\VNCsetup.reg

C:\Dnload\9xAddons\VNC_Install>Rem    Note:  You can get SecureVNCPlugin64.dsm   (ver. 1.1.8) at:

C:\Dnload\9xAddons\VNC_Install>Rem                  https://uvnc.com/

C:\Dnload\9xAddons\VNC_Install>Rem           1. Install the above file only selecting SecureVNCPlugin64.dsm

C:\Dnload\9xAddons\VNC_Install>Rem           2. After saving the SecureVNCPlugin64.dsm you can delete the rest that was installed.

C:\Dnload\9xAddons\VNC_Install>Rem

C:\Dnload\9xAddons\VNC_Install>Rem           Save the required files listed above to a scratch folder.

C:\Dnload\9xAddons\VNC_Install>Rem           The files are all created. Shut down VNC. You can uninstall it if you don't need it.

C:\Dnload\9xAddons\VNC_Install>Rem

C:\Dnload\9xAddons\VNC_Install>set /p Port="Enter the port: Example: 5900 "   || goto :processCancelled
Enter the port: Example: 5900 5920

C:\Dnload\9xAddons\VNC_Install>Rem Set Port=5917

C:\Dnload\9xAddons\VNC_Install>set "_os=64"

C:\Dnload\9xAddons\VNC_Install>if "AMD64" == "x86" (if not defined PROCESSOR_ARCHITEW6432 set "_os=32" )

C:\Dnload\9xAddons\VNC_Install>Rem if 64==32 echo This is a 32bit operating system

C:\Dnload\9xAddons\VNC_Install>if 64 == 64 (
echo This is a 64bit operating system
 Set "FileName=VNC UltraVNC_1436_X64_Setup.exe"
)  else (Set "FileName=VNC UltraVNC_1436_X86_Setup.exe" )
This is a 64bit operating system

C:\Dnload\9xAddons\VNC_Install>set "wkdir=C:\Dnload\9xAddons\VNC_Install\"

C:\Dnload\9xAddons\VNC_Install>cd /D C:\Dnload\9xAddons\VNC_Install\

C:\Dnload\9xAddons\VNC_Install>(set lf=  )

C:\Dnload\9xAddons\VNC_Install>setlocal EnableDelayedExpansion

C:\Dnload\9xAddons\VNC_Install>net use * /d /y
You have these remote connections:

    Z:              \\192.168.168.7\Dnload\VNC
Continuing will cancel the connections.

The command completed successfully.


C:\Dnload\9xAddons\VNC_Install>net use Z: \\192.168.168.7\Dnload\VNC
The command completed successfully.


C:\Dnload\9xAddons\VNC_Install>set "file="

C:\Dnload\9xAddons\VNC_Install>if not exist "VNC UltraVNC_1436_X64_Setup.exe" (
set "file=!file!!lf!   ?    VNC UltraVNC_1436_X64_Setup.exe"
 xcopy /y /f "Z:\VNC UltraVNC_1436_X64_Setup.exe" "C:\Dnload\9xAddons\VNC_Install\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if not exist "VNCsetup.inf" (
set "file=!file!!lf!   ?    VNCsetup.inf"
 xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCsetup.inf" "C:\Dnload\9xAddons\VNC_Install\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if not exist "VNCsetup.reg" (
set "file=!file!!lf!   ?    VNCsetup.reg"
 xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCsetup.reg" "C:\Dnload\9xAddons\VNC_Install\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if 64 == 64 (if not exist "SecureVNCPlugin64.dsm" (
set "file=!file!!lf!   ?    SecureVNCPlugin64.dsm"
 xcopy /y /f "\\192.168.168.7\C\Programs\UltraVNC\SecureVNCPlugin64.dsm" "C:\Dnload\9xAddons\VNC_Install\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
) )

C:\Dnload\9xAddons\VNC_Install>Rem if not exist "rc4.key" (

C:\Dnload\9xAddons\VNC_Install>Rem      set "file=!file!!lf!   ?    rc4.key"

C:\Dnload\9xAddons\VNC_Install>Rem      xcopy /y /f "\\192.168.168.7\Dnload\VNC\RC4.KEY" "C:\Dnload\9xAddons\VNC_Install\"

C:\Dnload\9xAddons\VNC_Install>Rem      IF NOT ERRORLEVEL 1 GOTO FileCopied)

C:\Dnload\9xAddons\VNC_Install>xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCultravnc.ini" "C:\Dnload\9xAddons\VNC_Install\"
\\192.168.168.7\Dnload\VNC\VNCultravnc.ini -> C:\Dnload\9xAddons\VNC_Install\VNCultravnc.ini
1 File(s) copied

C:\Dnload\9xAddons\VNC_Install>if not exist "replace.vbs" (
set "file=!file!!lf!   ?    replace.vbs"
 xcopy /y /f "\\192.168.168.7\Dnload\VNC\replace.vbs" "C:\Dnload\9xAddons\VNC_Install\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if not exist "C:\Batch\pskill.exe" (
set "file=!file!!lf!   ?    pskill.exe"
 If NOT exist "C:\Batch" Md "C:\Batch"  1>Nul
 xcopy /y /f "\\192.168.168.7\Dnload2\9xAddons\Batch\pskill.exe" "C:\Batch\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if not exist "C:\Batch\SetACL.exe" (
set "file=!file!!lf!   ?    SetACL.exe"
 If NOT exist "C:\Batch" Md "C:\Batch"  1>Nul
 xcopy /y /f "\\192.168.168.7\Dnload2\9xAddons\Batch\SetACL.exe" "C:\Batch"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)

C:\Dnload\9xAddons\VNC_Install>if not exist "C:\Program files\DeeEnEs\DeeEnEs.exe" (if not exist "C:\Programs\DeeEnEs\DeeEnEs.exe" (
set "file=!file!!lf!   ?    DeeEnEs.exe"
 If NOT exist "C:\Programs\DeeEnEs" Md "C:\Programs\DeeEnEs"  1>Nul
 xcopy /y /f "\\192.168.168.7\Dnload\VNC\DeeEnEs.exe" "C:\Programs\DeeEnEs"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
) )

C:\Dnload\9xAddons\VNC_Install>Pause
Press any key to continue . . .
The syntax of the command is incorrect.
This is the bat file:

Code: Select all

@echo On
>nul chcp 65001
Rem  The following code will make sure this is running as Administrator
@echo off & mode con cols=86 lines=22 & color 17
Set "Variable=0" & if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
fsutil dirty query %systemdrive%  >nul 2>&1 && goto :(Privileges_got)
If "%1"=="%Variable%" (echo. &echo. Please right-click on the file and select &echo. "Run as administrator". &echo. Press any key to exit. &pause>nul 2>&1& exit)
cmd /u /c echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "%~0", "%Variable%", "", "runas", 1 > "%temp%\getadmin.vbs"&cscript //nologo "%temp%\getadmin.vbs" & exit
:(Privileges_got)
Rem  The Above code will make sure this is running as Administrator

Rem  This will install UltraVNC on a PC remotely.
Rem 
Rem  Disclaimer:  Use at your own risk.  I have tested this on my PC running Windows 10.
Rem 
Rem  To run:  Copy this file to the remote PC
Rem           Run this Batch file on the remote PC
Rem           Wait for it to complete.  This could take a couple minutes.
Rem           View remote PC with the new VNC viewer.
Rem 
Rem    Note:  If the VNC service is not running you will get an error.
Rem                         You should ignore it.
Rem    Note:  This does produce a screen that says 
Rem                         "Warning:  This machine has no default password set"
Rem                         You should ignore it.  
Rem    Note:  This will re-boot.  When it comes up the password and all the settings will 
Rem                               be good to go if you followed the instructions below.

Rem  Required Files:  The following files must be in the same folder.
Rem           VNC UltraVNC_1436_X64_Setup.exe
Rem           VNCsaveinf.inf
Rem           VNCsetup.reg
Rem           SecureVNCPlugin64.dsm   (ver. 1.1.8)  Until ver. 1.2.1 is fixed
Rem           rc4.key
Rem 		I put all files on a PC on the local LAN. This bat file will download all files to the PC this bat file is run from.

Rem    Thanks to extremesanity on the ULtraVNC forum for some of these instructions.
Rem           I wanted to put all instructions in one place.

Rem    Note:  You can get VNC UltraVNC_1436_X64_Setup.exe at:
Rem                  https://uvnc.com/downloads/ultravnc.html
Rem    Note:  You can get VNCsaveinf.inf & VNCsetup.reg by running the following:
Rem           1. Run on a local PC the exe with the command "VNC UltraVNC_1436_X64_Setup.exe /saveinf=c:\VNCsaveinf.inf"
Rem                  This will save the main config file to a path of your choosing.
Rem           2. Go through the setup changing config settings to how you want it installed (language, program path, etc).
Rem              Make sure to make the following selections
Rem                  UltraVNC Server
Rem                  Mirror Driver
Rem                  DSM Encryption Plugin
Rem              and on the additional tasks page select Register UltraVNC as service
Rem              DO NOT select Start or restart UltraVNC Service
Rem              select Configure MS-Logon II (If you want it)
Rem              DO NOT select Configure Admin Properties
Rem              DO NOT select Clean old VNC registry keys
Rem              Don't worry about the ACL settings, we will change those in a bit
Rem           3. When it's finished go to the start menu and click on UltraVNC > UltraVNC Server
Rem              Click on the show default settings.
Rem              Make all the changes you want applied across all computers here. 
Rem                  The password, MS Logon groups, and misc settings need to be set.
Rem           4. If you don't have the file rc4.key from a previous install create one by:
Rem              Putting a check mark into the box DSM Plugin.
Rem              Select the plugin.
Rem              Select Config.
Rem              Select 128 bit
Rem              Select Gen Key    
Rem           5. If you want to use MS-Logon II:
Rem                  In DOS in c:\programs\ultravnc
Rem                  Type in MSLogonACL.exe /e c:\someaclconfigfile.acl - this will create your ACL file
Rem                  close DOS 
Rem              Note:  I have not included this in the install bat file.  I have not used it yet.
Rem                     Someone else might be able to comment on how to use it.
Rem           6. Start > run > regedit
Rem                  Export the hkey_local_machine > software > ORL key to reg file VNCsetup.reg
Rem           7. Edit the VNCsaveinf.inf file you created in steps 1 & 2 above, 
Rem                  and put this in for the acl and reg paths
Rem                       AclFile=c:\PathToThisFolder\someaclfile.txt
Rem                       PropertiesFile=c:\PathToThisFolder\VNCsetup.reg
Rem    Note:  You can get SecureVNCPlugin64.dsm   (ver. 1.1.8) at:
Rem                  https://uvnc.com/
Rem           1. Install the above file only selecting SecureVNCPlugin64.dsm
Rem           2. After saving the SecureVNCPlugin64.dsm you can delete the rest that was installed.  
Rem           
Rem           Save the required files listed above to a scratch folder. 
Rem           The files are all created. Shut down VNC. You can uninstall it if you don't need it.
Rem 
@echo on
    set /p Port="Enter the port: Example: 5900 " || goto :processCancelled

Rem Set Port=5917
set _os=64
if "%PROCESSOR_ARCHITECTURE%"=="x86" (if not defined PROCESSOR_ARCHITEW6432 set _os=32)
Rem if %_OS%==32 echo This is a 32bit operating system
	if %_OS%==64 (
	echo This is a 64bit operating system 
	Set FileName=VNC UltraVNC_1436_X64_Setup.exe
	) else (
	Set FileName=VNC UltraVNC_1436_X86_Setup.exe
	)
set wkdir=%~dp0
cd /D %wkdir%
(set lf=^
	%= creates a line feed, do not alter =%
)
@echo on 
setlocal EnableDelayedExpansion
net use * /d /y
net use Z: \\192.168.168.7\Dnload\VNC

:FileCopied
set "file="
if not exist "%FileName%" (
	set "file=!file!!lf!   ?    %FileName%"
	xcopy /y /f "Z:\%FileName%" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.inf" (
	set "file=!file!!lf!   ?    VNCsetup.inf"
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCsetup.inf" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.reg" (
	set "file=!file!!lf!   ?    VNCsetup.reg"
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCsetup.reg" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if %_OS%==64 (
		if not exist "SecureVNCPlugin64.dsm" (
		set "file=!file!!lf!   ?    SecureVNCPlugin64.dsm"
		xcopy /y /f "\\192.168.168.7\C\Programs\UltraVNC\SecureVNCPlugin64.dsm" "%wkdir%"
		IF NOT ERRORLEVEL 1 GOTO FileCopied)
)
Rem if not exist "rc4.key" (
Rem 	set "file=!file!!lf!   ?    rc4.key"
Rem 	xcopy /y /f "\\192.168.168.7\Dnload\VNC\RC4.KEY" "%wkdir%"
Rem 	IF NOT ERRORLEVEL 1 GOTO FileCopied)
::if not exist "VNCultravnc.ini" (
::	set "file=!file!!lf!   ?    VNCultravnc.ini"
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\VNCultravnc.ini" "%wkdir%"
rem	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "replace.vbs" (
	set "file=!file!!lf!   ?    replace.vbs"
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\replace.vbs" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "C:\Batch\pskill.exe" (
	set "file=!file!!lf!   ?    pskill.exe"
	If NOT exist "C:\Batch" Md "C:\Batch" > Nul
	xcopy /y /f "\\192.168.168.7\Dnload2\9xAddons\Batch\pskill.exe" "C:\Batch\"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "C:\Batch\SetACL.exe" (
	set "file=!file!!lf!   ?    SetACL.exe"
	If NOT exist "C:\Batch" Md "C:\Batch" > Nul
	xcopy /y /f "\\192.168.168.7\Dnload2\9xAddons\Batch\SetACL.exe" "C:\Batch"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "C:\Program files\DeeEnEs\DeeEnEs.exe" (
	if not exist "C:\Programs\DeeEnEs\DeeEnEs.exe" (
	set "file=!file!!lf!   ?    DeeEnEs.exe"
	If NOT exist "C:\Programs\DeeEnEs" Md "C:\Programs\DeeEnEs" > Nul
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\DeeEnEs.exe" "C:\Programs\DeeEnEs"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
	)
	@Echo On
if defined file (
	Echo.
	Echo.
	Echo.
	Echo.
	Echo.
	Echo.
	Echo.
	echo    ┌──────────────────────────────────────────────────────────────┐
	echo    ?  The files ...%file%
	echo    ?  
	echo    ?  ... do not exist in this directory.
	echo    ?                                
	echo    ?  Move the above files into %wkdir% 
	echo    ?                                
	echo    ?                                
	echo    ?                                
	echo    ?  Press any key to close this window                              
	echo    ?                                
	echo    └──────────────────────────────────────────────────────────────┘
	Pause > Nul
) Else (
	@echo on 
	Echo.
	Echo.
	Echo.
	echo    ┌──────────────────────────────────────────────────────────────┐
	echo    ?                                
	echo    ?  Please ignore all messages...
	echo    ?                                
	echo    ?                                
	echo    ?  Please wait.  This does take a couple minutes ...                        
	echo    ?                                
	echo    └──────────────────────────────────────────────────────────────┘
	cscript replace.vbs "%wkdir%VNCultravnc.ini" "5905" %Port% 
	Rem (if command errors) || (exec this command)
	netsh advfirewall firewall show rule name="UltraVNCTCP%Port%" >nul || netsh advfirewall firewall add rule name="UltraVNCTCP!Port!" dir=in action=allow protocol=TCP localport=!Port!
	netsh advfirewall firewall show rule name="vnc5900" >nul | netsh advfirewall firewall delete rule name="vnc5900"
	netsh advfirewall firewall show rule name="vncviewer.exe" >nul | netsh advfirewall firewall delete rule name="vncviewer.exe"
	netsh advfirewall firewall show rule name="winvnc.exe" >nul | netsh advfirewall firewall delete rule name="winvnc.exe"
	netsh advfirewall firewall show rule name="UltraVNCServer" >nul | netsh advfirewall firewall delete rule name="UltraVNCServer"
	netsh advfirewall firewall add rule name=UltraVNCServer dir=in action=allow program="C:\Programs\UltraVNC\winvnc.exe" enable=yes 
	@Echo On
	C:
	cd\Batch
	C:\Batch\SetACL.exe -on "C:\Programs\UltraVNC" -ot file -actn ace -ace "n:%username%;p:full"
	Rem vncserver -kill :2
	Rem vncserver -kill :1
	C:\Batch\pskill.exe -t vncviewer.exe >nul
	Rem C:\Batch\pskill.exe -t winvnc.exe >nul
	Rem If process winvnc.exe 
	Rem Change the name of notepad.exe to the process .exe that you're trying to track
	Rem Process names are CASE SENSITIVE, so notepad.exe works but Notepad.exe does NOT
	Rem Do not change IMAGENAME
	Rem You can Copy and Paste this into an empty batch file and change the name of
	Rem notepad.exe to the process you'd like to track
	Rem Also, some large programs take a while to no longer show as not running, so
	Rem give this batch a few seconds timer to avoid a false result!!

	@Echo on
	SETLOCAL EnableExtensions
	set EXE=notepad.exe
	FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq !EXE!"') DO IF %%x == !EXE! goto ProcessFound
	goto ProcessNotFound
	:ProcessFound
	Echo !EXE! is running
	goto Finished
	:ProcessNotFound
	Echo !EXE! is not running
	goto Finished
	:Finished
	Echo Finished!
	rem C:\Batch\pskill.exe -t winvnc.exe 
	C:\Programs\UltraVNC\winvnc.exe -kill >nul
	cd\
	net stop WinVNC 2>nul
	net stop uvnc_service 2>nul
	sc delete uvnc_service 2>nul
	@Echo Remove "%ProgramFiles%\uvnc bvba"...
	C:\Batch\SetACL.exe -on "%ProgramFiles%\uvnc bvba" -ot file -actn ace -ace "n:%username%;p:full" >nul
	If exist "C:\Program Files\uvnc bvba\UltraVNC\unins000.exe" start "" /wait "%ProgramFiles%\uvnc bvba\UltraVNC\unins000.exe" /VERYSILENT /NORESTART >nul
	If exist "C:\Program Files\uvnc bvba" rd "C:\Program Files\uvnc bvba"
	C:\Batch\SetACL.exe -on "%ProgramFiles%\UltraVNC" -ot file -actn ace -ace "n:%username%;p:full" >nul
	If exist "C:\Program Files\UltraVNC\unins000.exe" start "" /wait "%ProgramFiles%\UltraVNC\unins000.exe" /VERYSILENT /NORESTART >nul
	If exist "C:\Program Files\UltraVNC\*" Del /S /Q "C:\Program Files\UltraVNC\*"
	If exist "C:\Program Files\UltraVNC" rd "C:\Program Files\UltraVNC"
	If exist "%UserProfile%\AppData\Roaming\UltraVNC\*" Del /S /Q "%UserProfile%\AppData\Roaming\UltraVNC\*"
	If exist "%UserProfile%\AppData\Roaming\UltraVNC" rd "%UserProfile%\AppData\Roaming\UltraVNC"
	If exist "%UserProfile%\Documents\UltraVNC\*" Del /S /Q "%UserProfile%\Documents\UltraVNC\*"
	If exist "%UserProfile%\Documents\UltraVNC" rd "%UserProfile%\Documents\UltraVNC"
	If NOT exist "C:\Programs\UltraVNC" Md "C:\Programs\UltraVNC" > Nul     
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UFH\SHC"
Rem Set "Str=uvnc bvba"
Set "Str=UltraVNC"
setlocal EnableExtensions DisableDelayedExpansion
If exist %~dpn0.txt del %~dpn0.txt
If exist %~dpn0Str.txt del %~dpn0Str.txt
for /F "tokens=1,2*" %%A in ('@%SystemRoot%\System32\reg.exe query "%Key%" /v * ^| find "%Str%"') DO @(%SystemRoot%\System32\reg.exe delete "%Key%" /v "%%A" /f
    if not errorlevel 1 echo Deleted "%%A" from "%Key%" >>%~dpn0.txt >nul
	echo %%C >>%~dpn0Str.txt
)
reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FeatureUsage\AppSwitched" /v "{6D809377-6AF0-444B-8957-A3773F02200E}\UltraVNC\vncviewer.exe" /f
reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" /v "C:\Program Files\UltraVNC\winvnc.exe" /f
reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" /v "C:\Program Files\UltraVNC\vncviewer.exe" /f
reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" /v "C:\Program Files\uvnc bvba\UltraVNC\vncviewer.exe" /f
reg delete "HKEY_CURRENT_USER\SOFTWARE\Ordinarysoft\Start Menu X\RunPaths" /v "102383863" /f
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\ORL" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Application\UltraVNC" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{FF5A5146-C6BB-41B7-9D61-727E42414F9F}" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{AEB15B01-FD2B-447E-A421-879AC272A93E}" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\Setup\FirstBoot\Services\uvnc_service" /f
	@CD /d "%~dp0"
	start "" /wait "%wkdir%%FileName%" /verysilent /loadinf="%wkdir%VNCsetup.inf" /NORESTART /DIR=C:\Programs\UltraVNC
	echo Importing vnc settings...
	start "" /wait regedit /s %wkdir%vncsetup.reg
	echo Copy the VNCultravnc.ini
	copy /y "%wkdir%VNCultravnc.ini" "C:\Programs\UltraVNC\ultravnc.ini" > Nul
	echo Copy the MSRC plugin...
	if %_OS%==64 (
		copy /y "%wkdir%SecureVNCPlugin64.dsm" "C:\Programs\UltraVNC\SecureVNCPlugin64.dsm" > Nul
	)
Rem 	echo 128 Bit encryption key...
Rem 	copy /y %wkdir%rc4.key "C:\Programs\UltraVNC" > Nul
	echo Starting UltraVnc ...
	net start uvnc_service

	Rem start "" /d "C:\Programs\UltraVNC" winvnc.exe -servicehelper"
	Rem  If you don't want the links on the desktop
	Rem If exist "%UserProfile%\Desktop\Ultr@VNC Viewer.lnk" Del "%UserProfile%\Desktop\Ultr@VNC Viewer.lnk"
	netsh advfirewall firewall show rule name="vnc5900" >nul | netsh advfirewall firewall delete rule name="vnc5900"
	If exist "%UserProfile%\Desktop\UltraVNC Server.lnk" Del "%UserProfile%\Desktop\UltraVNC Server.lnk"
	If exist "%UserProfile%\Desktop\UltraVNC Settings.lnk" Del "%UserProfile%\Desktop\UltraVNC Settings.lnk"
	If exist "%UserProfile%\Desktop\UltraVNC Launcher.lnk" Del "%UserProfile%\Desktop\UltraVNC Launcher.lnk"
	If exist "%UserProfile%\Desktop\UltraVNC Viewer.lnk" Del "%UserProfile%\Desktop\UltraVNC Viewer.lnk"
	If exist "%UserProfile%\Desktop\UltraVNC Repeater.lnk" Del "%UserProfile%\Desktop\UltraVNC Repeater.lnk"
	C:\Batch\pskill.exe -t DeeEnEs
	If exist "C:\Program files\DeeEnEs\DeeEnEs.exe" (
		start "" "C:\Program files\DeeEnEs\DeeEnEs.exe")
	if not exist "C:\Program files\DeeEnEs\DeeEnEs.exe" (
		start "" "C:\Programs\DeeEnEs\DeeEnEs.exe")
	Rem %windir%\System32\shutdown.exe -r -t 00
	del /q "%wkdir%"SecureVNC*
	del /q "%wkdir%"replace.vbs
	del /q "%wkdir%"ultravnc*
	del /q "%wkdir%"VNC*
	@Echo Finished...
	endlocal
)
:processCancelled 
cmd/k

Re: How to debug this bat file

Posted: 05 Mar 2024 10:48
by miskox
Been offline for a while.

Maybe you should remove this line

Code: Select all

Rem (if command errors) || (exec this command)
or add ^ infront of the problematic characters (, ), |.

Maybe there are more.

Try this and let us know.

Saso

Re: How to debug this bat file

Posted: 05 Mar 2024 12:20
by Docfxit
Thank you for the reply...

If I add ^ infront of the problematic characters (, ), |

What would the line look like?
I'm not familiar with that character.

Isn't that line a remark? Why would the cmd interpreter care what characters are in a remark?

Thank you,

Re: How to debug this bat file

Posted: 05 Mar 2024 14:05
by Squashman
Docfxit wrote:
05 Mar 2024 12:20
Thank you for the reply...

If I add ^ infront of the problematic characters (, ), |

What would the line look like?
I'm not familiar with that character.

Isn't that line a remark? Why would the cmd interpreter care what characters are in a remark?

Thank you,
Are you saying you are not familiar with the "^"? If so, $10 says I can find multiple threads you started that you are using it in your code.

Re: How to debug this bat file

Posted: 05 Mar 2024 17:40
by Docfxit
The reason I create a thread here is so I can learn something. I don't come here to place bets. I did a search on all the bat files I have. I did find some bat files with a carrot. The only reason I have bat files with a carrot is because I have copied it from someone else's code. I have never used a carrot in my coding. I did a search on Google for batch "^". I didn't find anything.
If you don't know how to explain what the carrot does please don't post a response, and let someone that does know what it does to give me an explanation. I'm sorry I am not as sharp as you are with batch coding. That's why I come here so I can learn more about batch coding. That's great that you can find something I have done in the past. I don't ask questions that I remember I have asked before. If I have asked about something that I did get an answer to before I am truly sorry. Anything I ask on this forum I have done a search on before I ask here. You must spend a lot more time doing searches and betting on things I have done in the past than just answering the question. Some people get satisfaction in answering peoples questions. It's obvious you get satisfaction from pointing out that the person asking a question has asked it before.

Re: How to debug this bat file

Posted: 06 Mar 2024 10:18
by miskox
So, did you try it? Does it work?

Start here:

https://ss64.com/nt/syntax-esc.html

Code: Select all

Escape Character

      ^  Escape character.

    Adding the escape character before a command symbol allows it to be treated as ordinary text. These characters which normally have a special meaning can be escaped and then treated like regular characters  : & \ < > ^ |

    e.g. Echo THIS ^& THAT
         Echo Heading1 ^| heading2 ^| heading3
         Echo The Escape character looks like this ^^


https://www.robvanderwoude.com/escapechars.php


Saso

Re: How to debug this bat file

Posted: 06 Mar 2024 23:55
by Docfxit
miskox wrote:
06 Mar 2024 10:18
So, did you try it? Does it work?

Start here:

https://ss64.com/nt/syntax-esc.html

Code: Select all

Escape Character

      ^  Escape character.

    Adding the escape character before a command symbol allows it to be treated as ordinary text. These characters which normally have a special meaning can be escaped and then treated like regular characters  : & \ < > ^ |

    e.g. Echo THIS ^& THAT
         Echo Heading1 ^| heading2 ^| heading3
         Echo The Escape character looks like this ^^


https://www.robvanderwoude.com/escapechars.php


Saso
That is very nice of you to let me know what the carrot does.
Thank you very much. That was really great of you.
Thanks...

I have found all the errors. It is working now. I have replaced the bat file in the first post to be the corrected one.

Thank you.