How to bring the output of a command into my user property?

Discussions about using Windows guests in VirtualBox.
Post Reply
Plagrö
Posts: 140
Joined: 27. May 2018, 14:57

How to bring the output of a command into my user property?

Post by Plagrö »

I am in my windows guest.
I open cmd.
I type in the following:

Code: Select all

REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice
I get this output:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice
Progid REG_SZ Word.Document.12

What I want:
I want to bring this output into a user defined property.

To get this, have tried this in my cmd window in the path D:\NT3x:

Code: Select all

vboxcontrol guestproperty set /myproperties/myproperty REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice
But this was not successful.
But when I make this:

Code: Select all

vboxcontrol guestproperty set /myproperties/myproperty "This is my Text for my property"
... then it works.

Question: How can I bring the output of "REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice" into my guest-user-property?

Would appreciate some help. Thank you.





Edit1:
Important:
-It should be a direct way (in one step). Not first putting the output into a variable and then put the content of this variable in my user property. (This would be two steps. But I need it in one line/step)
-It must be via cmd, not shell.

Edit2:
This also does not work:

Code: Select all

REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice | vboxcontrol guestproperty set /myproperties/myproperty
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to bring the output of a command into my user property?

Post by scottgus1 »

Plagrö wrote:It must be via cmd, not shell
Does this mean 'not Powershell'?
Plagrö wrote:It should be a direct way (in one step). Not first putting the output into a variable and then put the content of this variable in my user property.
Going to a variable is a good way. Why not?

This is all Windows batch file command line manipulation. It is beyond the scope of the Virtualbox forum.

If you're willing to back down on the 'variables-are-bad' thing, googling "Windows command line redirect command output into variable" might get you started.
Plagrö
Posts: 140
Joined: 27. May 2018, 14:57

Re: How to bring the output of a command into my user property?

Post by Plagrö »

scottgus1 wrote: ... googling "Windows command line redirect command output into variable" might get you started.
Thank you. I am a step further now, because I have found this link with your searching suggest:
https://stackoverflow.com/questions/635 ... batch-file

But now there is a problem with the command:

Code: Select all

vboxcontrol guestproperty set /myproperties/myproperty ...
Here is what I have made in a cmd window:

Code: Select all

C:\Users\D>echo %Registry1%
Progid    REG_SZ    Word.Document.12

C:\Users\D>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty %Registry1%
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 6.1.14
(C) 2008-2020 Oracle Corporation
All rights reserved.

Usage:

vboxcontrol [-V|--version]           print version number and exit
vboxcontrol --nologo ...             suppress the logo

vboxcontrol guestproperty            get <property> [--verbose]
vboxcontrol guestproperty            set <property> [<value> [--flags <flags>]]
vboxcontrol guestproperty            delete|unset <property>
vboxcontrol guestproperty            enumerate [--patterns <patterns>]
vboxcontrol guestproperty            wait <patterns>
                                     [--timestamp <last timestamp>]
                                     [--timeout <timeout in ms>
The content of "Registry1" was obtained from the command:
FOR /F "tokens=* USEBACKQ" %g IN (`REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice`) do (SET "Registry1=%g")

As you see above it fails to set the content of the variable "Registry1" as a guestproperty.


Question:
Why does it not work for Registry1 with ...

Code: Select all

Progid    REG_SZ    Word.Document.12
... as content?
Is there a way to bring a content like ...

Code: Select all

Progid    REG_SZ    Word.Document.12
... into a guestproperty?




Edit:
Strange:
The content of Registry1 (see above) was obtained from the command:

Code: Select all

REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice
But when I now set the variable Registry1 manually (see below), all works.

Code: Select all

C:\Users\D>set Registry1="Progid    REG_SZ    Word.Document.12"

C:\Users\D>echo %Registry1%
"Progid    REG_SZ    Word.Document.12"

C:\Users\D>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty %Registry1%
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 6.1.14
(C) 2008-2020 Oracle Corporation
All rights reserved.
I can't understand this. (??)
Of course this does not help, because my content of the variable will be from the command above.
Any idea?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to bring the output of a command into my user property?

Post by scottgus1 »

There's extra things to do to a For command in a batch file.
scottgus1 wrote:This is all Windows batch file command line manipulation. It is beyond the scope of the Virtualbox forum.
Keep web-searching. This isn't a Windows batch file forum.
Post Reply