Unable to run vbs file from windows registry - windows

I have a registry key that calls a vbscript file as below.It will be triggered on selecting a Change Cursor option from right click on .cur file
"C:\Program Files\Cursor Manager\CustomCursor.vbs" "%1" 2
Below is the vbs file(CustomCursor.vbs)
Set objArgs = WScript.Arguments ' Create object.
CusorValue=objArgs(1)
Path=objArgs(0)
MsgBox CusorValue
MsgBox Path
But its not working.Its not showing any message
Its working when i am calling the script from command prompt like below.
"C:\Program Files\Cursor Manager\CustomCursor.vbs" "E:\new\CM v5\cursors new\more\Arrow.cur" 2
If the registry value is batch file its working
"C:\Program Files\Cursor Manager\CustomCursor.cmd" "%1" 2
Below is batch file(CustomCursor.cmd)
echo %1
echo %2
pause
But i can use batch file as it will show a command window,as it will show command window while executing script.
Please tell me a way to execute the vbs file from registry or atleast a way to run batch file in background.
Thank you

Change your registry to
"%windir%\system32\wscript.exe" "C:\Program Files\Cursor Manager\CustomCursor.vbs" "%1" 2
The problem is that invoking directly the script file makes windows search for the program to execute it and call the asociated executable with the script as argument, but in this process the rest of the arguments are discarded. Call yourself the script host with all the needed arguments.

Related

Keep cmd.exe console window with specific title open?

in Windows 7 x64 SP1 I need to create a batch file (.bat) which keeps the cmd.exe console window open and has a specific title:
#ECHO OFF
title notepadtest
#ECHO ON
start "" /WAIT notepad
But this batch file keeps opening an infinite number of cmd.exe console windows in an unstoppable loop!
How can I create a batch file (.bat) which creates only ONE cmd.exe console window and keeps it open and has a specific title?
Please ensure that your batchfile is not named notepad.cmd or notepad.bat or anything like any system or external command. Name it something like mynotepad.cmd instead., then try this one please:
#echo off
title notepadtest
start "" /w notepad.exe
cmdline and batch files typically works like this. When a command is issued, it first checks the local path, where the script was launched from for the command, if not found, it will check your environment and system environment. So if you name a batchfile notepad.bat your batch is actually starting itself over and over, instead of finding notepad.exe in the environment variables.
Always name batch files something unique and not system/external command related.
Always use full executable name in a batch, like start "" /w notepad.exe and not start "" /w notepad

Execute bat file as a windows service

I have a windows batch file which i want to execute as a service. I have found app like alwaysRun but i want to use windows in-build app for this purpose. Can anyone please suggest.
My Use Case is : - I have a batch file which will be executing after every 10 secs. So i have created a normal batch file which calls this bat file and sleeps for 10 secs. So i want to make this second bat file as a service. So that it is called once and when the windows reboots.
This file should be called as a service.
#echo off
:begin
CALL dummyfile.bat
timeout /t 1
goto begin
Please suggest.
I would not do that. You could run the first batch file from a scheduled task.
OR
If you want it to run at startup,
As an example, on Windows 8 you could
Create a VBS file that will completely hide your batch file.
hideme.vbs
Set MyScript = CreateObject("WScript.Shell")
MyScript.Run "C:\wherever\script\is\batch.cmd", 0, False
It can be launched as cscript hideme.vbs
Then open Start / Run and type shell:startup and press enter. Paste a shortcut of the VBS file here.
This will let VBS file call the second batch file in hidden mode each time the PC starts up.
EDIT
In order to kill it, you need to create another batchfile which you can run to find the cmd.exe that is running in the background.
In your original batch file, create a title at the very beginning after #echo off
#echo off
title LOOP
:begin
CALL dummyfile.bat
timeout /t 1
goto begin
Now in your new batchfile, let's call it killLOOP.cmd you add this:
taskkill /F /FI "WindowTitle eq LOOP" /T
This will search for a process with Window title LOOP, then kill it. Just run it when you want to close it.
now in your
I executed batch file as a service, but it didn't work.
NSSM package resolved my problem. here are the steps to follow:
1- Download NSSM package
2- Add NSSM Directory path in Environment Variables Path
3- Execute command like:
nssm install Service_Name
3.1 After executing command mentioned in step 3, it will show a popup to provide
program file path. provide batch file path like "C:/Test/test.bat"
3.2 Click on install and now batch file will be executed as a window Service.
have you ever looked at the native Windows program called sc.exe ? It allows you to run a program as a service.
Here's some Microsoft documentation on it: https://support.microsoft.com/en-us/help/251192/how-to-create-a-windows-service-by-using-sc-exe
sc [Servername] Command Servicename [Optionname= Optionvalue...]
In particular, you could use the Create Command to create a new service:
Create
Creates a service (adds it to the registry).
So the simplest syntax would be something like:
sc Create myservice binPath=C:\some\path\to\myservice.bat

VBScript is running batch file from the file path of VBScript, not path of batch

I am having a problem with a VBScript which was working just fine yesterday, but for some reason does not work today. I am attempting to run a batch file off the sever, from a VBScript in an adjacent server folder. The VBScript reads like this:
Dim Shell
Set Shell = CreateObject ("WScript.Shell")
Shell.run "cmd /K ..\Analyses\GeniE_SP.bat"
The VBScript is in a file in the folder ..\Local Design Calculations, whereas the batch file is in ..\Analyses. The script is calling up the batch file just fine, but when the batch file runs it is running with the file path of the VBScript. This is what is shown in the command window:
I:\Shared\Projects\105874\Local Design Calculations>REM #echo off
If I simply run the batch file from its actual location, there are no problems as the first line in the command window will read like this (as it should):
I:\Shared\Projects\105874\Analyses>REM #echo off
Any ideas?
Shell.run "cmd /K cd ..\Analyses & GeniE_SP.bat"
If the current active directory for the batch file is a requirement, first change it.
You would specify the full path to what you want. There in no such thing as per drive default directories in WinNT. Graphical programs (ie normal) set their own default directory based on the folder the exe is in (and that's not a per drive default but a program default).
For console programs (ie non graphical) cmd.exe simulates per drive default directories.
SPECIFY FULL PATHS.

startup batch file hangs up on second command

I created a startup bat file that looks like this
taskkill /im RemoteDesktopManager.exe
C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
"C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
"C:\Program Files\Mozilla Firefox\firefox.exe"
it does the first and second, but won't go any further, they all exist
how can I fix this?
update : I tried suggestion provided by #phd443322 and wrote this:
taskkill /im RemoteDesktopManager.exe
start "" /w C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" /w "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" /w "C:\Program Files\Mozilla Firefox\firefox.exe"
intrestingly each command still waits for that program to be closed to continue to the next.
so why still not working?
Below there is a working Batch file, as first advised by phd443322:
taskkill /im RemoteDesktopManager.exe
start "" C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
Batch files wait for programs to exit unlike interactive. These are the rules documented in the Start command.
If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:
non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.
When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.
When executing a command line whose first token is the string "CMD "
without an extension or path qualifier, then "CMD" is replaced with
the value of the COMSPEC variable. This prevents picking up CMD.EXE
from the current directory.
When executing a command line whose first token does NOT contain an
extension, then CMD.EXE uses the value of the PATHEXT
environment variable to determine which extensions to look for
and in what order. The default value for the PATHEXT variable
is:
.COM;.EXE;.BAT;.CMD
Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.
When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.

Running vbscript from batch file

I just need to write a simple batch file just to run a vbscript. Both the vbscript and the batch file are in the same folder and is in the SysWOW64 directory as the vbscript can only be execute in that directory. Currently my batch file is as follows:
#echo off
%WINDIR%\SysWOW64\cmd.exe
cscript necdaily.vbs
But the vbscript wasn't executed and just the command prompt is open. Can anyone tell me how can i execute the vbscript when i run this batch file?
You can use %~dp0 to get the path of the currently running batch file.
Edited to change directory to the VBS location before running
If you want the VBS to synchronously run in the same window, then
#echo off
pushd %~dp0
cscript necdaily.vbs
If you want the VBS to synchronously run in a new window, then
#echo off
pushd %~dp0
start /wait "" cmd /c cscript necdaily.vbs
If you want the VBS to asynchronously run in the same window, then
#echo off
pushd %~dp0
start /b "" cscript necdaily.vbs
If you want the VBS to asynchronously run in a new window, then
#echo off
pushd %~dp0
start "" cmd /c cscript necdaily.vbs
This is the command for the batch file and it can run the vbscript.
C:\Windows\SysWOW64\cmd.exe /c cscript C:\Windows\SysWOW64\...\necdaily.vbs
Just try this code:
start "" "C:\Users\DiPesh\Desktop\vbscript\welcome.vbs"
and save as .bat, it works for me
Batch files are processed row by row and terminate whenever you call an executable directly.
- To make the batch file wait for the process to terminate and continue, put call in front of it.
- To make the batch file continue without waiting, put start "" in front of it.
I recommend using this single line script to accomplish your goal:
#call cscript "%~dp0necdaily.vbs"
(because this is a single line, you can use # instead of #echo off)
If you believe your script can only be called from the SysWOW64 versions of cmd.exe, you might try:
#%WINDIR%\SysWOW64\cmd.exe /c call cscript "%~dp0necdaily.vbs"
If you need the window to remain, you can replace /c with /k
Well i am trying to open a .vbs within a batch file without having to click open but the answer to this question is ...
SET APPDATA=%CD%
start (your file here without the brackets with a .vbs if it is a vbd file)
You should put your .bat file in the same folder as your .vbs file and call the following code inside the .bat file.
start cscript C:\filePath\File.vbs

Resources