Reg not starting vbscript - windows

I've got registry entries inside of a .reg file. The reg file is for making a URI Scheme. It worked when I was passing %1 argument to a .bat file, but I don't like viewing the .bat file, so I want to use the well known VBScript method of hiding the .bat file. How do I pass the arguments to the batch file?
Apps.reg
REGEDIT4
[HKEY_CLASSES_ROOT\Apps]
#="URL:Apps Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\Apps\shell]
[HKEY_CLASSES_ROOT\Apps\shell\open]
[HKEY_CLASSES_ROOT\Apps\shell\open\command]
#="\"M:\\Apps\\Apps.vbs\" \"%1\""
Apps.vbs
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "Apps.bat" & Chr(34), 0
Set WshShell = Nothing
The batch file just uses %1 argument. The problem is getting the argument to the batch file. Currently every time I try to use the URI Scheme with the VBScript, I get "apps://foo is not a valid Win32 application." Any help is appreciated!

This works:
WshShell.Run "Apps.bat /foo", 0
If you want to separate your program path which may include spaces from the command line you could try this:
WshShell.Run """Apps.bat"" /foo", 0

Related

How can I update a text file using batch script which will be triggered by VB Script

The challenge here is, the batch script is triggered using Vb script and the text file is created using the same VBScript.
The text file name contains a variable in it. I am able to pass the variable from VBS to batch, but unable to append the same text file.
VBScript :
Dim wsh
Set wsh = Wscript.CreateObject("Wscript.Shell")
strinputa = "102590"
wsh.run "Test.bat " + chr(34) + strinputa + chr(34)
set wsh = nothing
Batch script :
Set Rid = %1
Xcopy "Location 1" "Location 2" /s /e /k /i >> %~dp0Logs\log_%Rid%.txt
pause
Keep in mind that there is already have a text file in "\Logs" folder with file name
'log_102590', which I want to update.

Run batch file with parameters

I would like to run a batch file with some extra character at the end.
If I write it directly to cmd it is working, like change directory to "c:\Users\Public\Uploader\" and write the following: start.bat "cmd:file.import c:\Users\tom\Desktop\a.xml"
I do not know how to write it in VBScript, because the following script is not working:
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory="C:\Users\Public\Uploader\"
WshShell.Run "start.bat" & "cmd:file.import C:\Users\tom\Desktop\a.xml"
The a.xml should dynamically change based on the last modified file in the folder.
Thank you for your help!
If you're trying to duplicate what you're doing in the command prompt, you need to add a space between the batch file name and its arguments. You also need to add the quotes.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory="C:\Users\Public\Uploader\"
WshShell.Run "start.bat " & chr(34) & "cmd:file.import C:\Users\tom\Desktop\a.xml" & chr(34)

Deleting Winzip Command Line Add On 2.2 vbs

I'm trying to delete a file like winzip command line using this code
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\Program Files\WinZip\wzuninst.exe wzcline C:\Program Files\WinZip\wzclun.dll")
When I run it on cmd it says Bad name or number. Can someone clarify it for me?
That's not a valid command line.
If you want to run a program you use wshshell.run.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /k dir c:\windows\*.*"

How can I hide ms-dos window when running a .bat file?

I am running a .bat file for my script (Scheduled Tak (CronJob)) per minute.
When it runs, windows command prompt appears for a fiction of time.
My batch code like this;
#ECHO OFF
C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\tst\index.php"
How can I hide this window when it run?
Use a VBScript
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\yourbatch.bat"), 0, True
Run that which will run your batch file hidden.
I don't like the VBScript solution.
Download and copy nircmd.exe to your %systemroot%\system32 folder, then add this command to first line of your batch:
nircmd.exe win hide ititle "cmd.exe"
You can also change the title of your batch file terminal window by title command to avoid from hiding all cmd windows, like this:
title MyBatch
nircmd.exe win hide ititle "MyBatch"
This VBScript creates a copy of your batch file in %Temp%, executes it silently and deletes it afterwards
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim tempfolder
Const TemporaryFolder = 2
Dim WshShell, strCurDir
Set WshShell = CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
batch = "#ECHO OFF" & vbCrLf & _
"C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\tst\index.php"
Set tempfolder = fso.GetSpecialFolder(TemporaryFolder)
WshShell.CurrentDirectory = tempfolder
i=1
n=0
While n <> 1
If (fso.FileExists(i&".bat")) Then
i = i + 1
Else
n = 1
End If
Wend
Set File = fso.CreateTextFile(i&".bat",True)
File.Write batch
File.Close
Dim batchfile
batchfile = fso.GetAbsolutePathName(i&".bat")
WshShell.CurrentDirectory = strCurDir
WshShell.Run chr(34) & batchfile & Chr(34), 0, TRUE
fso.DeleteFile batchfile
I know the post is old but here is my solution, AGerman from dostips helped me code this script, its very useful.
#echo off &setlocal EnableExtensions DisableDelayedExpansion
:: Change the working directory to the directory of the batch file.
:: If the first passed argument was ~e~ (that is, the batch file was called from the VBScript)
:: then shift the parameters by one and continue at label :elevated
cd /d "%~dp0"&if "%~1"=="~e~" (shift&goto :elevated)
:: Assign the passed arguments to variable param.
set "param=%*"
:: NET SESSION fails if the batch code doesn't run with elevated permissions.
:: Assign variable __verb to "open" if the batch file runs elevated or to "runas" if it doesn't run elevated
>nul 2>&1 net session &&(set "__verb=open")||(set "__verb=runas")
:: Assign the name of the VBScript to variable vbs.
:: Assign the full name of the batch file to variable me.
:: Enable delayed variable expansion.
set "vbs=%temp%\uac.vbs"&set "me=%~f0"&setlocal enabledelayedexpansion
:: If arguments were passed, prepare them to be passed from within the VBScript by doubling the quotation marks.
if defined param set "param=!param:"=""!"
:: Write the VBScript. The ShellExecute method will run the batch file in a cmd.exe process where ~e~ will be passed as
:: first argument followed by the original arguments (saved in param). The UAC will be invoked if __verb was set to "runas".
:: Elsewise the UAC will not be invoked. For further information about the ShellExecute method see:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx
>"!vbs!" echo CreateObject("Shell.Application").ShellExecute "!comspec!", "/c """"!me!"" ~e~ !param!""", "", "%__verb%", 0
:: Run the VBScript in a cscript.exe process.
:: Delete the VBScript file.
:: Quit the batch execution.
cscript //nologo "!vbs!"&del "!vbs!"&goto :eof
:elevated
::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: Do your elevated stuff here...

Hiding a simple batch window

I've searched this and some pages came which weren't really useful or were too complicated (I am not a skilled batch file programmer!)! What I need is to run a batch file in hidden form (no console window). The batch file will not be called from external application or code. It will be clicked on by the client and then I want no console pages to be shown (only pages which are called by call command should be shown)! The batch file is exactly as follows:
#echo off
call setup.exe
IF EXIST "C:/caillog" goto tracking
IF NOT EXIST "C:/caillog" goto end
:tracking
call dotnet4.exe
call ClientService.msi
goto end
:end
I use VBScripts to open it hidden, like this:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%batchfile%"), 0, True
for e.g the bat file I want to run is run.bat then I'll do like this
objShell.Run("run.bat"), 0, True
Instead of running the batch file run the vb file.
Write it in notepad and save it as *.vbs
If your Windows system supports powershell you can place this infront of "#echo off":
cmd /c powershell -Nop -NonI -Nologo -WindowStyle Hidden "Write-Host"
As others have said, use VBS.
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\FilePath" & Chr(34), 0
Set WinScriptHost = Nothing
This is what I use.

Resources