The correct method is to register your custom URL Protocol in windows registry as follows:
enter image description here
Once the above keys and values are added, from the web page, just call "customurl:\parameter1=xxx¶meter2=xxx" . You will receive the entire url as the argument in exe, which you need to process inside your exe. Change 'customurl' with the text of your choice.
Not sure how this works, i am getting lost somewhere, can someone help me with this with an example of an app?
Thanks in advance!
You are on the right track, you just need to change the "ExeName.exe" part to the path of your .exe. Your .exe application needs to parse the command line, this is where the URL is.
Here is a example batch file that implements a protocol handler:
#echo off
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
if not "%~1."=="." goto proto
choice /C IUE /M "Install? Uninstall? Example launch?"
if errorlevel 3 goto launch
if errorlevel 2 goto uninstall
if errorlevel 1 goto install
goto :EOF
:proto
echo Launched protocol with %*
pause
goto :EOF
:install
reg add "HKCU\Software\Classes\customUrl" /ve /d "customUrl handler" /f
reg add "HKCU\Software\Classes\customUrl" /v "URL Protocol" /f
reg add "HKCU\Software\Classes\customUrl\shell\open\command" /ve /d """"%~0""" %%1" /f
pause
goto :EOF
:uninstall
reg delete "HKCU\Software\Classes\customUrl" /f
pause
goto :EOF
:launch
start "" "customUrl:foo=bar"
goto :EOF
Save as myproto.cmd and run it and press i to install it. Then run it again and press e to launch a URL or make a dummy .html file with a customUrl: link you can click on.
Related
Error Message I want to remove:
I get this error when I run a code that runs a shortcut that's shared over network.
How can I stop cmd script from showing Network Errors like these, even if I know there is an error?
#echo off
echo.
echo 1. Add
echo 2. Remove
echo.
set /p var= Type option number here -
if %var%==1 (goto :add)
if %var%==2 (goto :remove)
if else (goto :EOF)
:add
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\ /v RestoreConnection /d 0
echo.
echo SUCESSFULLY ADDED!
timeout /t 2 /nobreak >nul &exit
:remove
reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\ /v RestoreConnection
echo.
echo SUCESSFULLY REMOVED!
timeout /t 2 /nobreak >nul &exit
This .bat script could come handy btw. Atleast it's easier than changing the registry manually. You can add and delete the value any time you want, so its convenient. Save this as a (.bat) file and use it...
Thanks #FiddlingAway for giving reference for the script : )
UPDATE:
Ok below is the current code I wrote up but it errors out saying
ERROR: The RPC server is unavailable
If I manually just type in taskkill /s cn /im csmmviewer.exe within cmd it works, what I'm I missing here?
#echo off
:start
set /p "cn=Enter the computer name "
echo.
set /p "question=You will now close csmmviewer.exe on %cn% are you sure? [Y/N] "
echo.
if /I "%question%" EQU "Y" goto :run
if /I "%question%" EQU "N" goto :start
:run
taskkill /s cn /im csmmviewer.exe
set /p "again=Do you have another computer name? [Y/N] "
echo.
if /I "%again%" EQU "Y" goto :start
if /I "%again%" EQU "N" goto :exit
Hello noob here looking for some much needed help please.
At my job I run into this issue where too many people log into an application and when users that really need to use it can’t because too many people are logged into it (using up all the licenses) and I have to start kicking them off by killing the app remotely. The below command works every time but I have to manually copy and paste it into the command prompt and replace PCJXXXXX with the actual computer name. I will like to create a .bat file or .cmd file that I can just double click on which will then just ask to enter the computer name which I would just then enter and it runs the full command to end the task.
My script:
taskkill /s pcjXXXXX /u domain_name\admin /im csmmviewer.exe
XXXXX is what I delete and enter the actual name, can anyone help, if you need more details please let me know your questions?
You can use a parameter (like killap PCJ12345), when you call it from command line. %1 refers to the first parameter.
#echo off
if "%1" == "" (
set /p "PC=Enter PC Name: PCJ"
) else set "pc=%1"
taskkill /s pcj%PC% /u domain_name\admin /im csmmviewer.exe
(or if the string PCJ is fix, simpler
killap 12345, when you replace set "pc=%1" with set "pc=PCJ%1")
If you don't give a parameter, (like when you start it by doubleclicking) it will ask you for the name.
Using set /P by simply prompting the user for input, stores the result in a variable and use the variable from there onwards.
#echo off
set /P "var=Please enter your PC Name: "
taskkill /s pcj%var% /u domain_name\admin /im csmmviewer.exe
for more detail on set you can run set /? from cmd.exe
I have a batch file with this line of code in it:
choice /c:123 /n
This is basically a glorified pause that only proceeds if 1, 2, or 3 have been pressed. If I press any other button, It will beep. I've search around the internet for the file location of this beep, but I can't find anything.
Where is the file located? How can I get access this sound file?
Choice.exe imports the Beep function and that is where the sound comes from, it is not a wav file on disk, it is generated dynamically. You can run it in a debugger and set a breakpoint on that function to figure out the exact parameters it is using. On Windows 10 it uses (1500, 500).
You can get the beep sound using a little trick with the FORFILES command as documented on DosTips.com
#echo off
setlocal
::Define a Linefeed variable
set LF=^
::above 2 blank lines are critical - do not remove.
call :hexprint "0x07" rtnvar
FOR /L %%L IN (1,1,5) do echo %rtnvar%
pause
exit /b
:hexPrint string [rtnVar]
for /f eol^=^%LF%%LF%^ delims^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b
I have a script to change registry values.
Running it from an elevated command window it changes the key ok.
Running it directly as an administrator (right click) it does nothing, same thing running it from task scheduler with elevated privileges.
Any idea why?
Code, basically it checks IP number and according to that it changes autoconfig proxy script with several option of .reg files with the different internet connection setup key.
#ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
SET Target=%computername%
IF %Target%.==. ECHO Missing target!&PAUSE&GOTO :EOF
FOR /F "tokens=2 delims=[]" %%A in ('PING %Target% -4 -n 1 ^| FIND "["') DO (
SET TargetIP=%%A
SET TargetIP
)
IF NOT DEFINED TargetIP ECHO NO IP found!&PAUSE&GOTO :EOF
:Compare
SET PartialIP=%TargetIP:~0,9%
IF "%PartialIP%"=="172.20.25" (
REGEDIT /S conbae.reg
goto :eof)
IF "%PartialIP%"=="172.20.22" (
REGEDIT /S conbna.reg
goto :eof)
SET PartialIP=%TargetIP:~0,6%
SET PartialIP
IF "%PartialIP%"=="172.20" (
REGEDIT /S conweb.reg
) ELSE (
REGEDIT /S sinbae.reg
)
Right clicking to run as Admin changes the working directory to the system32 folder, and the conbae.reg file can't be found as it is in the current folder.
You can change conbae.reg to "%~dp0conbae.reg" in all reg files and places and it should work fine too.
I have a bunch of old machines running Windows 2000 Pro and IE 5.0 which I want to upgrade to IE 6 with Silverlight. I downloaded the IE6 and Silverlight installers from Microsoft's web sites and fortunately they both have command line options to allow them to run in "silent mode".
I put the two commands in a DOS batch script and ran it, but the IE6 installer requires makes an automatic computer restart so the question is how to resume the script and run the 2nd command (install Silverlight).
My batch file is very simple right now:
ie6setup.exe /Q
silverlight.exe /q
From what I know, batch files can't resume execution after restarting the computer. Is there a way to make them do that? of is there another way to accomplish what I need.
Thank you
Based on Tim's post which, when tested, appended "two" to the batch file resulting in a failure to find the batch label "onetwo", so amended to read & write the "current" variable from a seperate text file, leaving the batch file untouched;
#echo off
call :Resume
goto %current%
goto :eof
:one
::Add script to Run key
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /d %~dpnx0 /f
echo two >%~dp0current.txt
echo -- Section one --
pause
shutdown -r -t 0
goto :eof
:two
echo three >%~dp0current.txt
echo -- Section two --
pause
shutdown -r -t 0
goto :eof
:three
::Remove script from Run key
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /f
del %~dp0current.txt
echo -- Section three --
pause
goto :eof
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
) else (
set current=one
)
You could put the second command in a exclusive batch file, and add an entry to regedit to execute this batch file automatically upon Windows' start, making silverlight be executed after the computer restarts.
Have you heard of msconfig? On some systems the regedit PATH you are looking for is:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
But you may want to check that. If you want to make a batch file to write that key on the registry, you probably should take a look at this tutorial.
If you do the IE6 installation with the command ie6setup.exe /q /r:n then it won't reboot automatically (see this page for details). Then theoretically you could install SilverLight immediately, and then reboot afterwards; but there is a chance that the SL install will refuse due to the need of a reboot, but it won't hurt to try it...
I know its a bit old but this works amazingly:
#echo off
call :Resume
goto %current%
goto :eof
:one
echo two >>myfile.cmd
::REBOOT HERE
goto :eof
:two
echo resumed here
goto :eof
:resume
rem THIS PART SHOULD BE AT THE BOTTOM OF THE FILE
set current=one
#echo off
set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
rem./ :: if no argument was passed, this line will be ignored, but if so, it will be executed here == ^> & %~1
:1st_command
ie6Setup.exe /Q
shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof
:2nd_command
SilverLight.exe /Q
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof
:3rd_command
Skype-8.92.0.401.exe /VerySilent /NoRestart /SuppressMsgBoxes /DL=1 & goto :eof
It is possible to do it without creating or manipulating readings in additional files, just writing and reading in the key and using arguments passed in the execution to control the command necessary for the relevant execution, using goto command as an argument %1
#echo off
set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
rem./ if no argument was passed, below will be ignored, but if so, it will be executed here == ^> & %~1
:1st_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "stackoverflow.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof
:2nd_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "meta.stackexchange.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof
:3rd_command
mode con cols=50 lines=1 | title %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "www.amazon.com" /new-tab
goto :eof