I can't see the var from an echo

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

I can't see the var from an echo

#1 Post by Docfxit » 16 Oct 2022 23:23

I have an echo on line 174 that I don't see when I run the batch script.
I do have:
setlocal EnableDelayedExpansion
On line 94
This is what it looks like when I run the script:
UVNCInstall.jpg
UVNCInstall.jpg (39.42 KiB) Viewed 5186 times
This is my batch file:

Code: Select all

@echo Off
:: The following code will make sure this is running as Administrator
(
>nul 2>&1 %__APPDIR__%net.exe session
) || (
echo Set UAC = CreateObject^("Shell.Application"^) > "%tmp%\uac.vbs"
echo UAC.ShellExecute "%~snx0", "%*", "%~sdp0", "runas", 1 >> "%tmp%\uac.vbs"
) && (
"%tmp%\uac.vbs" && exit /b
)
if exist "%tmp%\uac.vbs" del /f /q "%tmp%\uac.vbs"
:: The Above code will make sure this is running as Administrator

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

:: Required Files:  The following files must be in the same folder.
::          VNC_UltraVNC-102-Setup.exe
::          VNCsaveinf.inf
::          VNCsetup.reg
::          SecureVNCPlugin64.dsm   (ver. 1.1.8)  Until ver. 1.2.1 is fixed
::          rc4.key

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

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

setlocal EnableDelayedExpansion
::net use z: \\yourserver\sharename
::copy "z:\FolderName" "C:\TEST_BACKUP_FOLDER"

:FileCopied
set "file="
if not exist "%FileName%" (
set "file=!file!!lf!   ?    %FileName%"
xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\%FileName%" "%wkdir%"
IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.inf" (
set "file=!file!!lf!   ?    VNCsetup.inf"
xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.inf" "%wkdir%"
IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.reg" (
set "file=!file!!lf!   ?    VNCsetup.reg"
xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.reg" "%wkdir%"
IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "SecureVNCPlugin64.dsm" (
set "file=!file!!lf!   ?    SecureVNCPlugin64.dsm"
xcopy /y /f "\\DOCFXITLT10\C\Programs\UltraVNC\SecureVNCPlugin64.dsm" "%wkdir%"
IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "rc4.key" (
set "file=!file!!lf!   ?    rc4.key"
xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\RC4.KEY" "%wkdir%"
IF NOT ERRORLEVEL 1 GOTO FileCopied)

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.
Echo.
Echo.
echo    旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커
echo    ?                                
echo    ?  Please ignore all messages...
echo    ?                                
echo    ?                                
echo    ?  Please wait.  This does take a couple minutes ...                        
echo    ?                                
echo    읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸
netsh advfirewall firewall add rule name="UltraVNCTCP5909" dir=in action=allow protocol=TCP localport=5909
netsh advfirewall firewall add rule name=UltraVNCServer dir=in action=allow program="C:\Programs\UltraVNC\winvnc.exe" enable=yes 

:: To disable ForceGuest security setting:
::ForceGuest is disabled automatically in a domain environment
::   For workgroup computers, 
::       Open GPEDIT.MSC 
::          Browse through Computer Configuration
::                         Windows Settings
::                         Security Settings
::                         Local Policies
::                         Security Options 
::                         Select Network Access: Sharing and Security Model for Local Accounts. 
::                              Change this to Classic.
net stop WinVNC >nul
net stop uvnc_service >nul
sc delete uvnc_service >nul
If NOT exist "C:\Programs\UltraVNC" Md "C:\Programs\UltraVNC" > Nul
::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Set inffile="%wkdir%VNCsetup.inf"      ;I don't see this in the cmd window
echo %inffile%                         ;I don't see this in the cmd window
echo %wkdir%%FileName%                 ;I see this in the cmd window just fine
::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
::start /wait "%wkdir%%FileName%" /loadinf=%inffile% /props="vncsetup.reg" /Very silent
start /wait "%wkdir%%FileName%" /loadinf=%inffile% /Very silent
echo Importing vnc settings...
start /wait regedit /s %wkdir%vncsetup.reg
echo Copy the MSRC plugin...
copy /y "%wkdir%SecureVNCPlugin64.dsm" "C:\Programs\UltraVNC" > Nul
echo 128 Bit encryption key...
copy /y %wkdir%rc4.key "C:\Programs\UltraVNC" > Nul
echo Starting UltraVnc ...
::start /d "C:\Programs\UltraVNC" winvnc.exe -sinstall"
net start uvnc_service
start /d "C:\Programs\UltraVNC" winvnc.exe -servicehelper"
:: If you don't want the links on the desktop
::If exist "C:\Documents and Settings\%DesktopDir%\Desktop\Ultr@VNC Viewer.lnk" Del "C:\Documents and Settings\Gary\Desktop\Ultr@VNC Viewer.lnk"
If exist "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk" Del "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk"
::%windir%\System32\shutdown.exe -r -t 00
::exit
endlocal
CMD /k
)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#2 Post by aGerman » 17 Oct 2022 00:33

As always - if you update a variable value in a parenthesized block, and you want to access this value in the same block, you will need to enable delayed expansion and enclose your variables into exclamation points rather than percent signs. Proper line indentation helps to recognize whether you're in such a block.

Code: Select all

if 1==2 (
  rem foo
) else (
  set "var=hello"
  echo %var%
)
vs.

Code: Select all

setlocal EnableDelayedExpansion
if 1==2 (
  rem foo
) else (
  set "var=hello"
  echo !var!
)

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#3 Post by Docfxit » 17 Oct 2022 12:27

That's great to know.
I've see the exclamation points but I've never known why or the parameters for the requirement.
Thank you very much for explaining it to me.

I'd like to know why I don't see all lines echo'ed to the console.
VNCInstallBatError1.jpg
VNCInstallBatError1.jpg (106.54 KiB) Viewed 5151 times

Code: Select all

@echo Off
:: The following code will make sure this is running as Administrator
(
>nul 2>&1 %__APPDIR__%net.exe session
) || (
	echo Set UAC = CreateObject^("Shell.Application"^) > "%tmp%\uac.vbs"
	echo UAC.ShellExecute "%~snx0", "%*", "%~sdp0", "runas", 1 >> "%tmp%\uac.vbs"
) && (
	"%tmp%\uac.vbs" && exit /b
)
if exist "%tmp%\uac.vbs" del /f /q "%tmp%\uac.vbs"
:: The Above code will make sure this is running as Administrator

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

:: Required Files:  The following files must be in the same folder.
::          VNC_UltraVNC-102-Setup.exe
::          VNCsaveinf.inf
::          VNCsetup.reg
::          SecureVNCPlugin64.dsm   (ver. 1.1.8)  Until ver. 1.2.1 is fixed
::          rc4.key

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

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

setlocal EnableDelayedExpansion
::net use z: \\yourserver\sharename
::copy "z:\FolderName" "C:\TEST_BACKUP_FOLDER"

:FileCopied
set "file="
if not exist "%FileName%" (
	set "file=!file!!lf!   ?    %FileName%"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\%FileName%" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.inf" (
	set "file=!file!!lf!   ?    VNCsetup.inf"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.inf" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.reg" (
	set "file=!file!!lf!   ?    VNCsetup.reg"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.reg" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "SecureVNCPlugin64.dsm" (
	set "file=!file!!lf!   ?    SecureVNCPlugin64.dsm"
	xcopy /y /f "\\DOCFXITLT10\C\Programs\UltraVNC\SecureVNCPlugin64.dsm" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "rc4.key" (
	set "file=!file!!lf!   ?    rc4.key"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\RC4.KEY" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
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.
	Echo.
	Echo.
	echo    旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커
	echo    ?                                
	echo    ?  Please ignore all messages...
	echo    ?                                
	echo    ?                                
	echo    ?  Please wait.  This does take a couple minutes ...                        
	echo    ?                                
	echo    읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸
	netsh advfirewall firewall add rule name="UltraVNCTCP5909" dir=in action=allow protocol=TCP localport=5909
	netsh advfirewall firewall add rule name=UltraVNCServer dir=in action=allow program="C:\Programs\UltraVNC\winvnc.exe" enable=yes 

	:: To disable ForceGuest security setting:
	::ForceGuest is disabled automatically in a domain environment
	::   For workgroup computers, 
	::       Open GPEDIT.MSC 
	::          Browse through Computer Configuration
	::                         Windows Settings
	::                         Security Settings
	::                         Local Policies
	::                         Security Options 
	::                         Select Network Access: Sharing and Security Model for Local Accounts. 
	::                              Change this to Classic.
	echo Off
	net stop WinVNC >nul
	net stop uvnc_service >nul
	sc delete uvnc_service >nul
	If NOT exist "C:\Programs\UltraVNC" Md "C:\Programs\UltraVNC" > Nul
	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	Set inffile=%wkdir%VNCsetup.inf      
	echo !inffile!                         ;I see this in the cmd window
	echo %wkdir%%FileName%                 ;I see this in the cmd window just fine
	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	::start /wait "%wkdir%%FileName%" /loadinf=%inffile% /props="vncsetup.reg" /Very silent
	start /wait "%wkdir%%FileName%" /loadinf=!inffile! /Very silent
	echo Importing vnc settings...
	start /wait regedit /s %wkdir%vncsetup.reg
	echo Copy the MSRC plugin...
	copy /y "%wkdir%SecureVNCPlugin64.dsm" "C:\Programs\UltraVNC" > Nul
	echo 128 Bit encryption key...
	copy /y %wkdir%rc4.key "C:\Programs\UltraVNC" > Nul
	echo Starting UltraVnc ...
	::start /d "C:\Programs\UltraVNC" winvnc.exe -sinstall"
	net start uvnc_service
	start /d "C:\Programs\UltraVNC" winvnc.exe -servicehelper"
	:: If you don't want the links on the desktop
	::If exist "C:\Documents and Settings\%DesktopDir%\Desktop\Ultr@VNC Viewer.lnk" Del "C:\Documents and Settings\Gary\Desktop\Ultr@VNC Viewer.lnk"
	If exist "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk" Del "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk"
	::%windir%\System32\shutdown.exe -r -t 00
	::exit
	endlocal
	CMD /k
)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#4 Post by aGerman » 17 Oct 2022 13:57

I'm not familiar with UltraVNC. And in particular I'm not familiar with its command line syntax. A quick research in the internet suggests to enclose the path in quotes, like so:
/loadinf="!inffile!"
Also, in the same source I found that your
/Very silent
should rather be
/verysilent
at least without the space. For some tools command line switches may be also case-sensitive.

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#5 Post by Docfxit » 17 Oct 2022 14:13

Thank you for the reply...

I tried:

Code: Select all

start /wait "%wkdir%%FileName%" /loadinf="!inffile!" /verysilent
	
This is the result:
VNCInstallBatError2.jpg
VNCInstallBatError2.jpg (45.85 KiB) Viewed 5140 times
I'm getting the same result with quotes.

I origionally had:
/verysilent
This page says:
/Very silent
https://uvnc.com/docs/uvnc-server/48-uv ... ation.html

After I get it running I'll change it to what ever works.

Because it shows:
The system cannot find the drive specified
I'd like to see all cmds echo'ed to the window. Is there a way I can see that?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#6 Post by aGerman » 17 Oct 2022 14:36

I'd like to see all cmds echo'ed to the window. Is there a way I can see that?
Remove the @echo off. Alternatively update off to on.
Furthermore you can turn it off and on again at any position in your script.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#7 Post by aGerman » 17 Oct 2022 14:47

Now that I've taken a closer look at your screenshot it turns out that you have a lot of spaces after the .inf extension.
One of the reasons why you should prefer

Code: Select all

set "var=value"
to

Code: Select all

set var=value

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#8 Post by Docfxit » 17 Oct 2022 14:49

I have changed it to echo on.
I'm getting the same result.
VNCInstallBatError3.jpg
VNCInstallBatError3.jpg (47.58 KiB) Viewed 5129 times

Code: Select all

@echo Off
:: The following code will make sure this is running as Administrator
(
>nul 2>&1 %__APPDIR__%net.exe session
) || (
	echo Set UAC = CreateObject^("Shell.Application"^) > "%tmp%\uac.vbs"
	echo UAC.ShellExecute "%~snx0", "%*", "%~sdp0", "runas", 1 >> "%tmp%\uac.vbs"
) && (
	"%tmp%\uac.vbs" && exit /b
)
if exist "%tmp%\uac.vbs" del /f /q "%tmp%\uac.vbs"
:: The Above code will make sure this is running as Administrator

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

:: Required Files:  The following files must be in the same folder.
::          VNC_UltraVNC-102-Setup.exe
::          VNCsaveinf.inf
::          VNCsetup.reg
::          SecureVNCPlugin64.dsm   (ver. 1.1.8)  Until ver. 1.2.1 is fixed
::          rc4.key

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

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

setlocal EnableDelayedExpansion
::net use z: \\yourserver\sharename
::copy "z:\FolderName" "C:\TEST_BACKUP_FOLDER"

:FileCopied
set "file="
if not exist "%FileName%" (
	set "file=!file!!lf!   ?    %FileName%"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\%FileName%" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.inf" (
	set "file=!file!!lf!   ?    VNCsetup.inf"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.inf" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "VNCsetup.reg" (
	set "file=!file!!lf!   ?    VNCsetup.reg"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\VNCsetup.reg" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "SecureVNCPlugin64.dsm" (
	set "file=!file!!lf!   ?    SecureVNCPlugin64.dsm"
	xcopy /y /f "\\DOCFXITLT10\C\Programs\UltraVNC\SecureVNCPlugin64.dsm" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
if not exist "rc4.key" (
	set "file=!file!!lf!   ?    rc4.key"
	xcopy /y /f "\\DOCFXITLT10\Dnload2\9xAddons\VNC_Install\RC4.KEY" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
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.
	Echo.
	Echo.
	echo    旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커
	echo    ?                                
	echo    ?  Please ignore all messages...
	echo    ?                                
	echo    ?                                
	echo    ?  Please wait.  This does take a couple minutes ...                        
	echo    ?                                
	echo    읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸
	netsh advfirewall firewall add rule name="UltraVNCTCP5909" dir=in action=allow protocol=TCP localport=5909
	netsh advfirewall firewall add rule name=UltraVNCServer dir=in action=allow program="C:\Programs\UltraVNC\winvnc.exe" enable=yes 

	:: To disable ForceGuest security setting:
	::ForceGuest is disabled automatically in a domain environment
	::   For workgroup computers, 
	::       Open GPEDIT.MSC 
	::          Browse through Computer Configuration
	::                         Windows Settings
	::                         Security Settings
	::                         Local Policies
	::                         Security Options 
	::                         Select Network Access: Sharing and Security Model for Local Accounts. 
	::                              Change this to Classic.
	echo On
	net stop WinVNC >nul
	net stop uvnc_service >nul
	sc delete uvnc_service >nul
	If NOT exist "C:\Programs\UltraVNC" Md "C:\Programs\UltraVNC" > Nul
	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	Set inffile=%wkdir%VNCsetup.inf      
	echo !inffile!                         ;I see this in the cmd window
	echo %wkdir%%FileName%                 ;I see this in the cmd window just fine
	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	::start /wait "%wkdir%%FileName%" /loadinf=%inffile% /props="vncsetup.reg" /Very silent
	::start /wait "%wkdir%%FileName%" /loadinf=C:\Dnload\9xAddons\VNC.inf /Very silent
	start /wait "%wkdir%%FileName%" /verysilent /loadinf="!inffile!"
	echo Importing vnc settings...
	start /wait regedit /s %wkdir%vncsetup.reg
	echo Copy the MSRC plugin...
	copy /y "%wkdir%SecureVNCPlugin64.dsm" "C:\Programs\UltraVNC" > Nul
	echo 128 Bit encryption key...
	copy /y %wkdir%rc4.key "C:\Programs\UltraVNC" > Nul
	echo Starting UltraVnc ...
	::start /d "C:\Programs\UltraVNC" winvnc.exe -sinstall"
	net start uvnc_service
	start /d "C:\Programs\UltraVNC" winvnc.exe -servicehelper"
	:: If you don't want the links on the desktop
	::If exist "C:\Documents and Settings\%DesktopDir%\Desktop\Ultr@VNC Viewer.lnk" Del "C:\Documents and Settings\Gary\Desktop\Ultr@VNC Viewer.lnk"
	If exist "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk" Del "C:\Documents and Settings\%DesktopDir%\Desktop\UltraVNC Server.lnk"
	::%windir%\System32\shutdown.exe -r -t 00
	::exit
	endlocal
	CMD /k
)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#9 Post by aGerman » 17 Oct 2022 15:10

Code: Select all

	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	Set "inffile=%wkdir%VNCsetup.inf"
	echo !inffile!                         ;I see this in the cmd window
	echo %wkdir%%FileName%                 ;I see this in the cmd window just fine
	::*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	start "" /wait "%wkdir%%FileName%" /loadinf="!inffile!" /verysilent
Note
1) the quotes in the SET statements to get rid of trailing spaces
2) the "" after START because the first quoted string in a START command is treated as window title

FWIW
Bjarne Stroustrup, founder of C++ wrote:>>"Finding the smallest program that demonstrates the error" is a powerful debugging tool.<<
Why not just writing a few lines in a separate script to figure out how the syntax has to look like?

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#10 Post by Docfxit » 17 Oct 2022 19:29

I created a small bat file to include the minimum so i could see what wasn't working. I was able to see the lines that were executed and fixed the problems.

It's running now.

Thank you very much for your help.

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#11 Post by Docfxit » 19 Oct 2022 13:06

I'm getting an error saying:
"Invalid drive specification"

With this code:

Code: Select all

if not exist "%FileName%" (
	set "file=!file!!lf!   ?    %FileName%"
	xcopy /y /f "\\192.168.168.7\Dnload\VNC\%FileName%" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied)
The cmd window shows:

Code: Select all

C:\Dnload\VNC>if not exist "VNC UltraVNC_1_3_81_X64_Setup.exe" (
set "file=!file!!lf!   ?    VNC UltraVNC_1_3_81_X64_Setup.exe"
 xcopy /y /f \\192.168.168.7\"Dnload\VNC\VNC UltraVNC_1_3_81_X64_Setup.exe" "C:\Dnload\VNC\"
 IF NOT ERRORLEVEL 1 GOTO FileCopied
)
Invalid drive specification
0 File(s) copied

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: I can't see the var from an echo

#12 Post by ShadowThief » 19 Oct 2022 13:24

You may have to map the remote server to a network drive first.

Code: Select all

net use Z: \\192.168.168.7\

if not exist "%FileName%" (
	set "file=!file!!lf!   ?    %FileName%"
	xcopy /y /f "Z:\Dnload\VNC\%FileName%" "%wkdir%"
	IF NOT ERRORLEVEL 1 GOTO FileCopied
)

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#13 Post by Docfxit » 19 Oct 2022 13:37

I'm getting a system error 53 has occurred.
with this cmd:

Code: Select all

net use Z: \\192.168.168.7\

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I can't see the var from an echo

#14 Post by aGerman » 19 Oct 2022 13:58

I don't know. If you're sure the network resource is properly shared and existing, something like this might help:
https://learn.microsoft.com/en-us/troub ... -resources

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: I can't see the var from an echo

#15 Post by Docfxit » 19 Oct 2022 15:53

I tried to many different network setting.
Nothing worked.
I tried connecting manually, not in a bat file:

net use Z: \\192.168.168.7

I figured out it has to have a folder of some kind.

net use Z: \\192.168.168.7\Dnload\VNC

Then I found I had to remove the Mapped Network drive.

This is what I put into the bat file:
net use * /d /y
net use Z: \\192.168.168.7\Dnload\VNC


Thank you very much for your help.

Post Reply