KaustubhK
KaustubhK

Reputation: 775

find where is my windows os installed on from remote computer?

I want to find location of 'cmd.exe' or 'powershell.exe' from remote computer. I want to execute a script from remote computer. To execute it I want location of 'cmd' or 'powershell.exe'. It is possible that windows is installed on any drive. so how to find where is my windows is installed.

Upvotes: 0

Views: 311

Answers (3)

cyberponk
cyberponk

Reputation: 1766

Use %WINDIR% environment variable

Example:

set "_path=%WINDIR%\system32\cmd.exe"        --> sets _path variable
cd /d %_path%                                --> goes to _path folder

Upvotes: 0

Todd Hartman
Todd Hartman

Reputation: 90

It's available via WMI (Win32_OperatingSystem)

wmic.exe /NODE:<remote_computer> OS GET WindowsDirectory

Upvotes: 3

Dennis van Gils
Dennis van Gils

Reputation: 3452

To get the path + file of cmd.exe you can use this variable: %ComSpec%, which will return C:\Windows\System32\cmd.exe in most cases. To get only the path to that location, you can use for instance (in the cmd)

for /f %a in ("%ComSpec%") do echo %~dpa 

or (in a batch-file)

for /f %%a in ("%ComSpec%") do echo %%~dpa

Upvotes: 0

Related Questions