Batch file has errors when run, but enter trough command line works fine - windows

I'm helping one of my friends with his QA work. A lot of the time ctfmon.exe is always running in the background and he says it takes up memory on the computer for when he's testing. My friends work machine is using Windows XP
He already tried what was said in this article but it didn't help.
http://www.howtogeek.com/howto/windows-vista/what-is-ctfmonexe-and-why-is-it-running/
We then tried to create a simple batch file that would stop the process for him.
Here are the two files that we have
delete_cftmon.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"ctfmon.exe"=
Novoice.bat
taskkill /F /IM ctfmon.exe /T
regedit.exe /s delete_cftmon.reg
reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run C:\WINDOWS\system32\ctfmon.exe
rem reg delete [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] "ctfmon.exe"
I get the following errors "invalid command line parameters" and "Invalid key name"
When we enter the commands via the command line it works fine.
I believe it has to do with HKEY_CURRENT_USER but I'm not entirely sure why.
Any help would be greatly appreciated.

Related

How to Stop appearing command prompt at startup?

I m facing this problem since last week but couldn't find any workable solution for me. windows command prompt appear in start up then i must enter explorer.exe then window open for me. it don't directly open.
I hide all Microsoft program from msconfig. some suggest me to update window in latest version i did that too. some told me to run various kind of command like scf/scanner. i did that also.. but this is not worked for me.. can anyone one help me to solve this problem.
Not that your question is remotely on topic here, but here's my suggestion.
At the prompt, type the following and press the ENTER key:
%__AppDir__%reg.exe Add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /V Shell /D "explorer.exe" /F
Then type the following and press the ENTER key:
%__AppDir__%shutdown.exe /R /T 1
Your PC will reboot, and hopefully return to its normal explorer interface.

Batch "invalid command-line parameters"

For whatever reason, this:
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\BeginSecond
/v begin-second /t REG_DWORD /f
/d "%HOMEDRIVE%\Documents and Settings\%USERNAME%\Desktop\bat script\begin-second"
Line feeds were added for readability, the command itself is one continuous line.
Produces the message "Invalid command-line parameters" when the program is run. The command before that adds the registry key "BeginSecond", so that's not the issue...
But, for some strange reason, this command worked perfectly fine before I booted up my Windows 2000 virtual machine today.
There is probably some super easy fix for this. Any help, please?

batch file with reg add command executed from network

I have a simple batch file which adds registry with reg add command.
reg add "HKLM\SOFTWARE\test\test" /f /v "MainDir" /t REG_SZ /d "test"
When I run the bach from a network drive everithing looks fine but no registry was added. When I copy the batch to to my desktop and run it it works perfectly.
I tried to use PUSHD but wont help, only thing what works is creating a shortcut and in the shortcut add %TEMP% to start in
I solved it. It was so unexpected. The problem was the Commander which I alway use in windows. Everytime I run the batch from commander it don't work, when I run it from explorer or something else it was ok. Soooo weird. The commander have admin right so I don't know why it dont work. Thanks all for help. :)

How do I remove previous extension<->Program affiliations programatically?

I would like to write a batch file which ensures that when a user clicks on a .JNLP file, it opens using javaws.exe (located in program files/java/... you know the drill)
I have written the following batch file:
ASSOC .jnlp=JNLPFILE
IF EXIST "%ProgramFiles% (x86)" (GOTO x86) ELSE (GOTO x64)
:x86
FTYPE JNLPFILE="%ProgramFiles% (x86)\Java\jre7\bin\javaws.exe" "%1"
goto:eof
:x64
FTYPE JNLPFILE="%ProgramFiles%\Java\jre7\bin\javaws.exe" "%1"
I am testing this all in windows 7 64-bit.
This... doesn't work. Well, that's not entirely accurate. It modifies the registry correctly, and it adds .jnlp to windows list of Recommended programs to run. It does exactly what it should.
But it doesn't solve my problem. See, For testing, I went to Default Programs and associated .jnlp files with Notepad. And when I try to open .Jnlp files, IT tries to open in notepad, even after my code has run.
If I do an open with on a .jnlp, it gives me the option to open with Notepad or javaws.exe If I've run my code with the ASSOC, it adds a SECOND option of javaws.exe
I've tried ASSOC .jnlp="" and FTYPE JNLPFILE="" To try and clear notepad out, but had no luck.
How do I make my batch file blow away prior settings and assert its dominance on the machine?
EDIT: Using the answers below, I have added a single command to the beginning of my batch file, which should take care of my problem and make things work correctly.
REG DELETE HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp /f
Windows Explorer keeps its own list of file extensions for the user.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
To remove programs from this list, delete the program entry from
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.‌​jnlp\OpenWithList
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp\OpenWithProgIDs
and set the desired UserChoice Progid in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp\UserChoice
Also, note that the OpenWithList and OpenWithProgids can be set at multiple levels.
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.xyz\OpenWithList
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.xyz\OpenWithProgIDs
HKCR\.xyz\OpenWithList
HKCR\.xyz\OpenWithProgIDs
HKCR\SystemFileAssociations\FileType\OpenWithList

Why does batch file FOR fail when iterating over command output?

I have a batch file that uses this idiom (many times) to read a registry value into an environment variable:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName') DO SET MyVariable=%%B
(There's a tab character after delims=)
This works fine on thousands of customer's computers. But on one customer's computer (running Windows Server 2003, command extensions enabled),
it fails with 'REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName' is not recognized as an internal or external command, operable program or batch file.' Running the "reg query" command alone works fine. Reg.exe is present in C:\Windows\System32.
I was able to work around the problem by changing the code to
REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName > temp.txt
FOR /F "tokens=2* delims= " %%A IN (temp.txt) DO SET MyVariable=%%B
This got the customer up and running, but I would like to understand why the problem occurred so I can avoid it in the future.
Slightly off the primary topic - a more direct way to get a registry value (string or DWORD) into an environment variable would also be useful.
I would check:
The customer's role on the machine - are they an admin?
Where is reg.exe on the box - is there more than one copy of copy of reg.exe in the path?
Is there any locale difference on the customer's machine from the machines where this normally works?
Basically, enumerate everything that differs between this machine and machines where it works as expected. Include service packs, domain membership, etc.
Wow, that is odd.
If the same commands work when split into two lines, then I'd guess it has something to do with the way the command gets run in a subshell in the FOR command.
If you were really dying to figure out why it's dying in this particular case, you could run commands like "SET > envvars.txt" as the FOR command and compare that with the top shell.
Or maybe start off simple and try running the REG command via CMD /C to see if that does anything?
One quick guess here, what's the values of COMSPEC and SHELL ?
I had a similar situation to this. In my case it was a bad value in COMSPEC. I fixed that and the script started working as expected.
The /F switch needs command extensions to be turned on. Usually they are turned on by default, but I'd check that. On XP systems you can turn them on doing something like
cmd /e:on
or checking the registry under
HKCU\Software\Microsoft\Command Processor\EnableExtensions
Dunno about Windows Server.
Doing help for and help cmd could provide some hints as well.

Resources