开发者

Is it possible to properly execute qwinsta from a Cygwin ssh session?

I have Cygwin running on a Windows 7 machine and have the Cygwin ssh server running on it. On Linux I have a shell script where I want to do

ssh myuser@mymachine "qwinsta | grep Active"

to see who is logged in. This worked fine for a Windows Server 2008 R2 machine, but seems to have problems on Windows 7.

If I try this on the Windows 7 machine, I get:

bash: qwinsta: co开发者_如何转开发mmand not found

Now, here is where the weirdness begins...

If I login to the Windows 7 machine normally and look in C:\Windows\System32 with Windows Explorer, I see qwinsta.exe. If I open a CMD session and do a dir in C:\Windows\System32, I see qwinsta.exe. If I open a Cygwin shell and do a ls qwinsta.exe in /cygdrive/c/Windows/System32, I get:

ls: cannot access qwinsta.exe: No such file or directory

If I do a cmd /c dir C:\\\\Windows\\\\System32\\\\qwinsta.exe from the Cygwin shell, I get a "File Not Found"

If I copy qwinsta.exe into my Cygwin home directory, then it is visible in my home directory with ls. If I try to run this local copy of qwinsta from the Cygwin shell, it runs, but it also outputs a line:

{Message(): LoadString failed, Error 15105, (0x00003B01)}

What's up with qwinsta on Windows 7?


The problem is that qwinsta.exe is not actually located in C:\Windows\System32. It is actually found in

C:\Windows\winsxs\amd64_microsoft-windows-t..commandlinetoolsmqq_31bf3856ad364e35_6.XX.XXX.XXXX_none_XXXXXXXX\qwinsta.exe

Using the above path (or a softlink to the same) will run qwinsta.exe as it exists on any machine, and will not require you to copy the executable to your home directory.

The error message {Message(): LoadString failed, Error 15105, (0x00003B01)} is about the Multilinugal User Interface (localization) system not being able to find error message localization information for the program being run (see System Error Codes). In this case, it appears that the cygwin shell does not provide qwinsta.exe with the information it needs to find qwinsta.exe.mui in your language's locale folder (usually C:\Windows\System32\en-US or whatever your locale happens to be). Looking into this folder is somewhat misleading, as explorer will show the file in this directory, but when you run ls /cygdrive/c/Windows/System32/en-US, there is no qwinsta.exe.mui file. I suspect this has something to do with the new linking structure in NTFS (see mklink command), but I haven't figured out how to fix this part of the problem yet.


Solved:

  1. First, go to C:\Windows\winsxs\amd64_microsoft-windows-t..commandlinetoolsmqq_31bf3856ad364e35_6.1.7600.16385_none_851e6308c5b62529 (Copy and pasting that location works just as well as manually finding it.) You should find three files: Msg.exe , Quser.exe, and qwinsta.exe . Copy these files to your C:\Windows\system32 folder

  2. Next, go to C:\Windows\winsxs\amd64_microsoft-windows-t..etoolsmqq.resources_31bf3856ad364e35_6.1.7600.16385_en-us_7bef78d9f4a6a8ac

You should find three similarly named files, except these will end with .mui.

  1. Copy all three of these files to your C:\Windows\system32\en-US folder.

  2. Now try running the msg program. It should work without issue.


Windows 10

Following on from Erutan2099's answer, for Windows 10 it's a little trickier, since the files are compressed (binary delta compression, file signature 44 43 53 01). Trying to use them as is throws an Unsupported 16-Bit Application error:

The program or feature "\??\C:\Windows\System32\msg.exe" cannot start or run due to incompatibility with 64-bit versions of Windows. Please contact the software vendor to ask if a 64-bit Windows compatible version is available.

A specific tool has been made to decompress such files: SXSEXP (this post pointed me in the right direction)


Usage:

> sxsexp64.exe msg.exe expand\msg.exe
Processing target path  msg.exe
msg.exe => expand\msg.exe
File size               12602 bytes

DCS_HEADER found.

 NumberOfBlocks         1
 UncompressedFileSize   26112

DCS_BLOCK #1
 Block->CompressedBlockSize     0000312A
 Block->DecompressedBlockSize   00006600
Operation Successful
> sxsexp64.exe msg.exe.mui expand\msg.exe.mui
Processing target path  msg.exe.mui
msg.exe.mui => expand\msg.exe.mui
File size               2150 bytes

DCS_HEADER found.

 NumberOfBlocks         1
 UncompressedFileSize   7680

DCS_BLOCK #1
 Block->CompressedBlockSize     00000856
 Block->DecompressedBlockSize   00001E00
Operation Successful

These decompressed files can now be copied to C:\Windows\System32 and C:\Windows\System32\en-US respectively.

Example:

> msg * Hello, World!

Is it possible to properly execute qwinsta from a Cygwin ssh session?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜