Author Topic: Storing PC / User Name in a variable  (Read 2025 times)

0 Members and 1 Guest are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Storing PC / User Name in a variable
« on: February 17, 2016, 04:34:13 PM »
if one shares VC config cross multiple PCs (I use onedrive to sync it across 2 PCs), one might need to do things based on which PC VC is running on. Example: setting the microphone to listen to, or if the PCs are in different rooms, commands like "Lights On" will mean to turn different lights on ...etc.
here is a very simple and easy command to capture the PC name in a variable.

update: the command has been revised to store as well the current user name ... on XP requires service pack 2, and I kept the original as disabled for reference

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="867" name="Get PC &amp; User name" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch.Capture</cmdType>
    <params>
      <param>C:\Windows\System32\hostname.exe</param>
      <param />
      <param>true</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>PCName</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.Capture</cmdType>
    <params>
      <param>C:\Windows\System32\whoami.exe</param>
      <param />
      <param>true</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>(.*?)\\(.*)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>PCName</param>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>UserName</param>
      <param>{Match.1.2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>Windows.GetPC-UserName</event>
</command>
« Last Edit: February 20, 2016, 12:26:32 AM by Haddood »
When Voice command gets tough, use hand gestures

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Storing PC Name in a variable
« Reply #1 on: February 17, 2016, 04:45:41 PM »
here's another method but using python instead

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="879" name="PC Username" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>import getpass{CR}result=username = getpass.getuser()</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>Username</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>