bat file miss the vaule

liuwei@cesm 631 Reputation points
2021-09-01T03:11:58.603+00:00

HIk, Expert,

I run the script in cmd.exe direly, it runs well and get the product name and version and save to the assigned file.

I save the script as bat file and run it. I found the value missed. see below screenshot.

Please give advice what I lost?

128106-wmic-getname-valuemissed.png

Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
302 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,516 Reputation points
    2021-09-01T03:59:48.187+00:00

    Use of the root directory C:\ is suspicious, as in C:\ProductName.txt. You should not put any files in C:\ that do not need to be there. Put the file in a subdirectory.

    Probably the main problem is that wmic is deprecated, as in Windows 10 features we’re no longer developing - Windows Deployment. We are supposed to use PowerShell instead, as in (in PowerShell):

    Get-CimInstance -ClassName Win32_Product -Filter "Name like '.NET%'"  
    

    Except I do not know enough PowerShell to know how to write the output to a file.

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. liuwei@cesm 631 Reputation points
    2021-09-02T12:56:02.897+00:00

    Thanks for your post.

    get product name and save to a file like this. I test it working well.

    command | Out-File -FilePath C:\UninstallationSN\ProductName.txt
    Cheers

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more