Automating connection to VNC with batch file - windows

I'm trying to create a batch file to automate vnc connections, this is what i came up with:
#echo off
:Begin
set "PASS=123"
set /p IP=Enter IP Address:
echo Connecting...
start /d "C:\Program Files (x86)\UltraVNC\" VNCVIEWER.EXE %IP%
goto Begin
problem is that the program comes up with a second pop up display for the password which is always 123 but i don't know how to make that automatic too, once the process is open how do i make the batch file enter the password as well automatically ?

Related

batch script (.bat) called by openvpn process cannot successfully pass arguments to external .exe

I have an openvpn server running on a windows 10 host. The openvpn server config has a parameter -auth-user-pass-verify which allows you to specify a script that will receive a login username and password in the form of a temporary file.
In the .bat file I capture the username and pass as follows
set /A count=0
for /F "tokens=*" %%A in (%~1) do (
if !count!==1 (
set password=%%A
set /A count=2
)
if !count!==0 (
set username=%%A
set /A count=1
)
)
This part works and is verified, both when the script is run by myself and when it is called by openvpn. I then call an external .exe to verify the password.
for /f %%i in ('c:\"Program Files"\OpenVPN\config\foo\foo.exe %password%') do set RESULT=%%i
Now this last parts works when I call the .bat from command prompt myself, but it fails when the .bat is run by openvpn -- nothing is written to "RESULT". I don't even know if the exe is being called at all.
I have tried openvpn server with admin privileges. I have tried --script-security 2 and 3. Openvpn documentation says it calls the script "as a shell command" for what it's worth.
Try this:
for /f %%i in ('"c:\Program Files\OpenVPN\config\foo\foo.exe" %password%') do set RESULT=%%i

shortcut (.LNK) is copied from local network to user pc without his icon

I wrote a batch file script in order to copy shortcut from the local network to the user desktop station. everything is working perfect except that the shortcut that is copied to the user desktop is without his icon. I have no experience writing batch files, i will be grateful if someone can advice me how to solve that issue.
that is the script:
#echo off
setlocal
set alias=Reg query "HKLM\Software\Microsoft\NET Framework Setup\NDP"
FOR /F "TOKENS=6 DELIMS=\." %%A IN ('%alias%') DO set .NetVer=%%A
if [%.NetVer] ==[] GOTO noDotNet
if EXIST C:\Users\%USERNAME%\Desktop\Partner_Projects_System.lnk GOTO ShortCutAllreadyExist
if not exist "\\netapp2\public\all\INTERNET PROJECTS\PMS_Shortcut_noWhite\Partner_Projects_System.lnk" GOTO noPermissionToDir
copy "\\netapp2\public\all\INTERNET PROJECTS\PMS_Shortcut_noWhite\Partner_Projects_System.lnk" "C:\Users\%USERNAME%\Desktop"
:loop
ping -n 1 -w 3000 1.1.1.1 > nul
IF EXIST C:\Users\%USERNAME%\Desktop\Partner_Projects_System.lnk (
GOTO startApp
) ELSE (
GOTO loop
)
EXIT
pause
:noDotNet
msg "%username%" DOTNET Framework is not installed on your machine please contact partner helpdesk team
EXIT
:noPermissionToDir
msg "%username%" you need to have read and write permission to the path \\netapp2\public\all\INTERNET PROJECTS\ please contact partner helpdesk team
EXIT
:ShortCutAllreadyExist
msg "%username%" the shortcut is allredy exist on the desktop
EXIT
:startApp
msg "%username%" SHORTCUT TO PROJECT MANAGMENT SOFTWARE WAS CREATED ON YOUR DESKTOP
start C:\Users\%USERNAME%\Desktop\Partner_Projects_System.lnk
A shortcut can specify a separate path to a icon that is different from the actual shortcut target. If this path is not valid on the new machine the icon might not display correctly.
You cannot manipulate shortcuts with a batch file but you can with Windows Scripting Host. Try this script to print the shortcut properties.

Windows batch file using start not placing multiple programs in background

I am trying to get data from a sql server and ldap server for multiple clients. I need to get the sql data first and then the ldap data. In Unix shell it was straight forward to make a loop around a sub process with both retrievals going on for each client and then wait for it to complete. As a windows batch file however it happens sequentially. I.e. until I retrieve the data for one client, it won't go to the next. How can I get each client's data simultaneously? Here's what I have:
REM Get DB and client info. from config file
for /F "tokens=1,2,3,4,5,6 delims=| eol=#" %%G in (%cfg%\%env%.data) do (
REM Mark file as being in process of receiving data
type nul > %%K.tmp
REM Get data and remove tmp file to indicate completion
start cmd /C sqlcmd .... -Q "A long query" ^> %%K.dat1 && "c:\Program Files\Softerra\LDAP Administrator 4\laimex.exe" ... /sql "Another query" > %%K.dat2 && del %%K.tmp
)
For some reason, I need to do the first redirect escaped as ^> while the later one doesn't need that. At this point I am assuming that everything will be retrieved in the background and that I will need to check afterwards for when the processes are complete which I would do by checking the existence of the zero byte temp files I create. What happens though is that each iteration through the loop only starts when the prior one completes rather than occurring straight away by being placed in the background. Can anyone suggest how I can fix this?
You need to escape the && as well (^&^&), otherwise it executes everything after it as soon as start is fired. Example:
1 gets executed in a new shell correctly, while 2 takes over the main window (not what you want).
start cmd /C ping 127.0.0.1 && ping 127.0.0.2
Both get executed one after the other in a new window.
start cmd /C ping 127.0.0.1 ^&^& ping 127.0.0.2
Same as above, another way to do it.
start cmd /C "ping 127.0.0.1 && ping 127.0.0.2"
Also escape the other >'s, this might work:
start cmd /C sqlcmd .... -Q "A long query" ^> %%K.dat1 ^&^& "c:\Program Files\Softerra\LDAP Administrator 4\laimex.exe" ... /sql "Another query" ^> %%K.dat2 ^&^& del %%K.tmp

PSEXEC will copy .bat file but wont run it on remote computer?

i have looked around a fair bit, but cant seem to find an answer to this.
I am creating a script that is a part of the off boarding process for our company. As part of the process, it grants permssion for another user to access the exiting users profile share (working fine). The next part will map a network drive remotely (im having trouble with this. I am using PSEXEC to dispatch a bat script which maps the users drive:
#echo off
::Welcome note
echo Welcome to the User EXIT script!
:Start
:: set variable to be used throughout script for the username of the person exiting.
set /p uname="Please enter the username for exit:"
set /p cleanupu="Please enter the username for homedrive & mailbox cleanup:"
set /p computermap="Please enter the Computer to clean up the Homedrive:"
echo The username for exit is: %uname%
echo The username that is cleaning up is: %cleanupu%
echo The computer for the homedrive to be mapped to is %computermap%
set /P c=Is this correct [Y/N]?
if /I "%c%" EQU "Y" goto :init_confirm
if /I "%c%" EQU "N" goto :start
:init_confirm
::confirmation....
echo This script will exit the user: %uname%
pause
icacls "\\server\home$\%uname%" /grant DOMAIN\%cleanupu%:(OI)(CI)F
pause
echo net use z: \\server\home$\%uname%\ > map_temp.bat
psexec \\%computermap% -c -i -d map_temp.bat
pause
exit
This will copy the file to the remote computer and open up a blank command prompt window.
Can anyone see why this wont actually run map_tem.bat?
cheers

Why does batch file (.bat) converted to executable (.exe) not work?

So I have a batch file that I am trying to convert but i'm no success. The converter that I am using is
Bat To Exe Converter. The problem that I am encountering is that after converting the batch file it does not execute properly and immediately says "Press any key to continue . . ." and then closes. The batch file works fine on its own and when I converted it using the websites online converter it also worked (I would use the online but has little functions and is not exactly what I need).
Below is the batch code that I am using:
#ECHO OFF
TITLE ADB Over Network Running...
COLOR 17
CLS
IF "%ANDROID_PLATFORM_TOOLS%" == "" GOTO NOPATH
ADB tcpip 5555
IF ERRORLEVEL 1 GOTO END
IF ERRORLEVEL 0 GOTO NEXT
GOTO END
:NEXT
set /P ip=Enter Devices IP: %=%
ADB connect %ip%
GOTO END
:NOPATH
ECHO "ANDROID_PLATFORM_TOOLS" not found. Please add this environment variable
GOTO END
:END
PAUSE
EXIT
I hope that you can help me. Thank you for any help and your time :D
As all that program does is extract the batch file into a subfolder of temp and execute it, Windows has the exact same feature.
Type
iexpress
in Start - Run and follow the wizard and set your bat to run as the last step.

Resources