0

I have this batch file which runs correctly on test computer. However on the computer for my client I get this error: ERROR: Description = The executable program that this service is configured to run in does not implement the service. Press any key to continue . . .

The computer it runs correctly on is Windows 7 Pro 64-bit. The computer that is giving me trouble is Windows 7 Pro 32-bit.

Some information from the client’s computer: *Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Northside>path PATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Common Files\Intuit\QBPOSSDKRuntime

C:\Users\Northside>*

This is my batch file that runs without errors on 64-bit Windows 7 Pro but not on 32-bit Windows 7 Pro.

Any help to get this working or to use a Powershell command for the "for /F "skip=2 tokens=2 delims=," %%p in ('wmic logicaldisk where drivetype^=2 get deviceid^,volumename /format:csv') do (if EXIST "%%p\smart04.mdb" (" for this line will be greatly appreciated.

@echo off
rem This batch file is for use with the USb Thumb Drives
rem Save this file as "Upload Frayser.bat"
rem modified for Windows 7 on April 18, 2023

Echo Upload Frayser
echo.

for /F "skip=2 tokens=2 delims=," %%p in ('wmic logicaldisk where drivetype^=2 get deviceid^,volumename /format:csv') do (if EXIST "%%p\smart04.mdb" (

@echo Copying database file
COPY %%pSMART02.MDB n:\SMART\DATA\FRAYSER\SMART1.MDB

@echo Copying automat.in file
copy %%pautomat.in m:\

@echo off
@echo.
rem echo    OK to remove USB Stick!
rem powershell write-host -fore Cyan Please eject drive before removing.
start C:\"Program Files"\USB_Disk_Eject.exe /REMOVELETTER %%p
powershell write-host -fore Cyan  OK to remove USB Stick!
@echo.
rem pause> nul | set /p "=Click on the X at the top right corner to close after you have removed the USB drive. " 
@echo Click on the X at the top right corner to close
pause> nul | set /p "= after you have removed the USB stick." 
exit /b
 
)
powershell write-host -fore Cyan Cannot find frayser database file. Sorry,  no files were copied!
rem echo Cannot find database file. Sorry,  no files were copied!
start C:\"Program Files"\USB_Disk_Eject.exe /REMOVELETTER %%p
@echo.
powershell write-host -fore Cyan  OK to remove USB Stick!
@echo.
rem pause> nul | set /p "=Click on the X at the top right corner to close after you have removed the USB stick. " 
@echo Click on the X at the top right corner to close
pause> nul | set /p "= after you have removed the USB stick." 
exit /b
)
pause

Expecting the "for /F "skip=2 tokens=2 delims=," %%p in ('wmic logicaldisk " line to run with giving the "The executable program that this service is configured to run in does not implement the service." error.

MikeD
  • 19
  • 1
  • The problem is perhaps `/format:csv` at end of the `wmic` command line. The CSV format is not always available on Windows XP to Windows 7 depending on language of the operating system and configured country/language for the user account because of a failure by Microsoft. It is possible to fix that on a machine by copying manually files in `%SystemRoot%\System32\wbem\en-US` into the appropriate language folder in folder `%SystemRoot%\System32\wbem`. However, this batch file should not do that and use instead a different format which always works independent on language settings. – Mofi Apr 20 '23 at 05:27
  • There can be used `for /F "skip=2 tokens=2 delims==" %%I in ('%SystemRoot%\System32\wbem\wmic.exe LOGICALDISK where "DriveType=2" GET DeviceId /VALUE') do for /F %%J in ("%%I") do if exist "%%J\smart04.mdb" (` which works always. The reason for using the letters `I` and `J` as loop variables is described by [Issue 7: Usage of letters ADFNPSTXZadfnpstxz as loop variable](https://stackoverflow.com/a/60686543/3074564).. It is possible to use letter `p` as loop variable but it is better using a different character which cannot be mixed up with a loop variable modifier. – Mofi Apr 20 '23 at 05:37
  • The reason for the inner __FOR__ loop is a bug in `cmd.exe` on processing the captured UTF-16 Little Endian encoded output of `wmic.exe`. It interprets the byte sequence 0x0D 0x00 0x0A 0x00 (hexadecimal values of a UTF-16 LE encoded carriage return + line-feed) as a carriage return. There is assigned the drive letter + colon + an erroneous carriage return to loop variable `I` making the second __FOR__ loop necessary to remove the erroneous carriage return and get assigned to loop variable `J` only the drive letter and the colon. `%%J` must be used in rest of the batch file instead of `%%p`. – Mofi Apr 20 '23 at 05:40
  • BTW: If the batch file is stored on the USB storage media and executed with a double click after the stored media is plugged in, then the entire __FOR__ command line is not necessary at all. There can be used `%~d0` to reference the drive letter with colon of the drive on which the currently executed batch file is stored. `%~d0` references the drive of argument 0 as explained by help of command __CALL__ output on running `call /?` in a command prompt window. Argument 0 is the string used to run the batch file and references therefore always the batch file. – Mofi Apr 20 '23 at 05:43
  • Syntactically wrong but automatically corrected by `cmd.exe` on execution is also the command line `start C:\"Program Files"\USB_Disk_Eject.exe`. Please open a command prompt window, type `C:\Pro` and press multiple times the key __TAB__ and look after each key press what the file/folder name completion of `cmd.exe` suggests. When there is displayed again `"C:\Program Files"`, continue typing with `\USB` and press once again key __TAB__. The display changes from `"C:\Program Files"\USB` to `"C:\Program Files\USB_Disk_Eject.exe"` if that file exists. – Mofi Apr 20 '23 at 05:47
  • The entire file/folder name must be enclosed in `"` and not just parts of it if the file/folder name (or any other argument string like a password) contains a space or one of these characters ``&()[]{}^=;!'+,`~<>|``. That is explained by help of the Windows *Command Processor* output on running `cmd /?` in a command prompt window in last paragraph on last help page and the file/folder name completion demonstrates that perfectly. Now run `start /?` and read the output usage help. There can be read that an argument string enclosed within `"` is interpreted as title for the console window opened – Mofi Apr 20 '23 at 05:50
  • by called Windows kernel library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) on executable to run is a Windows console application. This is the reason why `start "C:\Program Files\USB_Disk_Eject.exe"` would not work as expected as the fully qualified file name enclosed in `"` would be interpreted as title string by `start`. The solution is specifying explicitly a title string which can be also an empty string if the executable is a Windows GUI application on which no console window is opened at all. – Mofi Apr 20 '23 at 05:53
  • So, please use `start "" "C:\Program Files\USB_Disk_Eject.exe" /REMOVELETTER %%J` or perhaps better `start "" "%ProgramFiles%\USB_Disk_Eject.exe" /REMOVELETTER %%J`. Well, the latter could be a problem if there is on 64-bit Windows 7 just `C:\Program Files\USB_Disk_Eject.exe` but not also `C:\Program Files (x86)\USB_Disk_Eject.exe` and the batch file is processed by 32-bit `cmd.exe` in `%SystemRoot%\SysWOW64` instead of 64-bit `cmd.exe` in `%SystemRoot%\System32`. See also [WOW64 Implementation Details](https://learn.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details). – Mofi Apr 20 '23 at 05:59
  • Thanks Mofi for your replies. The problem is not the “USB_Disk_Eject.exe” command as it never gets to this statement and if I remove it, I still get the same error. The users are Korean and have had the Windows language se to Korean at one time but now it is set to U.S. English. There is only a “en-US” under the wbem folder. I suspect the problem is the difference between a 32-bit and 64-bit machine or the “/format:csv” is the problem. – MikeD Apr 20 '23 at 09:36

1 Answers1

0

Based upon the error message you've shown, it seems as if Windows Management Instrumentation service is missing in the appropriate registry location.

To append it, I would suggest that you create a PowerShell script with the following content:

$key = Get-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost\"
$values = $key.GetValue("netsvcs")
$values += "winmgmt"
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost\" "netsvcs" $values -Type MultiString

Then, on your 'problem' Windows 7 Pro computer, right click on it and choose the 'Run as administrator' option.

If this is successful you should be able to run an improved version of your script including the WMIC.exe utility.

Compo
  • 36,585
  • 5
  • 27
  • 39